Design Pattern Examples
Overview of object-oriented design patterns
bridge_filelogger.py
Go to the documentation of this file.
5
6from .bridge_loggerinterface import ILogger
7from .bridge_loggerhelpers import LoggerHelpers
8
9
11
12
16 def __init__(self, filename : str) -> None:
17 self._filename = filename
18 self._file = open(filename, mode="w")
19
20
24
25
31 def _WriteLine(self, logLevel : str, msg : str) -> None:
32 if self._file:
33 formattedLine = LoggerHelpers.FormatLogLine(logLevel, msg)
34 self._file.write("{}\n".format(formattedLine))
35
36 #-------------------------------------------------------------------------
37 # ILogger interface implementation
38 #-------------------------------------------------------------------------
39
40
43 def Close(self) -> None:
44 if self._file:
45 self._file.close()
46 self._file = None
47
48
52 def LogTrace(self, msg : str) -> None:
53 self._WriteLine("TRACE", msg)
54
55
59 def LogInfo(self, msg : str) -> None:
60 self._WriteLine("INFO", msg)
61
62
66 def LogError(self, msg : str) -> None:
67 self._WriteLine("ERROR", msg)
68
69
70 #--------------------------------------------------------------------------
71 # Class factory static method
72 #--------------------------------------------------------------------------
73
74
78 @staticmethod
79 def CreateLogger(filename : str) -> ILogger:
80 return FileLogger(filename)
81
@ Close
Window is asked to close itself, generally sent by the window itself in response to a button up in a ...
Represents a logger that writes its output to a file.
None LogError(self, str msg)
Log error messages to the configured output.
None LogTrace(self, str msg)
Log trace messages to the configured output.
_filename
Name of the file to which to write log output.
None LogInfo(self, str msg)
Log informational messages to the configured output.
ILogger CreateLogger(str filename)
Create an instance of a file logger, which writes to a file.
None _WriteLine(self, str logLevel, str msg)
Write a formatted line to the log.
Represents an implementation of a logger object as called from the Logger class.