The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Log level in custom log writer

Alexander's Avatar

Alexander

16 Apr, 2012 10:23 AM

Hi!
How can i fetch log level in custom log writer, which receives only one parameter - message object, but not log level.
Thanx!

  1. Support Staff 1 Posted by Andrew Smith on 16 Apr, 2012 10:53 AM

    Andrew Smith's Avatar

    Hi Alexander,

    There is a setLevel public method available in the Slim_Log class, if you are extending this class you can use that to set the level. I am taking reference from 1.6.0 codebase, if you are using another codebase let me know.

    https://github.com/codeguy/Slim/blob/master/Slim/Log.php#L121

  2. 2 Posted by Alexander on 16 Apr, 2012 11:06 AM

    Alexander's Avatar

    You misunderstood my problem. I created separate class, which has public method write(), and i specify this class as writer in Slim:
    $slimApp->getLog()->setWriter(new MyWriterClass); When application send a message to MyWriterClass::write(), for example:
    $slimApp->info('Message'); method write receives only message string, but not level of message too. How can i determine level of message, which sent to method MyWriterClass::write()?

  3. Support Staff 3 Posted by Andrew Smith on 16 Apr, 2012 11:10 AM

    Andrew Smith's Avatar

    Hi Alexander, can you state the version of Slim you are using, then I can tell you how to accomplish this. Also when writing code on here put 4 spaces before the code on a new line and it will be written in a code block.

  4. 4 Posted by Alexander on 16 Apr, 2012 11:12 AM

    Alexander's Avatar

    1.6.0

  5. 5 Posted by Alexander on 16 Apr, 2012 11:18 AM

    Alexander's Avatar

    Actually I'm talking about is: https://github.com/codeguy/Slim/blob/master/Slim/Log.php#L214 , where no level transmitted to method write().

  6. Support Staff 6 Posted by Andrew Smith on 16 Apr, 2012 11:20 AM

    Andrew Smith's Avatar

    The level depends on which public function you use currently Slim has:

    $app->debug(); - level 4
    $app->info(); - level 3
    $app->warn(); - level 2
    $app->error(); - level 1
    $app->fatal(); - level 0
    

    Hope that helps.

  7. 7 Posted by Alexander on 16 Apr, 2012 11:23 AM

    Alexander's Avatar

    Yes, I understand that. But how do I determine the level of error in my method, write (), which is called from https://github.com/codeguy/Slim/blob/master/Slim/Log.php#L214

  8. Support Staff 8 Posted by Andrew Smith on 16 Apr, 2012 11:24 AM

    Andrew Smith's Avatar

    Ok just saw that, it's a bug, I will raise it with Josh and get it fix in there soon. Or you can patch it and do a pull request.

  9. 9 Posted by Alexander on 16 Apr, 2012 11:34 AM

    Alexander's Avatar

    I just sent a pull-request with fix of this problem.

  10. Support Staff 10 Posted by Josh Lockhart on 16 Apr, 2012 01:10 PM

    Josh Lockhart's Avatar

    @Alexander Custom writers are only meant to write output to a given destination. The Slim_Log class is used to filter what is written based on the log level.

    I'll have a look at your pull request later this evening.

  11. 11 Posted by bobp on 16 Apr, 2012 01:25 PM

    bobp's Avatar

    +1 for this. I wanted my log messages look like this:

    2012-04-16 12:56:08 [WARNING] Something interesting happened

    So I actually wound up modifying the Slim log write() interface to add the log level as a parameter to my write() method.

    But it would be great if Slim supported passing the log level on the write() method out-of -the box.

  12. 12 Posted by Alexander on 16 Apr, 2012 04:04 PM

    Alexander's Avatar

    Custom writers are only meant to write output to a given destination Okay, but how can I determine level of message, which was sent?

  13. Support Staff 13 Posted by Josh Lockhart on 16 Apr, 2012 04:06 PM

    Josh Lockhart's Avatar

    I agree this information would be helpful. I'll pull your changes into 1.6.1 when that is released later this week.

  14. 14 Posted by Alexander on 16 Apr, 2012 05:02 PM

    Alexander's Avatar

    Thank You!

  15. Andrew Smith closed this discussion on 01 Aug, 2012 12:53 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac