Added sanity check if logging was enabled
No more wrapping calls to the Log class with a check if it's enabled.
This commit is contained in:
parent
391e95c9e8
commit
7746567ec3
1 changed files with 30 additions and 23 deletions
|
@ -116,36 +116,43 @@ class Log
|
|||
*/
|
||||
private static function write($log_type, $message, $format = true, $time = false)
|
||||
{
|
||||
$log_path = LOG_PATH . date('Y/m/d/', ($time == false ? time() : $time));
|
||||
$config = Config::getInstance();
|
||||
|
||||
try
|
||||
if ($config->pickles['logging'] === true)
|
||||
{
|
||||
if (!file_exists($log_path))
|
||||
$log_path = LOG_PATH . date('Y/m/d/', ($time == false ? time() : $time));
|
||||
|
||||
try
|
||||
{
|
||||
mkdir($log_path, 0755, true);
|
||||
if (!file_exists($log_path))
|
||||
{
|
||||
mkdir($log_path, 0755, true);
|
||||
}
|
||||
|
||||
$log_file = $log_path . $log_type . '.log';
|
||||
|
||||
$message .= "\n";
|
||||
|
||||
if ($format == true)
|
||||
{
|
||||
$backtrace = debug_backtrace();
|
||||
rsort($backtrace);
|
||||
$frame = $backtrace[strpos($backtrace[0]['file'], 'index.php') === false ? 0 : 1];
|
||||
|
||||
return file_put_contents($log_file, date('H:i:s') . ' ' . str_replace(getcwd(), '', $frame['file']) . ':' . $frame['line'] . ' ' . $message, FILE_APPEND);
|
||||
}
|
||||
else
|
||||
{
|
||||
return file_put_contents($log_file, $message, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
$log_file = $log_path . $log_type . '.log';
|
||||
|
||||
$message .= "\n";
|
||||
|
||||
if ($format == true)
|
||||
catch (ErrorException $exception)
|
||||
{
|
||||
$backtrace = debug_backtrace();
|
||||
rsort($backtrace);
|
||||
$frame = $backtrace[strpos($backtrace[0]['file'], 'index.php') === false ? 0 : 1];
|
||||
|
||||
return file_put_contents($log_file, date('H:i:s') . ' ' . str_replace(getcwd(), '', $frame['file']) . ':' . $frame['line'] . ' ' . $message, FILE_APPEND);
|
||||
}
|
||||
else
|
||||
{
|
||||
return file_put_contents($log_file, $message, FILE_APPEND);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (ErrorException $exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue