3 * @file src/Core/Logger.php
5 namespace Friendica\Core;
7 use Friendica\BaseObject;
8 use Friendica\Core\Config;
9 use Friendica\Util\DateTimeFormat;
13 * @brief Logger functions
15 class Logger extends BaseObject
25 public static $levels = [
26 self::WARNING => 'Warning',
28 self::TRACE => 'Trace',
29 self::DEBUG => 'Debug',
35 * @brief Logs the given message at the given log level
40 public static function log($msg, $level = self::INFO)
44 $debugging = Config::get('system', 'debugging');
45 $logfile = Config::get('system', 'logfile');
46 $loglevel = intval(Config::get('system', 'loglevel'));
56 $processId = session_id();
60 $processId = $a->process_id;
63 $callers = debug_backtrace();
65 if (count($callers) > 1) {
66 $function = $callers[1]['function'];
71 $logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n",
72 DateTimeFormat::utcNow(DateTimeFormat::ATOM),
74 self::$levels[$level],
75 basename($callers[0]['file']),
81 $stamp1 = microtime(true);
82 @file_put_contents($logfile, $logline, FILE_APPEND);
83 $a->saveTimestamp($stamp1, "file");
87 * @brief An alternative logger for development.
88 * Works largely as log() but allows developers
89 * to isolate particular elements they are targetting
90 * personally without background noise
94 public static function devLog($msg)
98 $logfile = Config::get('system', 'dlogfile');
104 $dlogip = Config::get('system', 'dlogip');
106 if (!is_null($dlogip) && $_SERVER['REMOTE_ADDR'] != $dlogip)
111 $processId = session_id();
113 if ($processId == '')
115 $processId = $a->process_id;
118 if (!is_string($msg)) {
119 $msg = var_export($msg, true);
122 $callers = debug_backtrace();
123 $logline = sprintf("%s@\t%s:\t%s:\t%s\t%s\t%s\n",
124 DateTimeFormat::utcNow(),
126 basename($callers[0]['file']),
128 $callers[1]['function'],
132 $stamp1 = microtime(true);
133 @file_put_contents($logfile, $logline, FILE_APPEND);
134 $a->saveTimestamp($stamp1, "file");