RfcLogLevel.php 2.78 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

/**
 * @file
 * Contains \Drupal\Core\Logger\RfcLogLevel.
 */

namespace Drupal\Core\Logger;

use Drupal\Core\StringTranslation\TranslationWrapper;

/**
 * @defgroup logging_severity_levels Logging severity levels
 * @{
 * Logging severity levels as defined in RFC 5424.
 *
 * The constant definitions of this class correspond to the logging severity
 * levels defined in RFC 5424, section 4.1.1. PHP supplies predefined LOG_*
 * constants for use in the syslog() function, but their values on Windows
 * builds do not correspond to RFC 5424. The associated PHP bug report was
 * closed with the comment, "And it's also not a bug, as Windows just have less
 * log levels," and "So the behavior you're seeing is perfectly normal."
 *
 * @see http://tools.ietf.org/html/rfc5424
 * @see http://bugs.php.net/bug.php?id=18090
 * @see http://php.net/manual/function.syslog.php
 * @see http://php.net/manual/network.constants.php
 * @see self::getLevels()
 *
 * @} End of "defgroup logging_severity_levels".
 */
32
33
34
35
36
37

/**
 * Defines various logging severity levels.
 *
 * @ingroup logging_severity_levels
 */
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class RfcLogLevel {

  /**
   * Log message severity -- Emergency: system is unusable.
   */
  const EMERGENCY = 0;

  /**
   * Log message severity -- Alert: action must be taken immediately.
   */
  const ALERT = 1;

  /**
   * Log message severity -- Critical conditions.
   */
  const CRITICAL = 2;

  /**
   * Log message severity -- Error conditions.
   */
  const ERROR = 3;

  /**
   * Log message severity -- Warning conditions.
   */
  const WARNING = 4;

  /**
   * Log message severity -- Normal but significant conditions.
   */
  const NOTICE = 5;

  /**
   * Log message severity -- Informational messages.
   */
  const INFO = 6;

  /**
   * Log message severity -- Debug-level messages.
   */
  const DEBUG = 7;

  /**
   * An array with the severity levels as keys and labels as values.
   *
   * @var array
   */
  protected static $levels;

  /**
   * Returns a list of severity levels, as defined in RFC 5424.
   *
   * @return array
   *   Array of the possible severity levels for log messages.
   *
   * @see http://tools.ietf.org/html/rfc5424
   * @ingroup logging_severity_levels
   */
  public static function getLevels() {
    if (!static::$levels) {
      static::$levels = [
        static::EMERGENCY => new TranslationWrapper('Emergency'),
        static::ALERT => new TranslationWrapper('Alert'),
        static::CRITICAL => new TranslationWrapper('Critical'),
        static::ERROR => new TranslationWrapper('Error'),
        static::WARNING => new TranslationWrapper('Warning'),
        static::NOTICE => new TranslationWrapper('Notice'),
        static::INFO => new TranslationWrapper('Info'),
        static::DEBUG => new TranslationWrapper('Debug'),
      ];
    }

    return static::$levels;
  }

}