系统日志自定义优先级
有没有一种方法可以在 syslog 守护程序或 rsyslog 守护程序中使用自定义优先级? 即我无法找到实现它的配置更改..我能做的另一件事也许是使用它的源代码。
干杯!
Is there a way one can use custom priorities in syslog daemon or rsyslog daemon?
i.e. i am unable to locate a configuration change which achives it.. the other thing i can do is perhaps play with it's source.
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
系统日志输出是管理员查看的内容。系统日志由用户空间守护进程管理。
这意味着什么,如果您设法将自己的自定义优先级塞入
syslog( )
调用,接收方,同样的用户,将无法从中获利。为 syslog() 调用记录的优先级(或级别)非常简单,涵盖了管理员必须对错误情况关注的所有级别。因为这就是级别的用途。
我建议提出另一个问题,详细说明您真正想要实现的目标。因为发明自定义优先级是朝着错误方向迈出的一步。
PS 否则,如果它是某种跟踪或调试或诊断输出,仅在开发/测试/安装期间使用,您始终可以在日志消息中使用标准级别之一和不同的前缀。这就是我在少数情况下所做的,以便能够从系统日志(使用 grep)中仅提取特定类型的诊断信息。
Syslog output is something admins look into. And the syslog is managed by the user-space daemon.
What that means, if you would manage somehow to cram your own custom priorities into the
syslog()
call, the receiving side, likewise the users, wouldn't be able to make much out of them.The priorities (or levels) as they are documented for the syslog() call are pretty straightforward, covering all levels of attentions admins has to pay to the error conditions. Because that is what the levels there are for.
I would recommend posing on the SO another question with details what you really want to achieve. Because inventing custom priorities is a step in wrong direction.
P.S. Otherwise, if it is some sort of tracing or debugging or diagnostic output, used only during development/testing/installation, you can always use one of the standard levels and distinct prefix in the log message. That's what I did on few occasions to be able to extract from the syslog (with grep) only the particular types of diagnostics.
调用
syslog(3)
的进程与syslogd
守护进程之间的常用接口仅允许使用int
优先级。这并没有为特定于应用程序的优先级留下太多空间。应用程序应使用LOG_USER
设施。应用程序可以使用 8 个设施LOG_LOCAL0
到LOG_LOCAL7
(经 POSIX 认可)。这些设施的分配传统上由系统管理员决定,因此您应该将设施设置为默认的配置设置LOG_USER
(这也将允许管理员选择非标准设施)。除了设施和优先级之外,一些 syslog 守护进程和大多数日志排序程序还允许按应用程序名称(
openlog
的第一个参数)进行排序。这个主题最好在 Unix Stack Exchange 站点 上讨论。The usual interface between the process that calls
syslog(3)
and thesyslogd
daemon only allows anint
for the priority. This doesn't leave much room for application-specific priorities. Applications are expected to use theLOG_USER
facility. There are 8 facilitiesLOG_LOCAL0
throughLOG_LOCAL7
(sanctioned by POSIX) that can be used by applications. The allocation of these facilities is traditionally up to the system administrator, so you should make the facility a configuration setting with a default ofLOG_USER
(this will also allow the administrator to select a nonstandard facility).Some syslog daemons, and most log sorting programs, allow sorting by application name (the first argument to
openlog
) in addition to facility and priority. This subject would be best discussed at the Unix Stack Exchange site.