RfcLogLevel.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Drupal\Core\Logger;
  3. use Drupal\Core\StringTranslation\TranslatableMarkup;
  4. /**
  5. * @defgroup logging_severity_levels Logging severity levels
  6. * @{
  7. * Logging severity levels as defined in RFC 5424.
  8. *
  9. * The constant definitions of this class correspond to the logging severity
  10. * levels defined in RFC 5424, section 6.2.1. PHP supplies predefined LOG_*
  11. * constants for use in the syslog() function, but their values on Windows
  12. * builds do not correspond to RFC 5424. The associated PHP bug report was
  13. * closed with the comment, "And it's also not a bug, as Windows just have less
  14. * log levels," and "So the behavior you're seeing is perfectly normal."
  15. *
  16. * @see https://tools.ietf.org/html/rfc5424#section-6.2.1
  17. * @see http://bugs.php.net/bug.php?id=18090
  18. * @see http://php.net/manual/function.syslog.php
  19. * @see http://php.net/manual/network.constants.php
  20. * @see \Drupal\Core\Logger\RfcLogLevel::getLevels()
  21. *
  22. * @}
  23. */
  24. /**
  25. * Defines various logging severity levels.
  26. *
  27. * @ingroup logging_severity_levels
  28. */
  29. class RfcLogLevel {
  30. /**
  31. * Log message severity -- Emergency: system is unusable.
  32. */
  33. const EMERGENCY = 0;
  34. /**
  35. * Log message severity -- Alert: action must be taken immediately.
  36. */
  37. const ALERT = 1;
  38. /**
  39. * Log message severity -- Critical conditions.
  40. */
  41. const CRITICAL = 2;
  42. /**
  43. * Log message severity -- Error conditions.
  44. */
  45. const ERROR = 3;
  46. /**
  47. * Log message severity -- Warning conditions.
  48. */
  49. const WARNING = 4;
  50. /**
  51. * Log message severity -- Normal but significant conditions.
  52. */
  53. const NOTICE = 5;
  54. /**
  55. * Log message severity -- Informational messages.
  56. */
  57. const INFO = 6;
  58. /**
  59. * Log message severity -- Debug-level messages.
  60. */
  61. const DEBUG = 7;
  62. /**
  63. * An array with the severity levels as keys and labels as values.
  64. *
  65. * @var array
  66. */
  67. protected static $levels;
  68. /**
  69. * Returns a list of severity levels, as defined in RFC 5424.
  70. *
  71. * @return array
  72. * Array of the possible severity levels for log messages.
  73. *
  74. * @see http://tools.ietf.org/html/rfc5424
  75. * @ingroup logging_severity_levels
  76. */
  77. public static function getLevels() {
  78. if (!static::$levels) {
  79. static::$levels = [
  80. static::EMERGENCY => new TranslatableMarkup('Emergency'),
  81. static::ALERT => new TranslatableMarkup('Alert'),
  82. static::CRITICAL => new TranslatableMarkup('Critical'),
  83. static::ERROR => new TranslatableMarkup('Error'),
  84. static::WARNING => new TranslatableMarkup('Warning'),
  85. static::NOTICE => new TranslatableMarkup('Notice'),
  86. static::INFO => new TranslatableMarkup('Info'),
  87. static::DEBUG => new TranslatableMarkup('Debug'),
  88. ];
  89. }
  90. return static::$levels;
  91. }
  92. }