记录日志
boolean Core_Core::log( string $msg [, string $type = string(3) "log" , stirng $file = null ] )
参数列表
参数 类型 描述 默认值 $msg
string
日志内容 $type
string
类型,例如:log,error,debug 等 string(3) "log" $file
stirng
指定文件名,不指定则默认 null
boolean
public static function log($msg, $type = 'log', $file = null)
{
if (Core::is_file_write_disabled())return true;
# log配置
$log_config = Core::config('log');
# 不记录日志
if (isset($log_config['use']) && !$log_config['use'])
{
return true;
}
# 内容格式化
if ($log_config['format'])
{
$format = $log_config['format'];
}
else
{
# 默认格式
$format = ':time - :host::port - :url - :msg';
}
# 获取日志内容
$data = Core::log_format($msg, $type, $format);
if (IS_DEBUG)
{
# 如果有开启debug模式,输出到浏览器
Core::debug()->log($data, $type);
}
# 保存日志
return Core::write_log($data, $type, $file);
}