Skip to content

Instantly share code, notes, and snippets.

@cursork
Created November 20, 2014 15:30
Show Gist options
  • Save cursork/a13d79e1e06ac77ee5d7 to your computer and use it in GitHub Desktop.
Save cursork/a13d79e1e06ac77ee5d7 to your computer and use it in GitHub Desktop.
use v5.014;
use warnings;
use List::MoreUtils qw/zip/;
use Term::ANSIColor qw/color/;
# Basic log colourisation for Clojure apps using the default Timbre config
# N.B. '\ ' is an escaped space, as /x modifier ignores whitespace in pattern
my $log_line_re = qr/^(\d{4}-[A-z]{3}-\d\d)\ # date
(\d\d:\d\d:\d\d)\ # time
([+-]\d{4})\ # offset
(\S+)\ # server
([A-Z]+)\ # level
(\[\S+\]) # namespace
\ -\
(.*).* # message
/x;
my %level_colours = (
WARN => color('red'),
ERROR => color('bold red'),
DEBUG => color('cyan'),
);
while (my $line = <STDIN>) {
chomp $line;
if (my @parts = $line =~ $log_line_re) {
my $level_colour = $level_colours{$parts[4]} // color('reset white');
say color('reset blue'), (map { $_ . ' ' } @parts[0..2]), # all date parts
# color('grey0'), $parts[3], ' ', ## Ignore server
$level_colour, sprintf('%5s', $parts[4]), ' ',
color('reset grey0'), $parts[5], ' - ',
$level_colour, $parts[6];
} else {
say $line;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment