You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

2 years ago
  1. PSR Log
  2. =======
  3. This repository holds all interfaces/classes/traits related to
  4. [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md).
  5. Note that this is not a logger of its own. It is merely an interface that
  6. describes a logger. See the specification for more details.
  7. Installation
  8. ------------
  9. ```bash
  10. composer require psr/log
  11. ```
  12. Usage
  13. -----
  14. If you need a logger, you can use the interface like this:
  15. ```php
  16. <?php
  17. use Psr\Log\LoggerInterface;
  18. class Foo
  19. {
  20. private $logger;
  21. public function __construct(LoggerInterface $logger = null)
  22. {
  23. $this->logger = $logger;
  24. }
  25. public function doSomething()
  26. {
  27. if ($this->logger) {
  28. $this->logger->info('Doing work');
  29. }
  30. try {
  31. $this->doSomethingElse();
  32. } catch (Exception $exception) {
  33. $this->logger->error('Oh no!', array('exception' => $exception));
  34. }
  35. // do something useful
  36. }
  37. }
  38. ```
  39. You can then pick one of the implementations of the interface to get a logger.
  40. If you want to implement the interface, you can require this package and
  41. implement `Psr\Log\LoggerInterface` in your code. Please read the
  42. [specification text](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md)
  43. for details.