문제

I need to create a custom log file within Padrino that contains all of the logging information that is in stdout as well as custom log messages. I have been able to get the custom log file created, but the stdout file (development.log, production.log, etc.) still gets created with logging statements in it. I have tried putting these lines in the boot.rb file, but none of these seem to work:

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}

I have looked at Padrino's development commands and logger documentation but they didn't help.

In case it helps, this is the code that is generating the custom log file. (Whether I run this code or not, the stdout file keeps getting created):

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

Any help is greatly appreciated!

도움이 되었습니까?

해결책

You should be able to do this:

Padrino::Logger::Config[:development][:stream] = logger
# or
Padrino::Logger::Config[:production][:stream] = logger

after you have defined logger. If config[:stream] doesn't receive a keyword, Padrino::Logger will use whatever is passed as the output stream.

For more information on the Padrino logger, check out the relevant Padrino Core code, especially self.setup!: https://github.com/padrino/padrino-framework/blob/master/padrino-core/lib/padrino-core/logger.rb.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top