Browse Source

Changed time to a readable stamp similar to timestamp.pl

Alois Mahdal 12 years ago
parent
commit
854d91e9d0
1 changed files with 12 additions and 2 deletions
  1. 12
    2
      cgi-bin/htlog/htlog.cgi

+ 12
- 2
cgi-bin/htlog/htlog.cgi View File

@@ -21,12 +21,22 @@ use CGI;
21 21
 my $LOG_FILE = 'htlog.log';
22 22
 open my $fh, ">>", $LOG_FILE or die "cannot open log file for appending: $!";
23 23
 
24
+sub stamp {
25
+    my $unixtime = ($_[0] ? $_[0] : time );
26
+    my ($sec, $min, $hour, $mday, $mon, $year) = localtime $unixtime;
27
+    return sprintf (
28
+        "%04i-%02i-%02i %02i:%02i:%02i", 
29
+        $year + 1900,   $mon + 1,   $mday,  
30
+        $hour,          $min,       $sec
31
+    );
32
+}
33
+
24 34
 my $q = CGI->new;
25 35
 my $msg = ( defined $q->param('msg')    ? $q->param('msg')  : '' );
26 36
 my $tag = ( defined $q->param('tag')    ? $q->param('tag')  : '-none-' );
27 37
 
28
-my $message = sprintf("Time: %s, Origin: %s, Tag: %s, Message: %s\n",
29
-    time,
38
+my $message = sprintf("Time: %s; Origin: %s; Tag: %s; Message: %s\n",
39
+    &stamp(time),
30 40
     $ENV{'REMOTE_ADDR'},
31 41
     $tag,
32 42
     $msg