Symfony: Add log message manually

Contributor Icon Contributed by qmchenry  
Tag Icon Tagged: Symfony  

When troubleshooting a complex web application (or a simple one), there are times that sending a message to a log file will help. Two command syntaxes are required depending on if you are in an action or a template. When using the development environment of an application in Symfony, the log message will show up in the development toolbar which will make your life even easier.


To send a log message from within a template, use this syntax:


From an action, use:

$this->logMessage('help me!', 'info');

In both of these examples, the first parameter is the string to log and the second parameter is the severity level of the message. The possible messages levels are:

    emerg
    alert
    crit
    err
    warning
    notice
    info
    debug

The functions above are helpful proxy functions to the real logging methods. If you are not in an action or a template, you can create a log message this way:

sfContext::getInstance()->getLogger()->info('qmchenry was here');

In this case, the message level is determined by the function called at the end of that chain. To create a critical message, substitute crit() for info().

 

2 Comments -


  1. anonymous said on April 20, 2009

    The empty box in the text above should contain the following (lifted from http://www.symfony-project.org/book/1_0/16-Application-Management-Tools):

    {{{
    // From a template

    }}}

  2. D said on April 17, 2011

    Thanks a lot

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -