BlogNotesAbout
moon indicating dark mode
sun indicating light mode

How to Use VIM to Clean Multi-line Output From Papertrail

Papertrail inserts a timestamp and Heroku dyno information at the beginning of every log line. Each line in their logs has a maximum number of characters, so they break the log item at arbitrary locations.

That means a very long log item can look like this:

Apr 30 10:59:09 yourapp app/web.1 This repre
Apr 30 10:59:09 yourapp app/web.1 sents a very l
Apr 30 10:59:09 yourapp app/web.1 ong log item...

Paste all of these lines into VIM and run the following substitution command to clean it up:

%s/\r\?\n\?\(Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec\) \d\d\? \d\d:\d\d:\d\d \S\+ app\/[^.]\+.\d\+ /