导航首页 » 技术教程 » PHP异常处理:error_log()函数的用法
PHP异常处理:error_log()函数的用法 145 2023-12-14   

error_log

(PHP 4, PHP 5)

error_log — 发送错误信息到某个地方

说明

bool error_log ( string $message [, int $message_type = 0 [, string $destination [, string $extra_headers ]]] )

把错误信息发送到 web 服务器的错误日志,或者到一个文件里。

参数

message

应该被记录的错误信息。

message_type

设置错误应该发送到何处。可能的信息类型有以下几个:

error_log() 日志类型 0 message 发送到 PHP 的系统日志,使用 操作系统的日志机制或者一个文件,取决于 error_log 指令设置了什么。 这是个默认的选项。 1 message 发送到参数 destination 设置的邮件地址。 第四个参数 extra_headers 只有在这个类型里才会被用到。 2 不再是一个选项。 3 message 被发送到位置为 destination 的文件里。 字符 message 不会默认被当做新的一行。 4 message 直接发送到 SAPI 的日志处理程序中。

destination

目标。它的含义描述于以上,由 message_type 参数所决定。

extra_headers

额外的头。当 message_type 设置为 1 的时候使用。 该信息类型使用了 mail() 的同一个内置函数。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

更新日志

版本 说明 5.2.7 可能的值:4添加到了 message_type

范例

Example #1 error_log() 范例

<?php
// 如果无法连接到数据库,发送通知到服务器日志
if (!Ora_Logon($username, $password)) {
    error_log("Oracle database not available!", 0);
}

// 如果用尽了 FOO,通过邮件通知管理员
if (!($foo = allocate_new_foo())) {
    error_log("Big trouble, we're all out of FOOs!", 1,
               "operator@example.com");
}

// 调用 error_log() 的另一种方式:
error_log("You messed up!", 3, "/var/tmp/my-errors.log");
?>


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103