简体   繁体   English

有没有一种方法可以在application.rb中使用记录器?

[英]is there a way to use logger in application.rb?

For Rails4 application, is there a way to use logger in the application.rb? 对于Rails4应用程序,是否可以在application.rb中使用记录器?

I need to print out some log information here before anything else. 我需要先在这里打印出一些日志信息。

Yes, it is possible: 对的,这是可能的:

logger = ActiveSupport::TaggedLogging.new(Logger.new(File.join(Rails.root, "log/configuration.log")))
logger.info("Some log entry")

If you want to redirect all log output to the console you may try: 如果要将所有日志输出重定向到控制台,可以尝试:

logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
logger.info("Some log entry to the console")

or for simply inspection of something: 或仅用于检查某物:

puts "Another log entry to the console"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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