From 98446561cf3c7126dd93b34c9be361fa4aa8da36 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 29 May 2021 18:47:29 +0200 Subject: fix: restart logger thread after fork Logging was broken when daemonizing, due to the logger thread being dead after the fork. This can be solved by restarting the thread, if necessary when setting the log file (which we conveniently do right after the fork). --- lib/rbot/ircbot.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/rbot/ircbot.rb') diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index ecb48449..4eac68d6 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -403,6 +403,8 @@ class Bot debug "Using `#{@logfile}' as debug log" end + LoggerManager.instance.flush + # See http://blog.humlab.umu.se/samuel/archives/000107.html # for the backgrounding code if $daemonize @@ -421,8 +423,11 @@ class Bot # File.umask 0000 # Ensure sensible umask. Adjust as needed. end - # setup logger based on bot configuration - LoggerManager.instance.set_level(@config['log.level']) + # setup logger based on bot configuration, if not set from the command line + loglevel_set = $opts.has_key?('debug') or $opts.has_key?('loglevel') + LoggerManager.instance.set_level(@config['log.level']) unless loglevel_set + + # Set the logfile LoggerManager.instance.set_logfile(@logfile, @config['log.keep'], @config['log.max_size']) if $daemonize -- cgit v1.2.3