How to: View Human-Readable Timestamps in qmail Logs

InterWorx uses qmail to provide SMTP services. qmail provides logging in /var/log/send and /var/log/smtp for system administrators who would like to see information regarding the sending and receiving of email. qmail uses TAI64N timestamps on each line of its logs. They appear like so:

@40000000600db35c0c07e714

The tai64nlocal command can be used to convert TAI64N timestamps to a human-readable format. More information can be found here: http://cr.yp.to/daemontools/tai64nlocal.html.

This tool is installed by default alongside InterWorx.

To Convert TAI64N Timestamps

This command works by reading lines straight from stdin. In order to use it, it necessary to pipe the lines to convert into tai64nlocal. A simple example is:

[root@iw7 smtp]# echo @40000000600db35c0c07e714 | tai64nlocal
2021-01-24 12:50:10.201844500

It may necessary, in the course of system administration, to see these human-readable timestamps in /var/log/smtp/current. Normally, this log will appear like so:

[root@server ~]# cat /var/log/smtp/current
@40000000600dab2f0f7636bc tcpserver: status: 0/20
@40000000600db35c0bcdc05c tcpserver: status: 1/20
@40000000600db35c0c07e714 tcpserver: pid 7189 from 127.0.0.1
@40000000600db35c0c07eee4 tcpserver: ok 7189 iw7.com:::ffff:127.0.0.1:25 :::ffff:127.0.0.1::47407
@40000000600db35c1291f994 tcpserver: end 7189 status 256
@40000000600db35c12920164 tcpserver: status: 0/20
@40000000600db55b2aedd094 tcpserver: status: 1/20
@40000000600db55b2b1814e4 tcpserver: pid 10593 from 127.0.0.1
@40000000600db55b2b1818cc tcpserver: ok 10593 iw7.com:::ffff:127.0.0.1:25 :::ffff:127.0.0.1::47699
@40000000600db55b2ec2544c tcpserver: end 10593 status 256

Piping this output into tai64nlocal allows for the human-readable timestamps to replace the TAI64N timestamps:

[root@server ~]# cat /var/log/smtp/current | tai64nlocal
2021-01-24 12:15:17.259405500 tcpserver: status: 0/20
2021-01-24 12:50:10.198033500 tcpserver: status: 1/20
2021-01-24 12:50:10.201844500 tcpserver: pid 7189 from 127.0.0.1
2021-01-24 12:50:10.201846500 tcpserver: ok 7189 iw7.com:::ffff:127.0.0.1:25 :::ffff:127.0.0.1::47407
2021-01-24 12:50:10.311556500 tcpserver: end 7189 status 256
2021-01-24 12:50:10.311558500 tcpserver: status: 0/20
2021-01-24 12:58:41.720228500 tcpserver: status: 1/20
2021-01-24 12:58:41.722998500 tcpserver: pid 10593 from 127.0.0.1
2021-01-24 12:58:41.722999500 tcpserver: ok 10593 iw7.com:::ffff:127.0.0.1:25 :::ffff:127.0.0.1::47699
2021-01-24 12:58:41.784487500 tcpserver: end 10593 status 256

Using tai64nlocal With Other Commands

tai64nlocal can be combined with other commands for greater flexibility.

  • To convert timestamps before opening a file in vim:

    vim /var/log/send/current | tai64nlocal
    
  • To grep for a specific pattern in a file and return the output with converted timestamps:

    grep [pattern] [file] | tai64nlocal