3 * @file src/Core/Logger.php
5 namespace Friendica\Core;
7 use Friendica\Core\Config;
8 use Friendica\Util\DateTimeFormat;
12 * @brief Logger functions
14 class Logger extends BaseObject
24 public static $levels = [];
27 * @brief Get class constants, and avoid using substring.
29 public static function getConstants()
31 $reflectionClass = new ReflectionClass(__CLASS__);
32 return $reflectionClass->getConstants();
36 * @brief Logs the given message at the given log level
41 public static function log($msg, $level = self::INFO)
45 $debugging = Config::get('system', 'debugging');
46 $logfile = Config::get('system', 'logfile');
47 $loglevel = intval(Config::get('system', 'loglevel'));
57 if (count(self::$levels) == 0)
59 foreach (self::getConstants() as $k => $v)
65 $processId = session_id();
69 $processId = $a->process_id;
72 $callers = debug_backtrace();
74 if (count($callers) > 1) {
75 $function = $callers[1]['function'];
80 $logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n",
81 DateTimeFormat::utcNow(DateTimeFormat::ATOM),
84 basename($callers[0]['file']),
90 $stamp1 = microtime(true);
91 @file_put_contents($logfile, $logline, FILE_APPEND);
92 $a->saveTimestamp($stamp1, "file");
96 * @brief An alternative logger for development.
97 * Works largely as log() but allows developers
98 * to isolate particular elements they are targetting
99 * personally without background noise
104 public static function devLog($msg, $level = self::INFO)
108 $logfile = Config::get('system', 'dlogfile');
114 $dlogip = Config::get('system', 'dlogip');
116 if (!is_null($dlogip) && $_SERVER['REMOTE_ADDR'] != $dlogip)
121 if (count(self::$levels) == 0)
123 foreach (self::getConstants() as $k => $v)
129 $processId = session_id();
131 if ($processId == '')
133 $processId = $a->process_id;
136 $callers = debug_backtrace();
137 $logline = sprintf("%s@\t%s:\t%s:\t%s\t%s\t%s\n",
138 DateTimeFormat::utcNow(),
140 basename($callers[0]['file']),
142 $callers[1]['function'],
146 $stamp1 = microtime(true);
147 @file_put_contents($logfile, $logline, FILE_APPEND);
148 $a->saveTimestamp($stamp1, "file");