Symfony And Debugging


Table of Contents

How to use Logger 
How to use Logger 
How to use Logger 
How to use Logger 

How to use Logger 

http://www.symfony-project.org/forum/index.php?t=msg&goto=30435

> I'm new on Symfony, and i'm not able to find how use a Logger object to
> trace code execution in my Action class or Template file,

in an action you can do:

$this->logMessage($message);

or you can do this everywhere:

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

documented on: 28 June 2007, al_n

How to use Logger 

For debugging purpose, better use

$this->logMessage($message, 'debug');

or,

$this->debugMessage($message);

or,

sfContext::getInstance()->getLogger()->debug($message);

instead.

documented on: 2007.08.23, xpt

How to use Logger 

> And how i can use it in template ?

you could use the Debug Helper in Templates see:

http://www.symfony-project.org/book/trunk/16-Application-Management-Tools#Debugging

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

documented on: 28 June 2007, torsten

How to use Logger 

 

You shouldn't use it [logger] in a template - that would break the MVC model.

MVC, as I am sure you know, is about the separation of concerns between logic and presentation. I regard application logging as logic that firmly does not belong in the presentation layer, so I would still maintain that my comment was correct. Debugging logging, on the other hand, can go anywhere, which is perhaps what you had in mind.

 
 -- halfer

when people are asking about logging in order to *trace code execution* then I assume they are trying to debug something. You can surely understand that debugging is also something you are doing in your presentation layer. More then that, logging is not logic, its just …. logging, and it is not breaking the definition of the MVC design pattern if it happens in the view.

documented on: 28 June 2007, al_n