来自javascript背景,我在运行rails时发现命令行杂乱无章。每当发生某些事情时,我的命令行都会被一堆垃圾填满。 E.g:
[2013-06-19 20:25:53] WARN Could not determine content-length of response body.
Set content-length of the response or set Response#chunked = true
如何关闭它以便我只看到自己的日志(当然还有错误)?
感谢任何帮助!
答案 0 :(得分:9)
尝试更改日志级别,默认为info。
来自指南:http://guides.rubyonrails.org/debugging_rails_applications.html#log-levels
答案 1 :(得分:6)
更改config/environments/development.rb
和/或testing.rb
中的日志级别:
config.log_level = :error
可用的日志级别为::debug
,:info
,:warn
,:error
,:fatal
和:unknown
,对应于整数0
- 5
。
答案 2 :(得分:1)
您可以关闭SQL查询。我知道他们占用了很多空间。
答案 3 :(得分:0)
./ .env
通常文件 .env 用于存储应用程序环境的所有重要/秘密属性。创建 .env (如果不存在)并添加代码:
RAILS_LOG_TO_STDOUT=true
./ config / environments / *。rb
编辑您的环境文件(例如./config/environments/development.rb)以创建可断开连接的日志记录系统。
Rails.application.configure do
# ...
if ENV['RAILS_LOG_TO_STDOUT'] == 'true'
logger = ActiveSupport::Logger.new(STDOUT)
# To support a formatter, you must manually assign a formatter from the config.log_formatter value to the logger.
logger.formatter = config.log_formatter
# config.logger is the logger that will be used for Rails.logger and any
# related Rails logging such as ActiveRecord::Base.logger.
# It defaults to an instance of ActiveSupport::TaggedLogging that wraps an
# instance of ActiveSupport::Logger which outputs a log to the log/ directory.
config.logger = ActiveSupport::TaggedLogging.new(logger)
# config.log_level defines the verbosity of the Rails logger.
# This option defaults to :debug for all environments.
# The available log levels are: :debug, :info, :warn, :error, :fatal, and :unknown
#config.log_level = :debug
# config.log_tags accepts a list of: methods that the request object responds to,
# a Proc that accepts the request object, or something that responds to to_s.
# This makes it easy to tag log lines with debug information like subdomain and request id -
# both very helpful in debugging multi-user production applications.
config.log_tags = [:request_id]
end
end
在 .env 中将RAILS_LOG_TO_STDOUT=true
设置为打开控制台记录器
删除或注释行RAILS_LOG_TO_STDOUT=true
,或在 .env 中将RAILS_LOG_TO_STDOUT=false
设置为关闭控制台记录器
How to start Rails server with environment variables set?