SUBSCRIBE VIA RSS


Subscribe to our feed

Status Updates

  • First iPhone app nearly complete! I've been waiting for 3 weeks for Apple to finish "conducting company identity verification."
    3 days ago
  • Rainy day! Staying indoors. Creating computerized players in a simulation game that models cooperation in the work place.
    75 days ago
  • Up at 8AM, with a hot cup of coffee brought back from Cafe Lola in Ann Arbor. Will I succeed in putting in 8 billable hours in one day?
    101 days ago
  • full scale irish band outside my window playing the pipes for the past 20 minutes. pretty fun.
    109 days ago
  • listening to Kristin on Maxim Radio!
    115 days ago
  • back from an amazing meal at ouest with even more amazing company.
    116 days ago
  • wondering how so many online tshirt companies stay in business--ones that sell shirts with funny messages, i never see them in real life
    122 days ago

Topics

TWITTER

The old fashioned way

RECENT TUNES

June 12, 2007 – 4:12pm Symfony exceptions, logging, and debugging

Since I always forget, here is a quick reference for throwing exceptions and adding log/debug messages throughout your symfony project.

Exceptions
This is how you can throw a new symfony exception.

throw new sfException('An error occurred. Please go back and try again.');

Logging

Within an action, this is how you can log a message:

<?php use_helper('Debug') ?>
<?php if ($problem): ?>
  <?php echo log_message('{mainActions} been there', 'err') ?>
<?php endif ?>

And elsewhere within the code (model, etc):

sfContext::getInstance()->getLogger()->info($message);
sfContext::getInstance()->getLogger()->err($message);

Debugging

// in an action
$this->debugMessage($message);
// in a template
<?php echo debug_message($message) ?>

Reference: Symfony Docs: Debugging

Posted in  Web Development   |     |  delicious  Digg

3 Responses to “Symfony exceptions, logging, and debugging”

  1. Hej, I am wondering:
    how could certain actions be logged in the db when executed? I d like, for instance, the save() actions of certain modules to be logged in the db to create an history table of what happens on the site.

    Except creating an history table and saving the informations I am interested in in every actions, The info logs don’t seem to be reusable. Could a propel behavior do that?

    Cool reading you,
    mvh, hervé

    By herve on Sep 15, 2008

  2. Hervé,

    If you want to log actions in the db when executed, I wouldn’t even use the sfLogger class and instead just add custom code to my objects save() methods.

    A propel behavior would be perfect for this kind of thing!!! I would take a look at some of the existing plugins that provide propel behaviors and then just dive in and write your own. It’d make a great plugin ;)
    -Scott

    By Scott Meves on Sep 15, 2008

  3. Hi,
    Thanks for the very helpful but simple post. With regards to logging messages in the database, I’m pretty sure you’d be able to extend the sfLogger class or something to do this. Not sure how at the moment, but I understand symfony enough to guess this would be achievable!
    Steve

    By Steve B on Jan 5, 2009

Post a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word