Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

Update for critical security issue in PHPMailer included in release Vanilla 2.3.1

Tutorial: How to Enable a debug log and collect debugging information.

peregrineperegrine MVP
edited May 2014 in Tutorials

To Enable logging:


1 add these statements to your config.php

$Configuration['Garden']['Errors']['LogEnabled'] = TRUE;
$Configuration['Garden']['Errors']['LogFile'] = 'log/DebugLog';


2 create a log folder off of the root folder of your forum

e.g. if your forum resides in /forum

create a folder (directory) called log

give it read write and execute permissions. depending on ownership of files and what the owner of your web process.

you could try 777 or lesser permissions.

775


example

next you can add statements in any php file you want to collect values of variables.

by

putting a LogMessage( statement.

e.g. if I want to find the value of $IncrementBy in the DiscussionsModel

I could add this

LogMessage(__FILE__,__LINE__,'Object','Method',"myincrement is: $IncrementBy");

all of your debug messages will go to a file called DebugLog in the log folder.

which you can view.

here is how to debug. it is all temporary - so you will need to undo when you have finished debugging.

an example of it in use:

go into

/applications/vanilla/models/discussionmodel.php

temporarily replace around line 1837

        public function AddView($DiscussionID) {
        $IncrementBy = 0;
        if (C('Vanilla.Views.Denormalize', FALSE) && Gdn::Cache()->ActiveEnabled()) {
        $WritebackLimit = C('Vanilla.Views.DenormalizeWriteback', 10);
        $CacheKey = sprintf(DiscussionModel::CACHE_DISCUSSIONVIEWS, $DiscussionID);
        // Increment. If not success, create key.
        $Views = Gdn::Cache()->Increment($CacheKey);
        // added this one line
        LogMessage(__FILE__,__LINE__,'Object','Method',"my views are $Views");
        if ($Views === Gdn_Cache::CACHEOP_FAILURE)
        Gdn::Cache()->Store($CacheKey, 1);
        // Every X views, writeback to Discussions
        if (($Views % $WritebackLimit) == 0) {
        $IncrementBy = floor($Views / $WritebackLimit) * $WritebackLimit;
        Gdn::Cache()->Decrement($CacheKey, $IncrementBy);
        }
        } else {
        $IncrementBy = 1;
        }
        // added these three lines
        LogMessage(__FILE__,__LINE__,'Object','Method',"myincrement is: $IncrementBy");
        $IncrementBy = 2;
        LogMessage(__FILE__,__LINE__,'Object','Method',"mynew increment is:$IncrementBy");
        if ($IncrementBy) {
        $this->SQL
        ->Update('Discussion')
        ->Set('CountViews', "CountViews + {$IncrementBy}", FALSE)
        ->Where('DiscussionID', $DiscussionID)
        ->Put();
        }
        }

results

you should then see in the DebugLog file

something like this. and you will increment discussions by 2.

06 May 2014 - 01:51:05: [Garden] /var/www/vanilla/applications/vanilla/models/class.discussionmodel.php, 1837, Object.Method(), myincrement is: 1
06 May 2014 - 01:51:05: [Garden] /var/www/vanilla/applications/vanilla/models/class.discussionmodel.php, 1839, Object.Method(), mynew increment is:2

read the above three times before you do anything.

after you make the above changes.

go to the discussions page.

click on a discussion and the view count should increment by 2.

you will see the before and after values of IncrementBy -

myincrement is: 0 then that will give you a clue.
mynewincrement is: 2

you could also use @businessdad's excellent plugin as well to put things in a sql file

http://vanillaforums.org/addon/logger-plugin

read the instructions how to use the plugin for the method to use with the logger-plugin

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

vrijvlinderR_JhgtonightUnderDogLincShadowdare

Comments

  • peregrineperegrine MVP
    edited May 2014

    P.S. if it weren't for x00(my mentor in outer internet space) providing this info in a discussion years ago. I would have never known how to do this.

    and I might add x00 of the humblest guys on the forum - without him I'd be lost in the vanilla wilderness.

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

    R_JhgtonightUnderDog
  • businessdadbusinessdad Stealth contributor MVP
    edited May 2014

    Thanks for the instructions, they will surely be useful. And also thanks for mentioning the Logger plugin, about which I would like to add one note. The Logger plugin now incorporates all the premium features, free of charge. It allows to send log messages to remote log aggregators, such as Loggly and Papertrail. If you run multiple forums and you need to monitor them all, and to search through the logs, that feature alone can be a life saver.

    vrijvlinderhgtonightperegrineUnderDog
  • There also looks like there is some logging feature going to be added to core - if one peruses github.

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

  • LincLinc Vanilla's Bard (and Lead Developer) Detroit Vanilla Staff

    @peregrine We're putting the ability to collect logs into core as a framework feature. I don't think we're going to put much more actual logging into core.

    peregrinehgtonightUnderDogShadowdare
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Thanks for that tutorial! I used it the first time today and nearly instantly found my error

    peregrineUnderDog
  • LincLinc Vanilla's Bard (and Lead Developer) Detroit Vanilla Staff

    fyi, 666 or 664 is the permission. You only need a '7' or '5' if you're writing a shell script, basically. PHP and log files don't execute.

    UnderDog
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    I often have to dump $Sender to screen in order to understand what's going on and I use decho($Sender) so that I see the values inside this object. But it is not always possible to see the results (when inside of an ajax call, even decho($Sender);die; doesn't help).
    Thanks to that logging I can now always and everywhere track what is going on:

    ob_start();
    decho($Sender);
    $Result = ob_get_clean();
    LogMessage(__FILE__,__LINE__,'Object','Method',$Result);    
    

    But /!\ beware, that does create a lot of stuff in your debug log and thus I would use it very sparsely

  • another example of dumping objects or arrays here

    https://vanillaforums.org/discussion/comment/242768/#Comment_242768

    Pragmatism is all I have to offer. Avoiding the sidelines and providing centerline pro-tips.

Sign In or Register to comment.