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);
}
#
# 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.