在系统日志消息中添加年份 (linux)
我需要在 syslog 守护进程生成的日志消息中记录年份。特别是在 /var/log/secure 文件中。是否可以?
这是正常系统日志消息的示例:
Feb 16 04:06:58 HOST sshd[28573]: Accepted password for USER from SOURCE port 7269 ssh2
我需要类似的内容:
Feb 16 2011 04:06:58 HOST sshd[28573]: Accepted password for USER from SOURCE port 7269 ssh2
提前致谢。
I need to log the year in the log message generated by syslog daemon. In particular in the /var/log/secure file. Is it possible?
Here an example of normal syslog message:
Feb 16 04:06:58 HOST sshd[28573]: Accepted password for USER from SOURCE port 7269 ssh2
And I need something similar to:
Feb 16 2011 04:06:58 HOST sshd[28573]: Accepted password for USER from SOURCE port 7269 ssh2
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果你使用 rsyslog,这很容易。参考如下:
修改/etc/rsyslog.conf如下:
<前><代码>...
authpriv.* /var/log/secure;RSYSLOG_FileFormat
...
然后要求 rsyslog 守护进程重新加载配置:
更多参考:
If you use rsyslog, it is easy. Refer to following:
Modify /etc/rsyslog.conf to following:
And then asking rsyslog daemon to reload configuration:
More reference :
syslog-ng 具有 ts_format() 选项来指定文件的默认时间戳格式。默认设置为 iso 格式,其中包含年份。
您还可以使用 template() 选项配置文件格式。
syslog-ng has the ts_format() option to specify the default timestamp format for files. it is set to iso format by default, which includes the year.
you can also configure file formats using the template() option.
如果您的系统日志遵循 RFC 3164(BSD 系统日志协议),则您无法将其配置为记录年份。除非您有一个遵循 RFC 5424(rsyslog 或 syslog-ng)的现代 syslog 守护程序,否则您无法执行此操作。
If your syslog respects RFC 3164 (The BSD Syslog Protocol), then you cannot configure it to record the year. Unless you have a modern syslog daemon that follows RFC 5424 (rsyslog or syslog-ng) you cannot do that.
如果您无法更改系统本身的系统日志,也许您可以设置系统日志以将其发送到具有更好的系统日志守护程序的远程系统?
If you can't alter the syslog on the system itself, maybe you could setup syslog to send it to a remote system with a better syslog daemon?