Logger.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests;
  11. use Psr\Log\LoggerInterface;
  12. class Logger implements LoggerInterface
  13. {
  14. protected $logs;
  15. public function __construct()
  16. {
  17. $this->clear();
  18. }
  19. public function getLogs($level = false)
  20. {
  21. return false === $level ? $this->logs : $this->logs[$level];
  22. }
  23. public function clear()
  24. {
  25. $this->logs = [
  26. 'emergency' => [],
  27. 'alert' => [],
  28. 'critical' => [],
  29. 'error' => [],
  30. 'warning' => [],
  31. 'notice' => [],
  32. 'info' => [],
  33. 'debug' => [],
  34. ];
  35. }
  36. public function log($level, $message, array $context = [])
  37. {
  38. $this->logs[$level][] = $message;
  39. }
  40. public function emergency($message, array $context = [])
  41. {
  42. $this->log('emergency', $message, $context);
  43. }
  44. public function alert($message, array $context = [])
  45. {
  46. $this->log('alert', $message, $context);
  47. }
  48. public function critical($message, array $context = [])
  49. {
  50. $this->log('critical', $message, $context);
  51. }
  52. public function error($message, array $context = [])
  53. {
  54. $this->log('error', $message, $context);
  55. }
  56. public function warning($message, array $context = [])
  57. {
  58. $this->log('warning', $message, $context);
  59. }
  60. public function notice($message, array $context = [])
  61. {
  62. $this->log('notice', $message, $context);
  63. }
  64. public function info($message, array $context = [])
  65. {
  66. $this->log('info', $message, $context);
  67. }
  68. public function debug($message, array $context = [])
  69. {
  70. $this->log('debug', $message, $context);
  71. }
  72. }