HomeWeb application programmingSymfonySymfony: Add log message manually

Symfony: Add log message manually

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().

Quinn McHenry
Quinn McHenry
Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!