centos

centos中thinkphp日志如何管理

小樊
40
2025-11-15 20:08:49
栏目: 编程语言

CentOS 下 ThinkPHP 日志管理

一 日志位置与保留策略

return [
    'default' => env('log.channel', 'stack'),
    'channels' => [
        'stack' => [
            'type'   => 'stack',
            'channels' => ['daily', 'error_file', 'emergency'],
        ],
        'daily' => [
            'type'       => 'file',
            'path'       => runtime_path('logs/daily'),
            'level'      => ['info','notice','warning'],
            'max_files'  => 30,         // 保留30天
            'file_size'  => 10485760,    // 10MB分割
            'json'       => false,
        ],
        'error_file' => [
            'type'       => 'file',
            'path'       => runtime_path('logs/error'),
            'level'      => ['error','critical'],
            'max_files'  => 90,         // 保留90天
            'apart_level'=> true,        // 每个级别单独文件
            'file_size'  => 20971520,    // 20MB分割
            'json'       => true,         // 便于检索分析
        ],
        'emergency' => [
            'type'       => 'file',
            'path'       => runtime_path('logs/emergency'),
            'level'      => ['emergency'],
            'max_files'  => 365,        // 保留1年
        ],
    ],
];

二 清理与归档方案

三 集中化采集与分析(ELK 或兼容栈)

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/www/*/runtime/logs/*.log
  multiline.pattern: '^-'
  multiline.negate: true
  multiline.match: after
  encoding: utf-8
output.logstash:
  hosts: ["logstash:5044"]

四 权限与运行维护要点

0
看了该问题的人还看了