3 * @file src/Core/Logger.php
5 namespace Friendica\Core;
7 use Friendica\Core\Config;
8 use Friendica\Util\DataTimeFormat;
13 * @brief Logs the given message at the given log level
17 * LOGGER_INFO (default)
23 * @global array $LOGGER_LEVELS
27 public static function log($msg, $level = LOGGER_INFO)
30 global $LOGGER_LEVELS;
33 $debugging = Config::get('system', 'debugging');
34 $logfile = Config::get('system', 'logfile');
35 $loglevel = intval(Config::get('system', 'loglevel'));
45 if (count($LOGGER_LEVELS) == 0) {
46 foreach (get_defined_constants() as $k => $v) {
47 if (substr($k, 0, 7) == "LOGGER_") {
48 $LOGGER_LEVELS[$v] = substr($k, 7, 7);
53 $process_id = session_id();
55 if ($process_id == '') {
56 $process_id = get_app()->process_id;
59 $callers = debug_backtrace();
61 if (count($callers) > 1) {
62 $function = $callers[1]['function'];
67 $logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n",
68 DateTimeFormat::utcNow(DateTimeFormat::ATOM),
70 $LOGGER_LEVELS[$level],
71 basename($callers[0]['file']),
77 $stamp1 = microtime(true);
78 @file_put_contents($logfile, $logline, FILE_APPEND);
79 $a->saveTimestamp($stamp1, "file");
83 * @brief An alternative logger for development.
84 * Works largely as log() but allows developers
85 * to isolate particular elements they are targetting
86 * personally without background noise
90 * LOGGER_INFO (default)
96 * @global array $LOGGER_LEVELS
100 public static function devLog($msg, $level = LOGGER_INFO)
104 $logfile = Config::get('system', 'dlogfile');
109 $dlogip = Config::get('system', 'dlogip');
110 if (!is_null($dlogip) && $_SERVER['REMOTE_ADDR'] != $dlogip) {
114 if (count($LOGGER_LEVELS) == 0) {
115 foreach (get_defined_constants() as $k => $v) {
116 if (substr($k, 0, 7) == "LOGGER_") {
117 $LOGGER_LEVELS[$v] = substr($k, 7, 7);
122 $process_id = session_id();
124 if ($process_id == '') {
125 $process_id = $a->process_id;
128 $callers = debug_backtrace();
129 $logline = sprintf("%s@\t%s:\t%s:\t%s\t%s\t%s\n",
130 DateTimeFormat::utcNow(),
132 basename($callers[0]['file']),
134 $callers[1]['function'],
138 $stamp1 = microtime(true);
139 @file_put_contents($logfile, $logline, FILE_APPEND);
140 $a->saveTimestamp($stamp1, "file");