Rails logging makes easy with itslog + axe

Should errors occurred and to be isolated, Rails developer tend to spend hours digest the Rails log files to work out the issues. However this task could become a real nightmare because filtering through megabytes of text to search for specific thing you suspect that go wrong might be very tedious and strenuous. (I know it ’cause I’ve been through cases where log file get up to 60MByes). IMHO, life is too short to be small [1] ineffective, so I google-ed around and found this nice piece of gem ‘itslog‘ that could ‘nail the ass’.

itslog is a log formatter designed to aid rails development/debugging. The formatting will prepend all log statements with a colored header and additional information about the statement.

[timestamp] [rails namespace]: [normal log]

Example, default Rails log:

Taxon Load (4.1ms)  SELECT "taxons".* FROM "taxons" WHERE "taxons"."parent_id" IS NULL ORDER BY "lft"

turns to

19:17:29 active_record: Taxon Load (4.1ms)  SELECT "taxons".* FROM "taxons" WHERE "taxons"."parent_id" IS NULL ORDER BY "lft"

The log is now more readable and with the help of ‘cat’ you could extract specific info, for example:

cat log/development.log | grep 'active_record'

Furthermore, you can use ‘tail’ to track specific details from log file:

tail -f  log/development.log | grep 'active_record'

Yet even easier, the same author wrote ‘axe‘ which is a wrapper of ‘tail’ to help you generate ‘tail -f’ easily.

For example:

$ axe
> tail -f log/development.log

$ axe active_record
> tail -f log/development.log | grep active_record

$ axe active_record action_view INSERT
> tail -f log/development.log | grep "active_record\|action_view\|INSERT"

$ axe -e test
> tail -f log/test.log

$ axe -e test active_record action_view INSERT
> tail -f log/test.log | grep "active_record\|action_view\|INSERT"

$ axe -n 50
> tail -n 50 log/development.log

$ axe -n 50 INSERT
> tail -n 50 log/development.log | grep INSERT

I hope you find ‘itslog’ useful and if you like this post, please subscribe to my blog, I love you 🙂

[1] <humor>oops, I get mixed up with the protein drink advertising</humor>

Advertisements

About Jones Lee

Nothing much about me..

One response to “Rails logging makes easy with itslog + axe

  1. Hello to every body, it’s my first go to see of this blog; this webpage consists of remarkable and genuinely fine data in support of visitors.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: