我需要在Padrino中创建一个自定义日志文件,其中包含stdout中的所有日志信息以及自定义日志消息。我已经能够创建自定义日志文件,但标准输出文件(development.log、production.log等)仍然会在其中创建日志语句。我尝试将这些行放入boot.rb文件中,但似乎都不起作用:
Padrino::Logger::Config[:development][:stream] = :to_file
Padrino::Logger::Config[:development] = { :log_level => :debug, :stream => :to_file }
Padrino::Logger::Config[:development][:stream] = :null
Padrino::Logger::Config[:development] = { :log_level => :debug, :stream => :null}我看过帕德里诺的development commands和logger documentation,但它们没有帮助。
如果它有帮助,这是生成自定义日志文件的代码。(无论我是否运行此代码,都会不断创建stdout文件):
log_path = File.join(custom_log_path, 'My Service')
FileUtils.mkdir_p log_path
log_file_path = File.join(log_path, "MyService_#{current_date_time_formatted}.log")
logger = File.open(log_file_path, "a+")
if defined?(PADRINO_ENV) && PADRINO_ENV == 'production'
$stdout.reopen(logger)
$stderr.reopen(logger)
end任何帮助都是非常感谢的!
发布于 2013-07-10 03:45:22
你应该能够做到这一点:
Padrino::Logger::Config[:development][:stream] = logger
# or
Padrino::Logger::Config[:production][:stream] = logger在您定义了logger之后。如果config[:stream]没有接收到关键字,Padrino::Logger将使用传递的任何内容作为输出流。
有关Padrino记录器的更多信息,请查看相关的Padrino核心代码,特别是self.setup!:https://github.com/padrino/padrino-framework/blob/master/padrino-core/lib/padrino-core/logger.rb。
https://stackoverflow.com/questions/17553078
复制相似问题