Skip to content

Instantly share code, notes, and snippets.

@davorg
Created June 24, 2021 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davorg/73a922b218e0c4ac912d7661474af1df to your computer and use it in GitHub Desktop.
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
#!/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