Symfony: Add log message manually

Home -> Programming -> Web -> Symfony

4485 views

From the computer of: qmchenry (338 recipes)
Created: Sep 17, 2007     Updated: Oct 10, 2007


Add a comment

Add to:
Add to stumbleuponAdd to del.icio.usDigg itAdd to FURL

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:

<?php log_message('helpful message', 'info') ?>


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

Subscribe to the Tech-Recipes Newsletter

You can get tips like this delivered in your email every week!

Enter your Email

We will never, ever sell your email address or spam you.





Related recipes:

  Symfony: Fix propel-insert-sql error: Can't connect to local MySQL server
  Symfony: Troubleshooting file uploads
  Symfony: Rebuild from Schema.yml Without Loss of Data
  Symfony: Delete an Application
  Symfony / Propel: How to Left Join

 

Sponsored links

 

Login

Nickname

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.