Open crytjy opened 1 month ago
SeasLog SeasLog support => Enabled SeasLog Version => 2.2.0 SeasLog Author => Chitao.Gao [ neeke@php.net ] SeasLog Supports => https://github.com/SeasX/SeasLog Directive => Local Value => Master Value seaslog.default_basepath => /www/logs => /www/logs seaslog.default_logger => default => default seaslog.default_datetime_format => Y-m-d H:i:s => Y-m-d H:i:s seaslog.default_template => %T | %L | %Q | %M => %T | %L | %Q | %M seaslog.disting_folder => On => On seaslog.disting_type => Off => Off seaslog.disting_by_hour => Off => Off seaslog.use_buffer => Off => Off seaslog.buffer_size => 500 => 500 seaslog.buffer_disabled_in_cli => Off => Off seaslog.trace_notice => Off => Off seaslog.trace_warning => Off => Off seaslog.trace_error => On => On seaslog.trace_exception => On => On seaslog.level => 8 => 8 seaslog.recall_depth => 0 => 0 seaslog.appender => 1 => 1 seaslog.appender_retry => 0 => 0 seaslog.remote_host => no value => no value seaslog.remote_port => 0 => 0 seaslog.remote_timeout => 1 => 1 seaslog.trim_wrap => Off => Off seaslog.throw_exception => On => On seaslog.ignore_warning => On => On seaslog.trace_performance => Off => Off seaslog.trace_performance_sample_rate => 0 => 0 seaslog.trace_performance_start_depth => 0 => 0 seaslog.trace_performance_max_depth => 0 => 0 seaslog.trace_performance_max_functions_per_depth => 0 => 0 seaslog.trace_performance_min_wall_time => 1000 => 1000 seaslog.trace_performance_min_function_wall_time => 10 => 10
// 初始化 $config = config('seaslog'); \SeasLog::setBasePath($config['logPath']); $this->modules = $config['module'] ?? []; foreach ($this->modules as $modules) { \SeasLog::setLogger($modules); } public function log($module, $level, $message, array $context = []): void { $msg = $message . ':' . json_encode($context); \SeasLog::{$level}($msg, [], $module); } $this->log('test', 'debug', 'testMsg');
//定时删除日志的逻辑 \SeasLog::closeLoggerStream(SEASLOG_CLOSE_LOGGER_STREAM_MOD_ASSIGN, $module); $this->rotate($module); //删除文件的逻辑 \SeasLog::closeLoggerStream(SEASLOG_CLOSE_LOGGER_STREAM_MOD_ASSIGN, $module);
不对, 是时间问题, 今天的日志会被写入昨天的日志文件里. 比如今天26号, 会有部分数据被写入25号的日志文件里面
配置
在hyperf框架中使用seasLog, 使用定时器定期删除日志, 文件删除了, 但hyperf进程还是占用着这个文件, 必须重启hyperf才能释放.
使用了SeasLog::closeLoggerStream(SEASLOG_CLOSE_LOGGER_STREAM_MOD_ASSIGN, 'logger_name'); 还是会被占用.
hyperf 代码实现