PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.6.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.6.0
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Log.php
matomo / app / core Last commit date
API 4 years ago Access 5 years ago Application 4 years ago Archive 4 years ago ArchiveProcessor 4 years ago Archiver 5 years ago AssetManager 4 years ago Auth 5 years ago Category 5 years ago CliMulti 4 years ago Columns 5 years ago Concurrency 4 years ago Config 5 years ago Container 4 years ago CronArchive 4 years ago DataAccess 4 years ago DataFiles 5 years ago DataTable 4 years ago Db 4 years ago DeviceDetector 4 years ago Email 5 years ago Exception 4 years ago Http 5 years ago Intl 4 years ago Mail 5 years ago Measurable 5 years ago Menu 5 years ago Metrics 4 years ago Notification 4 years ago Period 4 years ago Plugin 4 years ago ProfessionalServices 5 years ago Report 5 years ago ReportRenderer 5 years ago Scheduler 4 years ago Segment 5 years ago Session 4 years ago Settings 5 years ago Tracker 4 years ago Translation 4 years ago UpdateCheck 5 years ago Updater 4 years ago Updates 4 years ago Validators 4 years ago View 4 years ago ViewDataTable 5 years ago Visualization 5 years ago Widget 5 years ago .htaccess 6 years ago Access.php 4 years ago Archive.php 4 years ago ArchiveProcessor.php 4 years ago AssetManager.php 5 years ago Auth.php 5 years ago AuthResult.php 5 years ago BaseFactory.php 5 years ago Cache.php 5 years ago CacheId.php 5 years ago CliMulti.php 4 years ago Common.php 4 years ago Config.php 4 years ago Console.php 5 years ago Context.php 5 years ago Cookie.php 4 years ago CronArchive.php 4 years ago DataArray.php 4 years ago DataTable.php 4 years ago Date.php 4 years ago Db.php 4 years ago DbHelper.php 4 years ago Development.php 5 years ago ErrorHandler.php 5 years ago EventDispatcher.php 4 years ago ExceptionHandler.php 4 years ago FileIntegrity.php 5 years ago Filechecks.php 5 years ago Filesystem.php 4 years ago FrontController.php 4 years ago Http.php 4 years ago IP.php 4 years ago Log.php 4 years ago LogDeleter.php 4 years ago Mail.php 4 years ago Metrics.php 5 years ago NoAccessException.php 5 years ago Nonce.php 4 years ago Notification.php 5 years ago NumberFormatter.php 5 years ago Option.php 4 years ago Period.php 5 years ago Piwik.php 4 years ago Plugin.php 4 years ago Profiler.php 4 years ago ProxyHeaders.php 5 years ago ProxyHttp.php 4 years ago QuickForm2.php 5 years ago RankingQuery.php 5 years ago ReportRenderer.php 5 years ago Segment.php 5 years ago Sequence.php 5 years ago Session.php 4 years ago SettingsPiwik.php 5 years ago SettingsServer.php 5 years ago Singleton.php 5 years ago Site.php 4 years ago SupportedBrowser.php 4 years ago TCPDF.php 5 years ago Theme.php 5 years ago Timer.php 5 years ago Tracker.php 4 years ago Twig.php 4 years ago Unzip.php 5 years ago UpdateCheck.php 5 years ago Updater.php 5 years ago UpdaterErrorException.php 5 years ago Updates.php 5 years ago Url.php 4 years ago UrlHelper.php 4 years ago Version.php 4 years ago View.php 4 years ago bootstrap.php 5 years ago dispatch.php 5 years ago testMinimumPhpVersion.php 5 years ago
Log.php
261 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 */
8
9 namespace Piwik;
10
11 use Monolog\Logger;
12 use Piwik\Container\StaticContainer;
13 use Psr\Log\LoggerInterface;
14
15 /**
16 * Logging utility class.
17 *
18 * Log entries are made with a message and log level. The logging utility will tag each
19 * log entry with the name of the plugin that's doing the logging. If no plugin is found,
20 * the name of the current class is used.
21 *
22 * You can log messages using one of the public static functions (eg, 'error', 'warning',
23 * 'info', etc.).
24 *
25 * Currently, Piwik supports the following logging backends:
26 *
27 * - **screen**: logging to the screen
28 * - **file**: logging to a file
29 * - **database**: logging to Piwik's MySQL database
30 *
31 * Messages logged in the console will always be logged to the console output.
32 *
33 * ### Logging configuration
34 *
35 * The logging utility can be configured by manipulating the INI config options in the
36 * `[log]` section.
37 *
38 * The following configuration options can be set:
39 *
40 * - `log_writers[]`: This is an array of log writer IDs. The three log writers provided
41 * by Piwik core are **file**, **screen**, **database**, **errorlog**,
42 * and **syslog**. You can get more by installing plugins. The default
43 * value is **screen**.
44 * - `log_level`: The current log level. Can be **ERROR**, **WARN**, **INFO**, **DEBUG**,
45 * or **VERBOSE**. Log entries made with a log level that is as or more
46 * severe than the current log level will be outputted. Others will be
47 * ignored. The default level is **WARN**.
48 * - `logger_file_path`: For the file log writer, specifies the path to the log file
49 * to log to or a path to a directory to store logs in. If a
50 * directory, the file name is piwik.log. Can be relative to
51 * Piwik's root dir or an absolute path. Defaults to **tmp/logs**.
52 * - `logger_syslog_ident`: If configured to log to syslog, mark them with this
53 * identifier string. This acts as an easy-to-find tag in
54 * the syslog.
55 *
56 *
57 * @deprecated Inject and use Psr\Log\LoggerInterface instead of this class.
58 * @see \Psr\Log\LoggerInterface
59 */
60 class Log extends Singleton
61 {
62 // log levels
63 const NONE = 0;
64 const ERROR = 1;
65 const WARN = 2;
66 const INFO = 3;
67 const DEBUG = 4;
68 const VERBOSE = 5;
69
70 // config option names
71 const LOG_LEVEL_CONFIG_OPTION = 'log_level';
72 const LOG_WRITERS_CONFIG_OPTION = 'log_writers';
73 const LOGGER_FILE_PATH_CONFIG_OPTION = 'logger_file_path';
74 const STRING_MESSAGE_FORMAT_OPTION = 'string_message_format';
75
76 /**
77 * The backtrace string to use when testing.
78 *
79 * @var string
80 */
81 public static $debugBacktraceForTests;
82
83 /**
84 * Singleton instance.
85 *
86 * @var Log
87 */
88 private static $instance;
89
90 /**
91 * @var LoggerInterface
92 */
93 private $logger;
94
95 public static function getInstance()
96 {
97 if (self::$instance === null) {
98 self::$instance = StaticContainer::get(__CLASS__);
99 }
100 return self::$instance;
101 }
102 public static function unsetInstance()
103 {
104 self::$instance = null;
105 }
106 public static function setSingletonInstance($instance)
107 {
108 self::$instance = $instance;
109 }
110
111 /**
112 * @param LoggerInterface $logger
113 */
114 public function __construct(LoggerInterface $logger)
115 {
116 $this->logger = $logger;
117 }
118
119 /**
120 * Logs a message using the ERROR log level.
121 *
122 * @param string $message The log message. This can be a sprintf format string.
123 * @param ... mixed Optional sprintf params.
124 * @api
125 *
126 * @deprecated Inject and call Psr\Log\LoggerInterface::error() instead.
127 * @see \Psr\Log\LoggerInterface::error()
128 */
129 public static function error($message /* ... */)
130 {
131 self::logMessage(Logger::ERROR, $message, array_slice(func_get_args(), 1));
132 }
133
134 /**
135 * Logs a message using the WARNING log level.
136 *
137 * @param string $message The log message. This can be a sprintf format string.
138 * @param ... mixed Optional sprintf params.
139 * @api
140 *
141 * @deprecated Inject and call Psr\Log\LoggerInterface::warning() instead.
142 * @see \Psr\Log\LoggerInterface::warning()
143 */
144 public static function warning($message /* ... */)
145 {
146 self::logMessage(Logger::WARNING, $message, array_slice(func_get_args(), 1));
147 }
148
149 /**
150 * Logs a message using the INFO log level.
151 *
152 * @param string $message The log message. This can be a sprintf format string.
153 * @param ... mixed Optional sprintf params.
154 * @api
155 *
156 * @deprecated Inject and call Psr\Log\LoggerInterface::info() instead.
157 * @see \Psr\Log\LoggerInterface::info()
158 */
159 public static function info($message /* ... */)
160 {
161 self::logMessage(Logger::INFO, $message, array_slice(func_get_args(), 1));
162 }
163
164 /**
165 * Logs a message using the DEBUG log level.
166 *
167 * @param string $message The log message. This can be a sprintf format string.
168 * @param ... mixed Optional sprintf params.
169 * @api
170 *
171 * @deprecated Inject and call Psr\Log\LoggerInterface::debug() instead.
172 * @see \Psr\Log\LoggerInterface::debug()
173 */
174 public static function debug($message /* ... */)
175 {
176 self::logMessage(Logger::DEBUG, $message, array_slice(func_get_args(), 1));
177 }
178
179 /**
180 * Logs a message using the VERBOSE log level.
181 *
182 * @param string $message The log message. This can be a sprintf format string.
183 * @param ... mixed Optional sprintf params.
184 * @api
185 *
186 * @deprecated Inject and call Psr\Log\LoggerInterface::debug() instead (the verbose level doesn't exist in the PSR standard).
187 * @see \Psr\Log\LoggerInterface::debug()
188 */
189 public static function verbose($message /* ... */)
190 {
191 self::logMessage(Logger::DEBUG, $message, array_slice(func_get_args(), 1));
192 }
193
194 /**
195 * @param int $logLevel
196 * @deprecated Will be removed, log levels are now applied on each Monolog handler.
197 */
198 public function setLogLevel($logLevel)
199 {
200 }
201
202 /**
203 * @deprecated Will be removed, log levels are now applied on each Monolog handler.
204 */
205 public function getLogLevel()
206 {
207 }
208
209 private function doLog($level, $message, $parameters = array())
210 {
211 // To ensure the compatibility with PSR-3, the message must be a string
212 if ($message instanceof \Exception) {
213 $parameters['exception'] = $message;
214 $message = $message->getMessage();
215 }
216
217 if (is_object($message) || is_array($message) || is_resource($message)) {
218 $this->logger->warning('Trying to log a message that is not a string', array(
219 'exception' => new \InvalidArgumentException('Trying to log a message that is not a string')
220 ));
221 return;
222 }
223
224 $this->logger->log($level, $message, $parameters);
225 }
226
227 private static function logMessage($level, $message, $parameters)
228 {
229 self::getInstance()->doLog($level, $message, $parameters);
230 }
231
232 public static function getMonologLevel($level)
233 {
234 switch ($level) {
235 case self::ERROR:
236 return Logger::ERROR;
237 case self::WARN:
238 return Logger::WARNING;
239 case self::INFO:
240 return Logger::INFO;
241 case self::DEBUG:
242 return Logger::DEBUG;
243 case self::VERBOSE:
244 return Logger::DEBUG;
245 case self::NONE:
246 default:
247 // Highest level possible, need to do better in the future...
248 return Logger::EMERGENCY;
249 }
250 }
251
252 public static function getMonologLevelIfValid($level)
253 {
254 $level = strtoupper($level);
255 if (!empty($level) && defined('Piwik\Log::'.strtoupper($level))) {
256 return self::getMonologLevel(constant('Piwik\Log::'.strtoupper($level)));
257 }
258 return null;
259 }
260 }
261