Re: Log Files

From: Andreas Vierengel <avierengel@dont-contact.us>
Date: Thu, 10 Dec 1998 13:16:36 +0100

-----Ursprüngliche Nachricht-----
Von: Bester Leon <BesterL@ael.co.za>
An: squid-users@ircache.net <squid-users@ircache.net>
Datum: Donnerstag, 10. Dezember 1998 13:02
Betreff: Log Files

>What formula is used to change the Unix Number representing the date and
>time to the normal time/date format

It represents the number of seconds elapsed since 00:00:00 on January 1,
1970, Coordinated Universal Time (UTC)

try man time or ctime in C.

In Perl use localtime (builtin).

following is a quick hack (please, no comments on the coding style :-)

#!/usr/bin/perl
#
# showlog.pl: Display the squid access.log in a human readable format
#
# syntax: showlog.pl < access.log
#
############################################################################
##########

if ($#ARGV != -1)
{
  print <<USAGE;
Usage: showlog.pl < access.log
       No parameters allowed

USAGE
}
else
{
  while ($line = <>)
  {
    if ( $line =~ /^(\d+)\.\d*\s+(.*?)$/ )
    {
      ($second, $minute, $hour, $tag, $monat, $jahr, undef, undef, undef) =
localtime($1);
      $tag = sprintf("%02d", $tag);
      $monat++;
      $monat = sprintf("%02d", $monat);
      $jahr += 1900;
      $second = sprintf("%02d", $second);
      $minute = sprintf("%02d", $minute);
      $hour = sprintf("%02d", $hour);
      print $jahr."/".$monat."/".$tag." ".$hour.":".$minute.":".$second."
".$2."\n";
    }
    else
    {
      print $line;
    }
  }
}
Received on Thu Dec 10 1998 - 05:41:40 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:43:36 MST