HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

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.



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


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


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) {
        ->Set('CountViews', "CountViews + {$IncrementBy}", FALSE)
        ->Where('DiscussionID', $DiscussionID)


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


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.



  • 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.

  • 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.

  • 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 Detroit Admin

    @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.

  • R_JR_J Ex-Fanboy Munich Admin

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

  • LincLinc Detroit Admin

    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.

  • R_JR_J Ex-Fanboy Munich Admin

    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:

    $Result = ob_get_clean();

    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


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

Sign In or Register to comment.