简体   繁体   中英

Rails 5: how to change log level in rails console?

I'm using Rails 5.2.5 and I want to change the log level when I use rails console. I want to stress that I don't want to change any file in the project, but just to do the change from the console.

I saw some suggestions to run:

conf.log_level = :debug

in the console, but I got the error

NameError (undefined local variable or method `config' for main:Object) Did you mean? conf

I also tried to execute

conf.log_level = :debug

but I also got the error:

Traceback (most recent call last): 2: from (irb):11 1: from (irb):11:in `rescue in irb_binding'

Do you have any suggestion?

Change YourApp configuration ( YourApp located at config/environment/[environment].rb

YourApp.configure do
 config.log_level = :info
end

Or you can use Rails.application.configure

2.5.8 :005 > Rails.application.configure do
2.5.8 :006 >     puts(config.log_level)
2.5.8 :007?>   end
debug
 => nil
2.5.8 :008 > Rails.application.configure do
2.5.8 :009 >     config.log_level = :info
2.5.8 :010?>   end
 => :info
2.5.8 :011 > Rails.application.configure do
2.5.8 :012 >     puts(config.log_level)
2.5.8 :013?>   end
info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM