Is there a way to change log format of Rails app in production?

I have Rails 3 app that runs on Nginx server using Puma. The logs goes to logs/production.log.

I was wondering if there is a way to change the format of the logs, so it includes more information that I can use. Informations like userId (if signed in) or sessionId, etc.

Is there a way to configure the format of the logs?

Right now they are like this:

Started GET "/" for at 2015-02-11 06:37:53 +0000
  Processing by MyController#home as HTML
Rendered my/home.html.erb within layouts/home (93.2ms)
Completed 200 OK in 542ms (Views: 94.8ms | ActiveRecord: 158.6ms)

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

These two blog posts were really helpful for me in understanding how to configure and modify logging in Rails applications:

At the most basic, you can configure Rails to log more information by setting config.log_level = debug in your config/application.rb But you can also totally customize the output and information available by writing your own formatter. If you’re looking to just append a bit more info, you might look at the config.log_tags setting. From the docs:

config.log_tags accepts a list of methods that the request object responds to. This makes it easy to tag log lines with debug information like subdomain and request id - both very helpful in debugging multi-user production applications.

For example, to add a user’s UUID to the logs:

config.log_tags = [ :uuid ]