Pull merge.
[yaffs-website] / vendor / consolidation / log / README.md
1 # Consolidation\Log
2
3 Improved [PSR-3](http://www.php-fig.org/psr/psr-3/) [Psr\Log](https://github.com/php-fig/log) logger based on Symfony Console components.
4
5 [![Travis CI](https://travis-ci.org/consolidation-org/log.svg?branch=master)](https://travis-ci.org/consolidation-org/log) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/consolidation-org/log/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/consolidation-org/log/?branch=master) [![Coverage Status](https://coveralls.io/repos/github/consolidation-org/log/badge.svg?branch=master)](https://coveralls.io/github/consolidation-org/log?branch=master) [![License](https://poser.pugx.org/consolidation/log/license)](https://packagist.org/packages/consolidation/log)
6
7 ## Component Status
8
9 In use in [Robo](https://github.com/Codegyre/Robo).
10
11 ## Motivation
12
13 Consolidation\Log provides a Psr-3 compatible logger that provides styled log output to the standard error (stderr) stream. By default, styling is provided by the SymfonyStyle class from the Symfony Console component; however, alternative stylers may be provided if desired.
14
15 ## Usage
16 ```
17 $logger = new \Consolidation\Log\Logger($output);
18 $logger->setLogOutputStyler(new LogOutputStyler()); // optional
19 $logger->warning('The file {name} does not exist.', ['name' => $filename]);
20 ```
21 String interpolation -- that is, the substitution of replacements, such as `{name}` in the example above, is not required by Psr-3, and is not implemented by default in the Psr\Log project. However, it is recommended by PRS-3, and is often done, e.g. in the Symfony Console logger.
22
23 Consolidation\Log supports string interpolation.
24
25 ## Comparison to Existing Solutions
26
27 Many Symfony Console compoenents use SymfonyStyle to format their output messages. This helper class has methods named things like `success` and `warning`, making it seem like a natural choice for reporting status.
28
29 However, in practice it is much more convenient to use an actual Psr-3 logger for logging. Doing this allows a Symfony Console component to call an external library that may not need to depend on Symfony Style.  Having the Psr\Log\LoggerInterface serve as the only shared IO-related interface in common between the console tool and the libraries it depends on promots loose coupling, allowing said libraries to be re-used in other contexts which may wish to log in different ways.
30
31 Symfony Console provides the ConsoleLogger to fill this need; however, ConsoleLogger does not provide any facility for styling output, leaving SymfonyStyle as the preferred logging mechanism for style-conscienscious console coders.
32
33 Consolidation\Log provides the benefits of both classes, allowing for code that both behaved technically correctly (redirecting to stderr) without sacrificing on style.
34
35 Monlog also provides a full-featured Console logger that might be applicable for some use cases.