4

how can I disable the logging to logs/(env).log but still preserve rails logging to STDOUT? The correct answer works in in a vanilla rails 4 app running the latest stable version of rails, with no modifications of the Gemfile (i.e. no additional dependencies) and does not use /dev/null (only modifications to ruby code). Monkey patching allowed (encouraged?).

if it works in older versions of rails thats great but not required.

Log output should not be altered in any way, e.g:

I, [2015-02-20T07:54:35.257440 #64936]  INFO -- :   Rendered /Users/lsu/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_source.erb (3.0ms)
I, [2015-02-20T07:54:35.257504 #64936]  INFO -- :   Rendered /Users/lsu/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_source.erb (3.0ms)
I, [2015-02-20T07:54:35.261314 #64936]  INFO -- :   Rendered /Users/lsu/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_trace.html.erb (1.3ms)
I, [2015-02-20T07:54:35.261366 #64936]  INFO -- :   Rendered /Users/lsu/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_trace.html.erb (1.3ms)
I, [2015-02-20T07:54:35.270427 #64936]  INFO -- :   Rendered /Users/lsu/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_request_and_response.html.erb (6.4ms)
I, [2015-02-20T07:54:35.270466 #64936]  INFO -- :   Rendered /Users/lsu/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_request_and_response.html.erb (6.4ms)
I, [2015-02-20T07:54:35.273338 #64936]  INFO -- :   Rendered /Users/lsu/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_web_console.html.erb (0.6ms)
I, [2015-02-20T07:54:35.273367 #64936]  INFO -- :   Rendered /Users/lsu/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_web_console.html.erb (0.6ms)
I, [2015-02-20T07:54:35.273420 #64936]  INFO -- :   Rendered /Users/lsu/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/diagnostics.html.erb within rescues/layout (22.8ms)

2 Answers 2

7

To suppress output to log files, set the output stream of the configured logger to nil.

# config/environments/development.rb
Rails.application.configure do
  config.logger = ActiveSupport::Logger.new(nil)
end

rails server will still log to STDOUT, but no log file is created.

Sign up to request clarification or add additional context in comments.

1 Comment

Logger.new(nil) will disable DEPRECATION WARNINGS by Rails. Pass STDOUT instead of nil to show it in the console.
2

You would add the following to your config/environments/development.rb file:

# config/environments/development.rb
ExampleApp::Application.configure do 
  ...
  config.logger = Logger.new(STDOUT)
  config.log_formatter = Logger::SimpleFormatter.new
  ...
end

Read more on The Logger.

7 Comments

this solution prepends the log output with a bunch of stuff like "I, [2015-02-19T10:46:22.566771 #73657] INFO -- :".. updated question with clarification
So, what is your expected output. Can you include an example in your question?
the expectation is that the log output is unaltered, the desired solution would simply disable the logging to the file (wherever that may be inside of rails) and simply leave the existing log to STDOUT as-is
I'm pretty sure this does exactly what you are asking for. Did you restart your rails server after making this change? All this line is doing is instead of logging to the default logger, it's outputting to STDOUT.
did you see my first comment? It prepends the log lines with "metadata" with the timestamp, loglevel, etc...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.