After demonstrating the script, the logger can no longer write to the file. So how and when should I initialize the log?
require 'rubygems'
require 'daemons'
require 'logging'
def create_new_logger
logger = Logging.logger['trend-analyzer']
logger.add_appenders(
Logging.appenders.rolling_file('./logs/trend-analyzer.log'),
Logging.appenders.stdout
)
logger.level = :debug
return logger
end
logger = create_new_logger
logger.debug Time.new
Daemons.run_proc('ForestPress', :log_dir => '.logs', :backtrace => true) do
running_as_daemon = true
logger.debug Time.new
loop do
logger.info Time.new
sleep 5
end
end
EDIT
I noticed that the current path has changed from where I ran the script to /. Maybe that's why I can not register messages?
EDIT 2
Now I save the original path before becoming a daemon, and then use Dir.chdirto set the path to the original path. Then I can open the file directly and write to it. However, the logbook cannot write to him yet.
source
share