Changing date format in syslog


Is there anyway we can change the date format in a particular log file being logged to by syslog? I don’t want to change the way all logs are being logged, but just by log file.

EDIT: I’m using syslogd (in FreeBSD)

This is how my file looks like now:

Dec  5 07:52:10 Log data 1
Dec  5 07:52:10 Log data 2
Dec  5 07:52:10 Log data 3

This is how I want it to look like:

20131205 07:52:10 Log data 1
20131205 07:52:10 Log data 2
20131205 07:52:10 Log data 3

My syslog.conf looks like this, where /var/log/my_log.log is my logfile:

[email protected]
*.notice;local0.none;local1.none;local2.none;authpriv.none;kern.debug;mail.crit;news.err        /var/log/messages
security.*                                      /var/log/security;                         /var/log/auth.log                                       /var/log/maillog                                        /var/log/xferlog
cron.*                                          /var/log/cron
*.=debug                                        /var/log/debug.log                                    /var/log/console.log                                     /var/log/my_log.log


I ended up using an awk script to run through the log file and replace the date field

awk '{getDate="date -j -f \"%b %d %H:%M:%S\" \""$1" "$2" "$3"\" \"+%Y%m%d %H:%M:%S\""
      while ( ( getDate | getline date ) > 0 ) { }
      print date,$2,$3,$4,$5}' Temp1 > Temp2

Answered By – egorulz

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published