Please upgrade here. These earlier versions are no longer being updated and have security issues.

Log file without back line?

PamelaPamela ✭✭
edited November 2013 in Vanilla 2.0 - 2.8

Newbie question about Vanilla log file

I enabled it like this (config.php)

$Configuration['Garden']['Errors']['LogEnabled'] = TRUE; $Configuration['Garden']['Errors']['LogFile'] = 'log.txt';

but in this generated file, there aren't back line :( I don't know if it's "normal" but it's not very useful in fact... no easy way to add it ?

Really not the most important feature to fix but ;) voila...

Tagged:
peregrine

Comments

  • Are you on linux or Windows? Vanilla 2.1 beta?

    The back line is the

    /r/n
    

    Codes, correct?

    Prepare to create a bug report on github please

    peregrine
  • peregrineperegrine MVP
    edited November 2013

    @pamela @todd

    here's a fix to functions.error.php in vanilla 2.1b2

    edit : I added Underdogs idea of \n . I wonder if PHP_EOL is a better alternative - haven't tried it.

    change

    <br />   function LogException($Ex) {
          if(!class_exists('Gdn', FALSE))
             return;
          if (!Gdn::Config('Garden.Errors.LogEnabled', FALSE))
             return;
    
          if ($Ex instanceof Gdn_UserException) return;
    
          try {
             $Px = Gdn::Request()->Host().' Garden ';
          } catch (Exception $Ex) {
             $Px = 'Garden ';
          }
    
          $ErrorLogFile = Gdn::Config('Garden.Errors.LogFile');
          if (!$ErrorLogFile) {
             $Type = 0;
          } else {
             $Type = 3;
             $Date = date(Gdn::Config('Garden.Errors.LogDateFormat', 'd M Y - H:i:s'));
             $Px = "$Date $Px";
          }
    
          $Message = 'Exception: '.$Ex->getMessage().' in '.$Ex->getFile().' on '.$Ex->getLine();
          @error_log($Px.$Message, $Type, $ErrorLogFile);
    
          $TraceLines = explode("\n", $Ex->getTraceAsString());
          foreach ($TraceLines as $i => $Line) {
             @error_log("$Px  $Line", $Type, $ErrorLogFile);
          }
       }
    }
    
    

    to

    <br />   function LogException($Ex) {
          if(!class_exists('Gdn', FALSE))
             return;
          if (!Gdn::Config('Garden.Errors.LogEnabled', FALSE))
             return;
    
          if ($Ex instanceof Gdn_UserException) return;
    
          try {
             $Px = Gdn::Request()->Host().' Garden ';
          } catch (Exception $Ex) {
             $Px = 'Garden ';
          }
    
          $ErrorLogFile = Gdn::Config('Garden.Errors.LogFile');
          if (!$ErrorLogFile) {
             $Type = 0;
          } else {
             $Type = 3;
             $Date = date(Gdn::Config('Garden.Errors.LogDateFormat', 'd M Y - H:i:s'));
             $Px = "$Date $Px";
          }
    
          $Message = 'Exception: '.$Ex->getMessage().' in '.$Ex->getFile().' on '.$Ex->getLine();
          @error_log("\n ----\n" .$Px.$Message, $Type, $ErrorLogFile);
    
          $TraceLines = explode("\n", $Ex->getTraceAsString());
          foreach ($TraceLines as $i => $Line) {
             @error_log("\n" . "$Px  $Line", $Type, $ErrorLogFile);
          }
       }
    }
    
    
    

    output will change from this type of format of LogExceptions

    <br />16 Nov 2013 - 01:52:20 localhost Garden Exception: DiscussionController->CommentMode not found. in /var/www/vanilla3/applications/vanilla/controllers/class.discussioncontroller.php on 4416 Nov 2013 - 01:52:20 localhost Garden   #0 /var/www/vanilla3/applications/vanilla/controllers/class.discussioncontroller.php(138): DiscussionController->__get('CommentMode')16 Nov 2013 - 01:52:20 localhost Garden   #1 [internal function]: DiscussionController->Index('2', 'test-question', '')16 Nov 2013 - 01:52:20 localhost Garden   #2 /var/www/vanilla3/library/core/class.dispatcher.php(350): call_user_func_array(Array, Array)16 Nov 2013 - 01:52:20 localhost Garden   #3 /var/www/vanilla3/index.php(46): Gdn_Dispatcher->Dispatch()16 Nov 2013 - 01:52:20 localhost Garden   #4 {main}16 Nov 2013 - 01:52:49 localhost Garden Exception: DiscussionController->CommentMode not found. in /var/www/vanilla3/applications/vanilla/controllers/class.discussioncontroller.php on 4416 Nov 2013 - 01:52:49 localhost Garden   #0 /var/www/vanilla3/applications/vanilla/controllers/class.discussioncontroller.php(138): DiscussionController->__get('CommentMode')16 Nov 2013 - 01:52:49 localhost Garden   #1 [internal function]: DiscussionController->Index('2', 'test-question', '')16 Nov 2013 - 01:52:49 localhost Garden   #2 /var/www/vanilla3/library/core/class.dispatcher.php(350): call_user_func_array(Array, Array)16 Nov 2013 - 01:52:49 localhost Garden   #3 /var/www/vanilla3/index.php(46): Gdn_Dispatcher->Dispatch()16 Nov 2013 - 01:52:49 localhost Garden   #4 {main}
    
    

    to LogExceptions with each message grouping followed by ---- and each trace on a new line

    <br />16 Nov 2013 - 01:47:37 localhost Garden Exception: DiscussionController->CommentMode not found. in /var/www/vanilla3/applications/vanilla/controllers/class.discussioncontroller.php on 44
    16 Nov 2013 - 01:47:37 localhost Garden   #0 /var/www/vanilla3/applications/vanilla/controllers/class.discussioncontroller.php(138): DiscussionController->__get('CommentMode')
    16 Nov 2013 - 01:47:37 localhost Garden   #1 [internal function]: DiscussionController->Index('2', 'test-question', '')
    16 Nov 2013 - 01:47:37 localhost Garden   #2 /var/www/vanilla3/library/core/class.dispatcher.php(350): call_user_func_array(Array, Array)
    16 Nov 2013 - 01:47:37 localhost Garden   #3 /var/www/vanilla3/index.php(46): Gdn_Dispatcher->Dispatch()
    16 Nov 2013 - 01:47:37 localhost Garden   #4 {main}
     ----
    16 Nov 2013 - 01:48:11 localhost Garden Exception: DiscussionController->CommentMode not found. in /var/www/vanilla3/applications/vanilla/controllers/class.discussioncontroller.php on 44
    16 Nov 2013 - 01:48:11 localhost Garden   #0 /var/www/vanilla3/applications/vanilla/controllers/class.discussioncontroller.php(138): DiscussionController->__get('CommentMode')
    16 Nov 2013 - 01:48:11 localhost Garden   #1 [internal function]: DiscussionController->Index('2', 'test-question', '')
    16 Nov 2013 - 01:48:11 localhost Garden   #2 /var/www/vanilla3/library/core/class.dispatcher.php(350): call_user_func_array(Array, Array)
    16 Nov 2013 - 01:48:11 localhost Garden   #3 /var/www/vanilla3/index.php(46): Gdn_Dispatcher->Dispatch()
    16 Nov 2013 - 01:48:11 localhost Garden   #4 {main}
    
    

    @pamela - if you want to file on github and reference a potential fix, if they want to use it.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    UnderDogPamela
Sign In or Register to comment.