Logging from symfony's model layer

Posted by naag on Stack Overflow See other posts from Stack Overflow or by naag
Published on 2010-04-04T16:45:35Z Indexed on 2010/04/04 16:53 UTC
Read the original article Hit count: 329

Filed under:
|
|

I'm currently working on a project with symfony 1.4 and Doctrine 1.2. I'm looking for a proper way to do logging from the model layer.

In some model classes I use the record hook postSave() to create a ZIP file using exec() (since PHP zip doesn't provide for storage method 'Stored'). To be sure that everythings works fine I check the return code and log an error if something goes wrong. My first naive approach was to do it like this:

if ($returnCode != 0) {
  sfContext::getInstance()->getLogger()->debug(...);
}

As you know, this doesn't work so well because sfContext belongs to the controller layer and shouldn't be used from the model layer. My next try was to use the model's constructor to pass in an sfLogger instance, but this doesn't work due to Doctrine 1.2 reserving the constructor for internal use (Doctrine 1.2 Documentation).

I'm looking forward for your suggestions!

© Stack Overflow or respective owner

Related posts about symfony

Related posts about symfony-1.4