繁体   English   中英

如何获取错误和异常,并将其写入日志文件?

[英]How can I get errors and exceptions ,and write them to log files?

在我的PHP项目中,我想在产品Server中获得所有错误和异常。但是,如何获取它们并将其写入日志文件呢?

您可以在catch块中执行此操作:

try {
    foo();
} catch (Exception $e) {
    error_log("Caught $e");
}

或在异常处理程序中:

set_exception_handler(function($exception) {
    error_log($exception);
    error_page("Something went wrong!");
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM