2

Running the rails server with rails s results in a huge amount of text being outputted to the screen, as it appears to be logging at the verbose :info level. When I'm debugging, sometimes I just to print a few variables to screen via awesome_print, and don't want to sift through the text.

So is there a config setting in the developlment environment file I can set to completely supress the output, (apart from the output from my ap calls)?

1
  • you could just detach the server from the console using rails s --detach Commented Mar 26, 2014 at 0:55

4 Answers 4

1

You can silence the assets and just get the important information for developing, just add a file in your initializers, like config/initializers/silent_assets.rb with the following code

if Rails.env.development?

  Rails.application.assets.logger = Logger.new('/dev/null')

  Rails::Rack::Logger.class_eval do
    def call_with_quiet_assets(env)
      previous_level = Rails.logger.level
      Rails.logger.level = Logger::ERROR if env['PATH_INFO'] =~ %r{^/assets/}
      call_without_quiet_assets(env)
    ensure
      Rails.logger.level = previous_level
    end
    alias_method_chain :call, :quiet_assets
  end

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

2 Comments

where do you define call_without_quiet_assets?
Ah, it's created by alias_method_chain
0

You can control what gets logged in development, by customizing your config/environments/development.rb file.

Here you can find documentation on the various options.

You might want to set:

  1. config.log_level
  2. config.assets.debug (controls assets compilation and, as a side effect, shuts down assets compilation messages)

Comments

0

Another option would be to edit the file config/environments/development.rb, and set the log level to error:

config.log_level = :error

Then just print with awesome_print

ap {a: 1, b: 2}

If you start the server from the console like

script/rails s

In that console you will see just the output of awesome_print

3 Comments

So script/rails s instead of rails s? What's the significance of this?
btw do you mean bin/rails s ? :)
just start the server from the console, like running rails server
0

None of the other answers answer the question.

Use

config.logger = Logger.new('log/development.log')

Comments

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.