Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

日志删除了, 但还是被进程占用着 #325

Open
crytjy opened this issue Oct 24, 2024 · 1 comment
Open

日志删除了, 但还是被进程占用着 #325

crytjy opened this issue Oct 24, 2024 · 1 comment

Comments

@crytjy
Copy link

crytjy commented Oct 24, 2024

配置

SeasLog

SeasLog support => Enabled
SeasLog Version => 2.2.0
SeasLog Author => Chitao.Gao  [ [email protected] ]
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

在hyperf框架中使用seasLog, 使用定时器定期删除日志, 文件删除了, 但hyperf进程还是占用着这个文件, 必须重启hyperf才能释放.

使用了SeasLog::closeLoggerStream(SEASLOG_CLOSE_LOGGER_STREAM_MOD_ASSIGN, 'logger_name'); 还是会被占用.

hyperf 代码实现

// 初始化
$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);

image

@crytjy
Copy link
Author

crytjy commented Oct 26, 2024

不对, 是时间问题, 今天的日志会被写入昨天的日志文件里. 比如今天26号, 会有部分数据被写入25号的日志文件里面

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant