Package wsatools :: Module Logger :: Class Logger
[hide private]

Class Logger

source code


A monostate class for run-time logging of messages. Just call Logger.addMessage() to log a message. To output messages to a file you just need to create an instance of a Logger object, and when that object falls out-of-scope the log file will be written. Alternatively, if the isVerbose option is set to False, then the log file will be written too continuously whilst an initialised Logger object is in scope.


To Do:
Instance Methods [hide private]
 
__init__(self, fileName, path=None)
Initialise a Logger object by setting the full path to the log file.
source code
 
__del__(self)
Writes all messages that have been currently logged.
source code
 
_revertToHomePath(self, exception)
Reverts the log file path to the home directory in case of error.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
addExceptionDetails(e, eType=None)
Log the details of a trapped exception to the accumulating log file for a CU invocation.
source code
 
addExceptionMessage(e, eType=None, includeTrace=False)
Logs a message from a raised exception.
source code
 
addExceptionWarning(e, eType=None, echoOff=False)
Logs a message from a raised exception, that has been ignored.
source code
 
addMessage(message, alwaysLog=True, echoOff=False)
Log a message.
source code
 
dump(handle)
Write all messages that have been currently logged.
source code
str, str
extractExceptionDetails(e, stripScript=False)
Extracts useful information to be logged from a thrown exception.
source code
 
reset()
Remove all messages that have currently been logged.
source code
 
setEchoOn()
Echo all messages to standard output when logged.
source code
 
setEchoOff()
Log messages will be NOT echoed to standard output.
source code
Class Variables [hide private]
  archive = False
Archive all existing logs for the current database upon initialisation?
  echoOn = True
Echo log to terminal?
  isVerbose = True
Is this a verbose log? If not, continually write the log to file.
  pathName = ''
Full path to the log file.
  reqClearLine = False
Requires a line clear before logging?
  _logText = []
List of every log entry.
  _logTime = []
List of the time of every log entry.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, fileName, path=None)
(Constructor)

source code 

Initialise a Logger object by setting the full path to the log file. The path is existed to make sure it exists, and if isVerbose is set to False then the log file is initialised with messages logged to date.

Parameters:
  • fileName (str) - Name of the log file.
  • path (str) - Log file directory path. Defaults to system log path.
Overrides: object.__init__

_revertToHomePath(self, exception)

source code 

Reverts the log file path to the home directory in case of error.

Parameters:
  • exception (Exception) - The exception that mandates to this reversion.

addExceptionDetails(e, eType=None)
Static Method

source code 

Log the details of a trapped exception to the accumulating log file for a CU invocation. Also logs full trace-back information as to where the exception occurred (useful for programming errors).

Parameters:
  • e (Exception) - An instance of the exception thrown.
  • eType (str) - Optional description of type of exception to be logged.

To Do: This function is deprecated. Use addExceptionMessage() with the includeTrace flagged turned on instead.

addExceptionMessage(e, eType=None, includeTrace=False)
Static Method

source code 

Logs a message from a raised exception.

Parameters:
  • e (Exception) - An instance of the exception thrown.
  • eType (str) - Optional description of type of exception to be logged.
  • includeTrace (bool) - If True, include traceback in log message.

addExceptionWarning(e, eType=None, echoOff=False)
Static Method

source code 

Logs a message from a raised exception, that has been ignored.

Parameters:
  • e (Exception) - An instance of the exception thrown.
  • eType (str) - Optional description of type of exception to be logged.
  • echoOff (bool) - Don't display this message to the screen - just write it to the log file.

addMessage(message, alwaysLog=True, echoOff=False)
Static Method

source code 

Log a message. This is displayed to stdout if in "echoOn" mode, and also written to the log file if not in "isVerbose" mode.

Parameters:
  • message (str) - The message to log.
  • alwaysLog (bool) - If False, then this message will only be logged when isVerbose is True.
  • echoOff (bool) - Don't display this message to the screen - just write it to the log file.

dump(handle)
Static Method

source code 

Write all messages that have been currently logged.

Parameters:
  • handle (file) - File handle to which to send the messages.

extractExceptionDetails(e, stripScript=False)
Static Method

source code 

Extracts useful information to be logged from a thrown exception. Includes some specific features for database exceptions.

Parameters:
  • e (Exception) - An instance of the exception thrown.
  • stripScript (bool) - If True, for database exceptions, do not report the original script executed.
Returns: str, str
Exception class and error message.