PHP 的 error_log() 与 syslog() [英] PHP's error_log() vs syslog()
问题描述
我正在尝试决定使用什么功能来记录到自定义文件.
I'm trying to decide what functionality to use for logging to a custom file.
背景
我们有几个 PHP 进程,都以 Apache(mod_php)和 Deamons(CLI,分叉)的形式运行.我希望能够为每个要写入的进程/任务指定一个日志文件.对于作为守护进程的 Apache 进程,多个进程将写入同一个文件.
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.
选项
PHP 提供 error_log()
和 syslog()
.两者似乎都提供或多或少相同的功能.
Options
PHP offers both error_log()
and syslog()
. Both seem to offer more or less the same functionality.
我的问题
- 这些功能的优缺点是什么?
- 选择哪一个?(为什么?)
- 如果我放弃多个文件的要求会怎样?
推荐答案
syslog
将消息发送到 OS 记录器,而 error_log
有多个选项,要么发送到 OS记录器、电子邮件、文件或 SAPI 日志记录处理程序,如文档中所述.
syslog
sends the message to the OS logger, while error_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.
既然你说你想写多个日志,我推荐 error_log
和 $message_type = 3
,它可以让你将消息添加到文件集$destination
参数.
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.
这篇关于PHP 的 error_log() 与 syslog()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!