My apologies in advance if this question has already been answered. I have been attempting to search for this on Google and StackOverflow both, but since my search query has punctuation in it, search engines tend to munge it and give me nonsense results.
In my rails application (rails 3.2.11, ruby 1.9.3), my logs frequently look like this:
Started GET "/apply/contact" for 127.0.0.1 at 2013-01-29 17:35:21 -0600
Processing by JobApplicationsController#show as HTML
Parameters: {"id"=>"contact"}
[1m[36mJobApplication Load (0.5ms)[0m [1mSELECT "job_applications".* FROM "job_applications" WHERE "job_applications"."id" = 9 LIMIT 1[0m
[1m[35mPerson Load (0.4ms)[0m SELECT "people".* FROM "people" WHERE "people"."id" = 42 LIMIT 1
Rendered job_applications/contact.html.haml within layouts/bare (9.6ms)
Rendered shared/_messages.html.haml (0.1ms)
Completed 200 OK in 88ms (Views: 24.8ms | ActiveRecord: 0.9ms | Solr: 0.0ms)
What I am wondering is in regards to the [1m[36m
and [1m[35m
tokens, which appear before some of the lines, and also the [0m
and [1m
that sometimes appear within the line.
The only numbers that ever show up are 0, 1, 32, 35, and 36. These tokens are always preceded in the log file by an unprintable escape character.
What are these numbers indicating? Why are they showing up in my logs? And is there a way to get rid of them? They (and their escape-character friends) are exceedingly annoying when attempting to read through the logs and diagnose an issue.
Apply the formula for volume of a cylinder, V = π × r2 × h, where V is the log's volume, r is the radius of the log and h is its height (or if you prefer, its length; the straight-line distance from one end of the log to the other).
If you want to make use of those ANSI shell color codes instead of suppressing them, view your log in a pager (like less
) instead of an editor (like vim
).
less -r log/production.log
(Make sure you use the -r
flag to make use of the control codes.)
Those are ANSI shell color codes. You can suppress them using config.colorize_logging or remove them from existing logs with a sed command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With