Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding PHP-FIG : PSR-3 (Logger Interface)

As a learning experience I am building a PHP based CMS using the FIG standards. Can someone explain to me how I should integrate PSR-3 into my project. I downloaded the source @ https://github.com/php-fig/log/tree/master/Psr/Log and I guess I am lost on how to proceed.

I don't understand what LoggerAwareInterface does. Should I modify the above source to work actually log the data how I want or does this work as a wrapper to my own log class. Any help/information would be appreciate.

P.S. I should note that the best guide I was able to find was http://phpmaster.com/logging-with-psr-3-to-improve-reusability/ (specifically the section : Using PSR-3 to Avoid the Logger Dependency) and it still didn't click for me.

like image 475
hendr1x Avatar asked Jun 15 '13 15:06

hendr1x


1 Answers

Just in case someone searches and finds this I figured I should share what I've learned.

The answer I came up with is create a class called Log in your designated names space. To make things easier I simply setup my class to extend \Psr\Log\AbstractLogger. Because I did this I simply had to add a method called log with the params :

$level, $message, array $context = array()

If you didn't want do this simply create a class that has all the methods in AbstractLogger and then set it up to implment \Psr\Log\LoggerInterface

That's it.

like image 59
hendr1x Avatar answered Oct 02 '22 20:10

hendr1x