error_log() - php 错误处理日志函数
error_log()
(PHP 4, PHP 5, PHP 7)
发送错误信息到某个地方
说明
error_log(string $message[,int $message_type= 0[,string $destination[,string $extra_headers]]]): bool把错误信息发送到 web 服务器的错误日志,或者到一个文件里。
参数
$message应该被记录的错误信息。
$message_type设置错误应该发送到何处。可能的信息类型有以下几个:
0 | $message发送到 PHP 的系统日志,使用操作系统的日志机制或者一个文件,取决于error_log指令设置了什么。这是个默认的选项。 |
1 | $message发送到参数$destination设置的邮件地址。第四个参数$extra_headers只有在这个类型里才会被用到。 |
2 | 不再是一个选项。 |
3 | $message被发送到位置为$destination的文件里。字符$message不会默认被当做新的一行。 |
4 | $message直接发送到 SAPI 的日志处理程序中。 |
目标。它的含义描述于以上,由$message_type参数所决定。
$extra_headers额外的头。当$message_type设置为1的时候使用。该信息类型使用了mail()的同一个内置函数。
返回值
成功时返回TRUE
,或者在失败时返回FALSE
。
注释
Warningerror_log()并非二进制安全的。null 字符可能截断$message。
Tip$message不能包含 null 字符。注意,$message可能会发送到文件、邮件、syslog 等。所以在调用error_log()前需要使用适合的转换/转义函数:base64_encode()、rawurlencode()或addslashes()。
范例
Example #1error_log()范例
---------------%
If you have a problem with log file permission *silently* it's best to leave error_log directive unset so errors will be written in your Apache log file for current VirtualHost.
After scouring the internet for getting event logging to work in syslog on Windows 2003, I found the following from this post and was able to successfully get Windows Event Viewer to log PHP errors/notices: http://forums.iis.net/p/1159662/1912015.aspx#1913338 1. Copy the PHP 5 binaries to "C:\php". 2. Right-click My Computer and select Properties to bring up the Computer Properties dialog. Switch to the Advanced tab and click Environment Variables. Find the system environment variable PATH, edit it and add ";C:\php" (without the quotes) to the end. 3. Make sure that the configuration file "php.ini" resides in the directory "C:\php" and contains the correct path settings. 4. DELETE any old "php.ini" files from "C:\WINDOWS" and other directories. 5. Open REGEDIT, navigate to the key "HKLM\SOFTWARE\PHP" and DELETE the string value "IniFilePath" from there. It is outdated and no longer necessary! 6. Modify NTFS security permissions of the directory "C:\php" to give Read and Execute permissions to (1) the IIS Guest Account and (2) the group IIS_WPG. 7. Modify NTFS security permissions of the directories "C:\php\session" and "C:\php\upload" to give additional Modify permissions to (1) the IIS Guest Account and (2) the group IIS_WPG. 8. Navigate to the registry key "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog \Application" and edit the value "CustomSD" there. Find the substring "(D;;0xf0007;;;BG)" which Denies access to the application event log for Builtin Guest accounts (like the IIS Web User account) and replace this substring with "(A;;0x3;;;BG)" which allows read and write access. Please pay attention to leave the rest of the security string intact. Damaging this value can have dangerous effects! 9. Create or update the registry key "HKLM\SYSTEM\CurrentControlSet\Services\Eventlog\Application\ PHP-5.2.0" (adapt the last to your version part if necessary) with the following values: * "EventMessageFile" (REG_EXPAND_SZ) = "C:\php\php5ts.dll" * "TypesSupported" (REG_DWORD) = 7
It appears that error_log() only logs the first line of multi-line log messages. To log a multi-line message, either log each line individually or write the message to another file.
When error_log() unexpectedly uses stdout, you should check if the php.ini value for error_log is empty in your CLI environment. Something as simple as this might restore expected behavior:
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)