暂无描述

Logger.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 = array(
  26. 'emergency' => array(),
  27. 'alert' => array(),
  28. 'critical' => array(),
  29. 'error' => array(),
  30. 'warning' => array(),
  31. 'notice' => array(),
  32. 'info' => array(),
  33. 'debug' => array(),
  34. );
  35. }
  36. public function log($level, $message, array $context = array())
  37. {
  38. $this->logs[$level][] = $message;
  39. }
  40. public function emergency($message, array $context = array())
  41. {
  42. $this->log('emergency', $message, $context);
  43. }
  44. public function alert($message, array $context = array())
  45. {
  46. $this->log('alert', $message, $context);
  47. }
  48. public function critical($message, array $context = array())
  49. {
  50. $this->log('critical', $message, $context);
  51. }
  52. public function error($message, array $context = array())
  53. {
  54. $this->log('error', $message, $context);
  55. }
  56. public function warning($message, array $context = array())
  57. {
  58. $this->log('warning', $message, $context);
  59. }
  60. public function notice($message, array $context = array())
  61. {
  62. $this->log('notice', $message, $context);
  63. }
  64. public function info($message, array $context = array())
  65. {
  66. $this->log('info', $message, $context);
  67. }
  68. public function debug($message, array $context = array())
  69. {
  70. $this->log('debug', $message, $context);
  71. }
  72. }