centos

centos服务器上thinkphp日志管理

小樊
33
2025-11-25 19:09:03
栏目: 云计算

CentOS 服务器上 ThinkPHP 日志管理

一 基础配置与存放路径

return [
    'default' => 'file',
    'channels' => [
        'file' => [
            'type'      => 'file',
            'path'      => '',            // 默认 runtime/log
            'level'     => ['error','info'], // 只记录 error、info
            'max_files' => 30,           // 最多保留 30 个文件
            'json'      => false,
        ],
    ],
];
use think\facade\Log;
Log::info('用户登录', ['user_id' => 1]);
Log::error('支付失败', ['order_id' => 1001, 'reason' => '余额不足']);

二 写入策略与保留策略

# 每天 01:00 归档
0 1 * * * cd /path/to/project && php think log:archive

三 服务器侧日志轮转与清理

/path/to/project/runtime/log/*.log {
    daily
    rotate 30
    compress
    delaycompress
    missingok
    notifempty
    create 0755 www-data www-data
    copytruncate
}

说明:

四 常见问题与排查

0
看了该问题的人还看了