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.

Please upgrade to 2.1.x here. The 2.0 branch is no longer being updated.
Current version is 2.1.11, released 12 June.

Is there a Logger in Vanilla?

businessdadbusinessdad Stealth contributor MVP
edited March 2012 in Vanilla 2.0 Help

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.

  • businessdadbusinessdad Stealth contributor MVP

    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.

  • businessdadbusinessdad Stealth contributor MVP

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