PHP 的 error_log() 与 syslog()
我正在尝试决定使用什么功能来记录自定义文件。
背景
我们有几个 PHP 进程,都作为 Apache (mod_php) 和 Deamons(CLI,分叉)运行。我希望能够为每个进程/任务指定一个要写入的日志文件。对于作为守护进程的 Apache 进程,多个进程将写入同一个文件。
选项
PHP 提供了 error_log()
和 syslog()
。两者似乎都提供或多或少相同的功能。
我的问题
- 这些功能的优点和缺点是什么?
- 选择哪一个? (为什么?)
- 如果我放弃多个文件的要求会怎样?
I'm trying to decide what functionality to use for logging to a custom file.
Background
We have several PHP processes, both running as Apaches (mod_php) and as Deamons (CLI, forked). I would like to be able to specify a log file per process/task to write to. For both the Apache processes as the Deamons, multiple processes will be writing to the same file.
Options
PHP offers both error_log()
and syslog()
. Both seem to offer more or less the same functionality.
My question
- What are the pros and cons of those functions?
- Which one to choose? (and why?)
- What if I drop the requirement of multiple files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
syslog
将消息发送到操作系统记录器,而error_log
有多个选项,可以发送到操作系统记录器、电子邮件、文件或 SAPI 日志记录处理程序,如文档中所述。既然您说要在多个日志上写入,我建议使用
error_log
和$message_type = 3
,这样您就可以将消息添加到中设置的文件中$destination
参数。syslog
sends the message to the OS logger, whileerror_log
has multiple options, either to the OS logger, to an email, to a file, or to the SAPI logging handler, as is stated in the documentation.Since you say yo want to write on multiple logs, I'd recommend
error_log
with$message_type = 3
, wich lets you add messages to the file set in the$destination
parameter.