问题原文
原帖链接 · Diogo Braga · CC BY-SA 4.0
The format of the dates of my maillog logs looks like this:
May 12 04:12:54
I need to include the year on this date. Is it possible to make this kind of change?
社区高分解答
原帖链接 · Diogo Braga · CC BY-SA 4.0
After a little more research and some tests, I found the solution I need. My server works with CentOS 7.6, which use rsyslog to log.
- Edit the file /etc/rsyslog.conf and add the following template before the section "RULES":
$template MailLogFormat, "%timestamp:::date-year%-%timestamp:::date-month%-%timestamp:::date-day% %timestamp:::date-hour%:%timestamp:::date-minute%:%timestamp:::date-second% %hostname% %syslogtag%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
- Search for the line:
# Log all the mail messages in one place.
mail.* -/var/log/maillog
and change to:
# Log all the mail messages in one place.
mail.* -/var/log/maillog;MailLogFormat
- Restart rsyslog:
systemctl restart rsyslog
Done. The logs in the /var/log/maillog file will be printed with the date in the format: Year-Month-Day Hour:Minute:Second
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
