PHP 日志 : Warning format

标签 php date warnings logging

PHP 日志格式不包括警告的日期。例如

PHP Warning:  Cannot modify header information...

没有任何警告发生的日期。

有没有办法更改警告格式,或者至少在日志中包含日期? (如果重要,使用php-fpm)。

最佳答案

当然,您始终可以使用 set_error_handler 定义自己的错误处理程序.简化示例:

function handler($errno, $errstr, $errfile, $errline, $errcontext) {
    $message = date('Y-m-d H:i:s') . ": $errstr in $errfile at $errline\n";
    file_put_contents('error.log', $message, FILE_APPEND);
}

set_error_handler('handler');

关于PHP 日志 : Warning format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6259857/

相关文章:

javascript - 如何访问在 php 标签内创建的文本框值以进行 ajax 调用

php - date_create_from_format 接受无效日期作为输入

ios - 隐式转换失去整数精度Xcode 5.1

c - 我如何在不使用 stdlib.h 的情况下执行此代码

php - PDO 如何知道 MySQL 中最后插入的 id?

php - 如何使用 Amazon PHP SDK 2 获取 EC2 实例列表?

php - pngquant PHP 示例不工作

php - MySQL 条目按日期排序,顺序错误

ajax - 通过 ajax 的 grails datepicker 值

compiler-errors - 异常使用rust : how can I disable all the warnings and checks possible?