Created
June 24, 2021 10:39
-
-
Save davorg/73a922b218e0c4ac912d7661474af1df to your computer and use it in GitHub Desktop.
Simple program to count the type of log events in a Log4Perl file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my $logs; | |
while (<>) { | |
my ($date, $time, $type) = split; | |
# Some event logs have newlines in them, so we try | |
# to skip lines that don't parse correctly | |
next unless defined $type and defined $time; | |
# Grab the time and cut into ten-minute chunks | |
$time = substr($time, 0, 4) . '0'; | |
# We'll still have some lines that don't look right | |
next unless $time =~ /^\d\d:\d\d$/; | |
$logs->{$time}{$type}++; | |
} | |
for my $min (sort keys %$logs) { | |
print $min; | |
for my $type (qw[INFO DEBUG WARN ERROR FATAL]) { | |
print " : $type [", ($logs->{$min}{$type} // 0), "]"; | |
} | |
print "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment