/** * @brief Logging function for Hubzilla. * * Logging output is configured through Hubzilla's system config. The log file * is set in system logfile, log level in system loglevel and to enable logging * set system debugging. * * Available constants for log level are LOGGER_NORMAL, LOGGER_TRACE, LOGGER_DEBUG, * LOGGER_DATA and LOGGER_ALL. * * Since PHP5.4 we get the file, function and line automatically where the logger * was called, so no need to add it to the message anymore. * * @param string $msg Message to log * @param int $level A log level. * @param int $priority - compatible with syslog */ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { if (App::$module == 'setup' && is_writable('install.log')) { $debugging = true; $logfile = 'install.log'; $loglevel = LOGGER_ALL; } else { $debugging = get_config('system', 'debugging'); $loglevel = intval(get_config('system', 'loglevel')); $logfile = get_config('system', 'logfile'); } if (!$debugging || !$logfile || $level > $loglevel) { return; } $where = ''; // We require > 5.4 but leave the version check so that install issues (including version) can be logged if (version_compare(PHP_VERSION, '5.4.0') >= 0) { $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': '; } $s = datetime_convert() . ':' . log_priority_str($priority) . ':' . session_id() . ':' . $where . $msg . PHP_EOL; $pluginfo = array('filename' => $logfile, 'loglevel' => $level, 'message' => $s, 'priority' => $priority, 'logged' => false); if (!(App::$module == 'setup')) { call_hooks('logger', $pluginfo); } if (!$pluginfo['logged']) { @file_put_contents($pluginfo['filename'], $pluginfo['message'], FILE_APPEND); } }
/** * @brief Logging function for Hubzilla. * * Logging output is configured through Hubzilla's system config. The log file * is set in system logfile, log level in system loglevel and to enable logging * set system debugging. * * Available constants for log level are LOGGER_NORMAL, LOGGER_TRACE, LOGGER_DEBUG, * LOGGER_DATA and LOGGER_ALL. * * Since PHP5.4 we get the file, function and line automatically where the logger * was called, so no need to add it to the message anymore. * * @param string $msg Message to log * @param int $level A log level. * @param int $priority - compatible with syslog */ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) { // turn off logger in install mode global $a; global $db; if ($a->module == 'install' || !($db && $db->connected)) { return; } $debugging = get_config('system', 'debugging'); $loglevel = intval(get_config('system', 'loglevel')); $logfile = get_config('system', 'logfile'); if (!$debugging || !$logfile || $level > $loglevel) { return; } $where = ''; if (version_compare(PHP_VERSION, '5.4.0') >= 0) { $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); $where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': '; } $s = datetime_convert() . ':' . log_priority_str($priority) . ':' . session_id() . ':' . $where . $msg . PHP_EOL; $pluginfo = array('filename' => $logfile, 'loglevel' => $level, 'message' => $s, 'priority' => $priority, 'logged' => false); call_hooks('logger', $pluginfo); if (!$pluginfo['logged']) { @file_put_contents($pluginfo['filename'], $pluginfo['message'], FILE_APPEND); } }