【问题标题】:Rails 5: how to change log level in rails console?Rails 5:如何在 Rails 控制台中更改日志级别?
【发布时间】:2021-07-26 13:05:51
【问题描述】:

我使用的是 Rails 5.2.5,我想在使用 rails 控制台时更改日志级别。 我想强调一下,我不想更改项目中的任何文件,而只是从控制台进行更改。

我看到了一些运行建议:

conf.log_level = :debug

在控制台中,但我得到了错误

NameError(未定义的局部变量或方法 `config' 主要:对象)你的意思是?配置

我也尝试过执行

conf.log_level = :debug

但我也得到了错误:

Traceback(最近一次调用最后一次): 2:来自(irb):11 1: from (irb):11:in `rescue in irb_binding'

你有什么建议吗?

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    更改YourApp 配置(YourApp位于config/environment/[environment].rb

    YourApp.configure do
     config.log_level = :info
    end
    

    或者你可以使用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
    

    【讨论】:

    • “Rails.application.configure do”为我工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    相关资源
    最近更新 更多