Mercurial > hg > isophonics-drupal-site
annotate vendor/psr/log/README.md @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 129ea1e6d783 |
children |
rev | line source |
---|---|
Chris@0 | 1 PSR Log |
Chris@0 | 2 ======= |
Chris@0 | 3 |
Chris@0 | 4 This repository holds all interfaces/classes/traits related to |
Chris@0 | 5 [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md). |
Chris@0 | 6 |
Chris@0 | 7 Note that this is not a logger of its own. It is merely an interface that |
Chris@0 | 8 describes a logger. See the specification for more details. |
Chris@0 | 9 |
Chris@17 | 10 Installation |
Chris@17 | 11 ------------ |
Chris@17 | 12 |
Chris@17 | 13 ```bash |
Chris@17 | 14 composer require psr/log |
Chris@17 | 15 ``` |
Chris@17 | 16 |
Chris@0 | 17 Usage |
Chris@0 | 18 ----- |
Chris@0 | 19 |
Chris@0 | 20 If you need a logger, you can use the interface like this: |
Chris@0 | 21 |
Chris@0 | 22 ```php |
Chris@0 | 23 <?php |
Chris@0 | 24 |
Chris@0 | 25 use Psr\Log\LoggerInterface; |
Chris@0 | 26 |
Chris@0 | 27 class Foo |
Chris@0 | 28 { |
Chris@0 | 29 private $logger; |
Chris@0 | 30 |
Chris@0 | 31 public function __construct(LoggerInterface $logger = null) |
Chris@0 | 32 { |
Chris@0 | 33 $this->logger = $logger; |
Chris@0 | 34 } |
Chris@0 | 35 |
Chris@0 | 36 public function doSomething() |
Chris@0 | 37 { |
Chris@0 | 38 if ($this->logger) { |
Chris@0 | 39 $this->logger->info('Doing work'); |
Chris@0 | 40 } |
Chris@0 | 41 |
Chris@0 | 42 // do something useful |
Chris@0 | 43 } |
Chris@0 | 44 } |
Chris@0 | 45 ``` |
Chris@0 | 46 |
Chris@0 | 47 You can then pick one of the implementations of the interface to get a logger. |
Chris@0 | 48 |
Chris@0 | 49 If you want to implement the interface, you can require this package and |
Chris@0 | 50 implement `Psr\Log\LoggerInterface` in your code. Please read the |
Chris@0 | 51 [specification text](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) |
Chris@0 | 52 for details. |