Skip to content

Instantly share code, notes, and snippets.

@sideb0ard
Last active August 29, 2015 14:07
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 sideb0ard/055c5bea32f04105a0c1 to your computer and use it in GitHub Desktop.
Save sideb0ard/055c5bea32f04105a0c1 to your computer and use it in GitHub Desktop.
heroku2psql_format_logs.pl
#!/usr/bin/perl -w
use strict;
use Time::Piece;
die "Ooft, mate, i need an input file\n" unless (scalar @ARGV == 1);
my $date = localtime->strftime('%m-%d-%Y');
my $infile = $ARGV[0];
my $outfile = $infile . ".$date";
open(FILE, $infile) || die "Cannae open yer file, buddy\n";
open(OUTFILE, ">$outfile") || die "Cannae open OUTPUT file, buddy\n";
while (<FILE>) {
if ($_ =~ /^\d{4}-\d{2}-\d{2}.*/m) { # M for multiline so it matches multiline starting with a date
next if $_ =~ /\[GOLD\]/;# filter out unwanted app
$_ =~ s/\[OLIVE\]/LOG: /;# replace app name with standard postgres LOG: line
$_ =~ s/app\[postgres.\d+\]/[7777]: [1-1]/; # replace other app part with standard stderr placeholders (unused)
$_ =~ s/(\d{4})-(\d{2})-(\d{2})T(\d{2}:\d{2}:\d{2})Z/$1-$2-$3 $4 UTC/; # change date format
print "$_\n";
print OUTFILE "$_\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment