I’m trying to direct all my logging to a single file, specified by me. Unfortunately, while much of my game’s output does indeed go to that file, I still seem to get some output directed to the console, and some to files named in the pattern “log.<date-and-time>”. And I’m not sure of what I’m doing wrong.
This is, roughly speaking, how I’m setting up logging. The code is a little more spread out than I’m depicting here, but this should give you the general idea of my approach:
In the “Common” class, which handles logging:
class Common(): # An exit-handler designed to print crash-reports and the like to the log-file. # This seems to be somewhat hit-and-miss. @staticmethod def exitHandler(): Common.nout.flush() if hasattr(sys, "last_traceback"): errorList = traceback.format_exception(sys.last_type, sys.last_value, sys.last_traceback) errorString = "".format(errorList) Common.warn(errorString) # Initial setup of logging. @staticmethod def setupLogging(): filename = Filename(USER_DIR + "/logfile.txt") # Replace the file if it exists (so that it doesn't # append every run's output one after another) if filename.exists(): filename.unlink() Common.nout = MultiplexStream() Notify.ptr().setOstreamPtr(Common.nout, 0) Common.nout.addFile(filename) atexit.register(Common.exitHandler) # Initialisation code general to this class, # part of which is a final bit of logging setup. @staticmethod def initialise(fadeBin): Common.notifier = DirectNotify().newCategory("GameMessages") if Common.nout is not None: Common.notifier.setLogging(True) base.notify.__class__.streamWriter = StreamWriter(Notify.out(), False) # Other logic follows that's unrelated.
In the game’s core-class:
def __init__(self): Common.setupLogging() # A bit of code in-between... Common.initialise(GUI_BIN)
Does anyone see what the problem might be?