Skip to content

Commit

Permalink
Add MemoryHandler to logger and flush it to created logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
LegenJCdary committed Jun 21, 2022
1 parent b0e1548 commit 0d3fefc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 11 additions & 2 deletions source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,17 @@ def main():
config = configuration.load_configuration()

if options["subcommand"] in ("run", "verify"):
workdir = misc.create_workdir(start_ts, conf, logger.logger)
Loggers.set_logging_to_file(logger, workdir, start_ts, conf)
workdir = misc.create_workdir(start_ts, configuration.conf, logger.logger)
Loggers.set_logging_to_file(logger, workdir, start_ts, configuration.conf)
if options["syslog"]:
# handler[1] - MemoryHandler, handler[3] - FileHandler
logger.logger.handlers[1].setTarget(logger.logger.handlers[3])
else:
# handler[0] - MemoryHandler, handler[2] - FileHandler
logger.logger.handlers[0].setTarget(logger.logger.handlers[2])
logger.logger.handlers[0].flush()
else:
logger.logger.handlers[0].close()

validators = Validators(logger.logger)
validators.validate_options(options)
Expand Down
5 changes: 5 additions & 0 deletions source/modules/outputs/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def set_logging(options: dict):
rsys_handler.setLevel(logging.WARNING)
logger.addHandler(rsys_handler)

memory_handler = log_han.MemoryHandler(15, flushLevel=logging.DEBUG, flushOnClose=False)
memory_handler.setFormatter(formatter)
memory_handler.setLevel(logging.DEBUG)
logger.addHandler(memory_handler)

console_handler = logging.StreamHandler()
console_handler.setFormatter(console_formatter)
console_handler.setLevel(logging.DEBUG if options["debug"] else logging.INFO)
Expand Down

0 comments on commit 0d3fefc

Please sign in to comment.