Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable logging in Ruby on Rails on a per-action basis?

I have a Rails application that has an action invoked frequently enough to be inconvenient when I am developing, as it results in a lot of extra log output I don't care about. How can I get rails not to log anything (controller, action, parameters, completion time, etc.) for just this one action? I'd like to conditionalize it on RAILS_ENV as well, so logs in production are complete.

Thanks!

like image 429
archbishop Avatar asked Feb 04 '10 01:02

archbishop


People also ask

Where are rails logs stored?

In a Rails app, logs are stored under the /log folder. In development mode, the development. log file is used & you see log output on the terminal you're running rails server on.

How does Rails logger work?

Rails is configured to create separate log files for each of the three default environments: development, test and production. By default it puts these log files in the log/ directory of your project. So if you open up that folder you'll see a development. log and test.

Where are Ruby on Rails logs?

By default, each log is created under Rails. root/log/ and the log file is named after the environment in which the application is running.

What is logger in Ruby?

Logger is a simple but powerful logging utility to output messages in your Ruby program. Logger has the following features: Print messages to different levels such as info and error. Auto-rolling of log files. Setting the format of log messages.


2 Answers

You can silence the Rails logger object:

def action
  Rails.logger.silence do
    # Things within this block will not be logged...
  end
end
like image 139
Josh Delsman Avatar answered Nov 07 '22 22:11

Josh Delsman


Use lograge gem.

Gemfile:

gem 'lograge'

config/application.rb:

config.lograge.enabled = true
config.lograge.ignore_actions = ['StatusController#nginx', ...]
like image 18
merqlove Avatar answered Nov 07 '22 20:11

merqlove