Parsing Ahsay OBS logfile timestamps

All Ahsay OBS generated logfile timestamps use milliseconds since Unix epoch on January 1, 1970, 00:00:00 GMT, it’s great for scripting and programming as it’s easy to do date math, but if you want to output a humanly readable date you need to convert it.

The below perl script will work for all Ahsay OBS logfiles, pretty much.

#!/usr/bin/perl
#
# Usage:
#  cat /usr/local/obs/system/SystemLog/2009-10-19.log | perl obslog.pl
#
# Converts Java timestamp to humanly readable
#

use Time::localtime;

@wday=('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
@month=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

sub epochToDate {
   my ($epoch) = @_;

   $tm = localtime($epoch/1000);
   return(sprintf("[%02d/%s/%4d %02d:%02d:%02d]", $tm->mday, $month[$tm->mon], $tm->year+1900,
                                                  $tm->hour, $tm->min, $tm->sec));
}

while(<STDIN>)
{
    ($date, $rest) = /^(\d+)\,(.*)/;
    printf("%s%s\n", epochToDate($date), $rest);
}

Not exactly rocket science but hopefully someone will find it useful and it should work on Windows, Linux, Solaris and pretty much any system Ahsay OBS will run on.

This entry was posted in Ahsay and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>