Permit buffered log appending

This commit is contained in:
Joshua Boniface 2023-11-29 16:02:06 -05:00
parent 787f4216b3
commit fa12a3c9b1
1 changed files with 3 additions and 2 deletions

View File

@ -80,7 +80,7 @@ class Logger(object):
self.config["log_directory"] + "/" + self.config["daemon_name"] + ".log" self.config["log_directory"] + "/" + self.config["daemon_name"] + ".log"
) )
# We open the logfile for the duration of our session, but have a hup function # We open the logfile for the duration of our session, but have a hup function
self.writer = open(self.logfile, "a", buffering=0) self.writer = open(self.logfile, "a")
self.last_colour = "" self.last_colour = ""
self.last_prompt = "" self.last_prompt = ""
@ -93,7 +93,7 @@ class Logger(object):
# Provide a hup function to close and reopen the writer # Provide a hup function to close and reopen the writer
def hup(self): def hup(self):
self.writer.close() self.writer.close()
self.writer = open(self.logfile, "a", buffering=0) self.writer = open(self.logfile, "a")
# Provide a termination function so all messages are flushed before terminating the main daemon # Provide a termination function so all messages are flushed before terminating the main daemon
def terminate(self): def terminate(self):
@ -152,6 +152,7 @@ class Logger(object):
# Assemble output string # Assemble output string
output = colour + prompt + endc + date + prefix + message output = colour + prompt + endc + date + prefix + message
self.writer.write(output + "\n") self.writer.write(output + "\n")
self.writer.flush()
# Log to Zookeeper # Log to Zookeeper
if self.config["zookeeper_logging"]: if self.config["zookeeper_logging"]: