1*ee5c0205SAndreas GohrPSR Log 2*ee5c0205SAndreas Gohr======= 3*ee5c0205SAndreas Gohr 4*ee5c0205SAndreas GohrThis repository holds all interfaces/classes/traits related to 5*ee5c0205SAndreas Gohr[PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md). 6*ee5c0205SAndreas Gohr 7*ee5c0205SAndreas GohrNote that this is not a logger of its own. It is merely an interface that 8*ee5c0205SAndreas Gohrdescribes a logger. See the specification for more details. 9*ee5c0205SAndreas Gohr 10*ee5c0205SAndreas GohrInstallation 11*ee5c0205SAndreas Gohr------------ 12*ee5c0205SAndreas Gohr 13*ee5c0205SAndreas Gohr```bash 14*ee5c0205SAndreas Gohrcomposer require psr/log 15*ee5c0205SAndreas Gohr``` 16*ee5c0205SAndreas Gohr 17*ee5c0205SAndreas GohrUsage 18*ee5c0205SAndreas Gohr----- 19*ee5c0205SAndreas Gohr 20*ee5c0205SAndreas GohrIf you need a logger, you can use the interface like this: 21*ee5c0205SAndreas Gohr 22*ee5c0205SAndreas Gohr```php 23*ee5c0205SAndreas Gohr<?php 24*ee5c0205SAndreas Gohr 25*ee5c0205SAndreas Gohruse Psr\Log\LoggerInterface; 26*ee5c0205SAndreas Gohr 27*ee5c0205SAndreas Gohrclass Foo 28*ee5c0205SAndreas Gohr{ 29*ee5c0205SAndreas Gohr private $logger; 30*ee5c0205SAndreas Gohr 31*ee5c0205SAndreas Gohr public function __construct(LoggerInterface $logger = null) 32*ee5c0205SAndreas Gohr { 33*ee5c0205SAndreas Gohr $this->logger = $logger; 34*ee5c0205SAndreas Gohr } 35*ee5c0205SAndreas Gohr 36*ee5c0205SAndreas Gohr public function doSomething() 37*ee5c0205SAndreas Gohr { 38*ee5c0205SAndreas Gohr if ($this->logger) { 39*ee5c0205SAndreas Gohr $this->logger->info('Doing work'); 40*ee5c0205SAndreas Gohr } 41*ee5c0205SAndreas Gohr 42*ee5c0205SAndreas Gohr try { 43*ee5c0205SAndreas Gohr $this->doSomethingElse(); 44*ee5c0205SAndreas Gohr } catch (Exception $exception) { 45*ee5c0205SAndreas Gohr $this->logger->error('Oh no!', array('exception' => $exception)); 46*ee5c0205SAndreas Gohr } 47*ee5c0205SAndreas Gohr 48*ee5c0205SAndreas Gohr // do something useful 49*ee5c0205SAndreas Gohr } 50*ee5c0205SAndreas Gohr} 51*ee5c0205SAndreas Gohr``` 52*ee5c0205SAndreas Gohr 53*ee5c0205SAndreas GohrYou can then pick one of the implementations of the interface to get a logger. 54*ee5c0205SAndreas Gohr 55*ee5c0205SAndreas GohrIf you want to implement the interface, you can require this package and 56*ee5c0205SAndreas Gohrimplement `Psr\Log\LoggerInterface` in your code. Please read the 57*ee5c0205SAndreas Gohr[specification text](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) 58*ee5c0205SAndreas Gohrfor details. 59