News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

PHPMaster.com:
Logging with PSR-3 to Improve Reusability
February 07, 2013 @ 10:22:26

On PHPMaster.com Patrick Mulvey has written up a new tutorial looking at using the PSR-3 logging structure to make a basic logger for your application.

Logging is one of the most ubiquitous tasks encountered in PHP. We use logs to track error messages, record important events, and debug problems with our code. In any PHP project, the code is likely to be full of calls to a logging library which handles these actions for us. [...] To promote compatibility between logging libraries, the PHP-FIG group recently released PRS-3, a common interface for logger objects. In this article, I'll discuss how the logger interface defined by PSR-3 allows us to write reusable code that isn't dependent on any particular logging implementation.

He includes a quick introduction to the PSR-3 format, how to get the files you'll need to use it (via Composer). He includes some sample code showing how to make the basic email class with a logger injected for use. Since the Monolog logging project follows the PSR-3 format, it's an easy drop-in option. He also talks about using PSR-3 to avoid having logger dependencies with the "LoggerInterface". There's also a bit at the end of the tutorial showing you how to use the Adapter design pattern to "proxy" the logging calls to the class via a PSR-3 interface.

0 comments voice your opinion now!
psr3 logging reusability tutorial monolog dependency adapter designpattern


blog comments powered by Disqus

Similar Posts

Lorna Mitchell' Blog: PHP OAuth Provider: Access Tokens

MaltBlue.com: Zend Framework 2 Core Concepts - Dependency Injection

Vid Luther's Blog: Talking to multiple databases with Symfony 1.2

Noupe.com: 20 Useful PHP + jQuery Components & Tuts for Everyday Project

Fabien Potencier's Blog: Create your own framework... on top of the Symfony2 Components (part 2)


Community Events





Don't see your event here?
Let us know!


language conference bugfix laravel release voicesoftheelephpant podcast introduction zendserver api list threedevsandamaybe interview community series code framework tips symfony deployment

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework