CRMEB开发:错误调试开启记录sql日志

252 阅读1分钟

第一步:在config/app.php文件中开启 数据库日志记录。

return [
    // 应用地址
    'app_host'         => Env::get('app.host', ''),
    // 应用的命名空间
    'app_namespace'    => '',
    // 是否启用路由
    'with_route'       => true,
    // 是否启用事件
    'with_event'       => true,
    // 应用映射(自动多应用模式有效)
    'app_map'          => [],
    // 域名绑定(自动多应用模式有效)
    'domain_bind'      => [],
    // 禁止URL访问的应用列表(自动多应用模式有效)
    'deny_app_list'    => [],
    // 默认应用
    'default_app'      => '',

    'app_express'      => true,
    // 默认时区
    'default_timezone' => 'Asia/Shanghai',
    // 异常页面的模板文件
    'exception_tmpl'   => app()->getRootPath() . 'public/statics/exception.tpl',
    // 错误显示信息,非调试模式有效
    'error_message'    => '页面错误!请稍后再试~',
    // 显示错误信息
    'show_error_msg'   => true,
    //开启数据库调试,数据库执行语句写入日志
    'trigger_sql' => true,
    // 授权密钥
    'auth_crmeb'       => BaseAuth::AUTH_CRMEB
];

第二步:在config\log.php中日志级别加入sql

return [
    // 默认日志记录通道
    'default'      => Env::get('log.channel', 'file'),
    // 日志记录级别
    'level'        => ['error', 'warning', 'info', 'fail', 'success','sql'],
    // 日志类型记录的通道 ['error'=>'email',...]
    'type_channel' => [],
    // 是否关闭日志写入
    'close'        => false,
    //是否开启业务成功日志
   'success_log'  => false,
    //是否开启业务失败日志
    'fail_log'     => false,
    // 日志通道列表
    'channels'     => [
        'file' => [
            // 日志记录方式
            'type'        => 'File',
            // 日志保存目录
            'path'        => app()->getRuntimePath() . 'log' . DIRECTORY_SEPARATOR,
            // 单文件日志写入
            'single'      => false,
            // 独立日志级别
            'apart_level' => ['error','info','warning','sql', 'fail', 'success','sql'],
            // 最大日志文件数量
            'max_files'   => 1000,
        ],
        // 其它日志通道配置
    ],
];

第三步:配置好后,重新启动swoole,即可看到sql执行语句记录日志