[BUGFIX] LogLevelTest dataProvider not used
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Log / LogLevel.php
1 <?php
2 namespace TYPO3\CMS\Core\Log;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2012 Ingo Renner (ingo@typo3.org)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Log levels according to RFC 3164
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 * @package TYPO3
31 * @subpackage t3lib
32 */
33 class LogLevel {
34
35 /**
36 * Emergency: system is unusable
37 *
38 * You'd likely not be able to reach the system. You better have an SLA in
39 * place when this happens.
40 *
41 * @var integer
42 */
43 const EMERGENCY = 0;
44 /**
45 * Alert: action must be taken immediately
46 *
47 * Example: Entire website down, database unavailable, etc.
48 *
49 * @var integer
50 */
51 const ALERT = 1;
52 /**
53 * Critical: critical conditions
54 *
55 * Example: unexpected exception.
56 *
57 * @var integer
58 */
59 const CRITICAL = 2;
60 /**
61 * Error: error conditions
62 *
63 * Example: Runtime error.
64 *
65 * @var integer
66 */
67 const ERROR = 3;
68 /**
69 * Warning: warning conditions
70 *
71 * Examples: Use of deprecated APIs, undesirable things that are not
72 * necessarily wrong.
73 *
74 * @var integer
75 */
76 const WARNING = 4;
77 /**
78 * Notice: normal but significant condition
79 *
80 * Example: things you should have a look at, nothing to worry about though.
81 *
82 * @var integer
83 */
84 const NOTICE = 5;
85 /**
86 * Informational: informational messages
87 *
88 * Examples: User logs in, SQL logs.
89 *
90 * @var integer
91 */
92 const INFO = 6;
93 /**
94 * Debug: debug-level messages
95 *
96 * Example: Detailed status information.
97 *
98 * @var integer
99 */
100 const DEBUG = 7;
101 /**
102 * Reverse look up of log level to level name.
103 *
104 * @var array
105 */
106 static protected $levels = array(
107 self::EMERGENCY => 'EMERGENCY',
108 self::ALERT => 'ALERT',
109 self::CRITICAL => 'CRITICAL',
110 self::ERROR => 'ERROR',
111 self::WARNING => 'WARNING',
112 self::NOTICE => 'NOTICE',
113 self::INFO => 'INFO',
114 self::DEBUG => 'DEBUG'
115 );
116
117 /**
118 * Resolves the name of a log level.
119 *
120 * @param integer $level Log level.
121 * @return string Log level name.
122 */
123 static public function getName($level) {
124 self::validateLevel($level);
125 return self::$levels[$level];
126 }
127
128 /**
129 * Checks a level for validity,
130 * whether it is an integer and in the range of 0-7.
131 *
132 * @param integer $level log level to validate
133 * @return boolean TRUE if the given log level is valid, FALSE otherwise
134 */
135 static public function isValidLevel($level) {
136 return \TYPO3\CMS\Core\Utility\MathUtility::isIntegerInRange($level, self::EMERGENCY, self::DEBUG);
137 }
138
139 /**
140 * Validates a log level.
141 *
142 * @param integer $level log level to validate
143 * @return void
144 * @throws \RangeException if the given log level is invalid
145 */
146 static public function validateLevel($level) {
147 if (!self::isValidLevel($level)) {
148 throw new \RangeException('Invalid Log Level.', 1321637121);
149 }
150 }
151
152 }
153
154
155 ?>