Logger.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /**
  73. * @deprecated
  74. */
  75. public function emerg($message, array $context = array())
  76. {
  77. trigger_error('Use emergency() which is PSR-3 compatible', E_USER_DEPRECATED);
  78. $this->log('emergency', $message, $context);
  79. }
  80. /**
  81. * @deprecated
  82. */
  83. public function crit($message, array $context = array())
  84. {
  85. trigger_error('Use crit() which is PSR-3 compatible', E_USER_DEPRECATED);
  86. $this->log('critical', $message, $context);
  87. }
  88. /**
  89. * @deprecated
  90. */
  91. public function err($message, array $context = array())
  92. {
  93. trigger_error('Use err() which is PSR-3 compatible', E_USER_DEPRECATED);
  94. $this->log('error', $message, $context);
  95. }
  96. /**
  97. * @deprecated
  98. */
  99. public function warn($message, array $context = array())
  100. {
  101. trigger_error('Use warn() which is PSR-3 compatible', E_USER_DEPRECATED);
  102. $this->log('warning', $message, $context);
  103. }
  104. }