Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Is there a Logger in Vanilla?

edited March 2012 in Vanilla 2.0 - 2.8

Hi again,
I'm still developing my first plugin and I need to log some messages during execution, but I couldn't figure out if there's a logging function/module in Vanilla. I see there's a gdn_log table, but, in my installation, it's always empty no matter what happens. Should I configure/install something in particular? Thanks.

Best Answer

  • x00x00 MVP
    Answer ✓

    have a look at dashboard/class.logmodel.php

    it is used for logging with Insert

    * @param string $Operation The operation being performed. This is usually one of:
    *  - Delete: The record has been deleted.
    *  - Edit: The record has been edited.
    *  - Spam: The record has been marked spam.
    *  - Moderate: The record requires moderation.
    * @param string $RecordType The type of record being logged. This usually correspond to the tablename of the record.
    * @param array $Data The record data.
    *  - If you are logging just one row then pass the row as an array.
    *  - You can pass an additional _New element to tell the logger what the new data is.
    * @return int The log id.
    

    So it is generally used for logging operations on user content, and specifically posts I you want to do somethign different I suggest, creating your own.

    for debug error logging turn it on in config

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

    make sure you have file permissions set for /log. You can use

    LogMessage(__FILE__,__LINE__,'Object','Method', 'Message');

    grep is your friend.

Answers

  • x00x00 MVP
    Answer ✓

    have a look at dashboard/class.logmodel.php

    it is used for logging with Insert

    * @param string $Operation The operation being performed. This is usually one of:
    *  - Delete: The record has been deleted.
    *  - Edit: The record has been edited.
    *  - Spam: The record has been marked spam.
    *  - Moderate: The record requires moderation.
    * @param string $RecordType The type of record being logged. This usually correspond to the tablename of the record.
    * @param array $Data The record data.
    *  - If you are logging just one row then pass the row as an array.
    *  - You can pass an additional _New element to tell the logger what the new data is.
    * @return int The log id.
    

    So it is generally used for logging operations on user content, and specifically posts I you want to do somethign different I suggest, creating your own.

    for debug error logging turn it on in config

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

    make sure you have file permissions set for /log. You can use

    LogMessage(__FILE__,__LINE__,'Object','Method', 'Message');

    grep is your friend.

  • Thanks x00. I'll probably implement my own solution, as I'd like to have error logs saved into the database.

  • actually you can do that

    LogMessage can/is used as a last resort.

    just do error catching, and save your errors that way.

    grep is your friend.

  • @x00 Thanks. My solution will allow to log all sort of messages, not only exceptions (if that is what you meant by "catching"). If it comes out as something usable, I might try to post it as a plugin. :)

Sign In or Register to comment.