Reputation: 1244
I have a Rails 5 app in Heroku, and set up a Papertrailapp account to check the logs easier than checking manually in the console via heroku logs -t
. And I'm loving it. But I feel there's too much noise.
Before I used to activate Rails-12-factor gem to be able to see SQL logs in Heroku, but now they say from Rails 5 and up it's not needed anymore. So now I see the SQL w/out problem, but it's longer than before.
Feb 24 20:38:59 myapp-staging app/web.1: I, [2017-02-25T01:38:59.133806 #4] INFO -- : [b2be3dbb-edb6-45f7-8686-d37304ad3782] Rendered shared_partials/_head.html.slim (0.8ms)
That's a sample of a common line of log I see in Papertrail, so I'd like to understant some parts of it, and get an idea on how to disable some of those parts.
Feb 24 20:38:59 # Papertrail DateTime
myapp-staging # Papertrail system
app/web.1: # Heroku Dyno
I, # I guess this comes from the "new" Rails-12-factor way of logging, INFO, DEBUG, and so on
[2017-02-25T01:38:59.133806 #4] # I guess it's the DateTime from Heroku server
INFO -- : # Again, the type of log, but whole word. Rails generated?
[b2be3dbb-edb6-45f7-8686-d37304ad3782] # This is a hash that IDK where it comes from, nor what it means and what is used for
Rendered shared_partials/_head.html.slim (0.8ms) # The actual log message of Rails app
So I guess my questions are:
I,
part, that is already in the INFO --
Thanks to the @slothbear answer, I0've checked manually the logs form the console heroku logs -t
and I've noticed the Papertrail Datetime seems to be actually a reformat from Heroku DateTime because a regular message looks like this:
2017-02-26T18:00:09.976118+00:00 # Heroku Datetime
app[web.1]: # Heroku source[dyno]
I, # Type of log
[2017-02-26T18:00:09.976009 #4] # Rails Datetime
INFO -- : # Again type of log
[a6612ea9-1a31-46d3-8c8d-7f93f971c379] # Request ID
Rendered shared_partials/_top_card.html.slim (3.5ms) # Actual Rails message
So, knowing that Heroku DateTime would be more difficult to remove, I think I'll remove Rails DateTime, and may be RequestID too.
Upvotes: 1
Views: 450
Reputation: 2056
The long hash is the request_id
. This ID allows you to track a single request in the log. You can remove the ID by editing config/environments/production.rb
:
config.log_tags = [ :request_id ]
The DateTime format can be set to something short in production.rb
, though some characters remain:
config.log_formatter.datetime_format = ""
For more control of the message after the Heroku-standard parts (as interpreted by Papertrail) you need a custom log formatter. The production default is Logger::Formatter, as described in the Configuring Rails Applications guide. You can replace the default logger in production.rb
:
# config.log_formatter = ::Logger::Formatter.new
class UnmultiFormatter < ::Logger::Formatter
def call(severity, time, progname, msg)
"unmultilog [#{severity}]: #{msg}\n"
end
end
config.log_formatter = UnmultiFormatter.new
Note that this custom formatter gets wrapped by TaggedLogging
if the RAILS_LOG_TO_STDOUT
environment variable is set — which is set by default on Heroku.
Bad consequences of removing items? When debugging complex issues, more information is always better – and the default log information has been devised by a lot of smart folks. If you're working with a simpler app you're probably ok. Ideally, the log viewer would let you turn off items as you like – and turn them back on if debugging requires them. Papertrail does some of this: click on Options at the bottom of the screen and you can turn off time, app, and program name.
Upvotes: 1