Changing date format in syslog

date, freebsd, linux, syslog

Solution

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 ) { }
      close(getDate);
      print date,$2,$3,$4,$5}' Temp1 > Temp2

Problem

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: ``` +@ *.notice;local0.none;local1.none;local2.none;authpriv.none;kern.debug;mail.crit;news.err /var/log/messages security.* /var/log/security auth.info;authpriv.info /var/log/auth.log mail.info /var/log/maillog ftp.info /var/log/xferlog cron.* /var/log/cron *.=debug /var/log/debug.log console.info /var/log/console.log local1.info /var/log/my_log.log ```

Original source