By AminYazdani
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 xxx.xxx.xxx.xx 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)
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!
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_tagsaccepts 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 ]
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.