Package wsatools :: Module Logger
[hide private]

Module Logger

source code

Logging of run-time messages. Messages are logged through calling static methods of the singleton class Logger. Message logs are kept in memory until an instance of a Logger class object is destroyed, at which point the log is written to a file - over-writing any previous log file with the same name. There is also an option that writes the log to file continuously. We do not append to pre-existing log files with the same name, as this would be confusing, especially when test databases are reset.

Also, a ForLoopMonitor class is provided to display percentage completion progress of for-loops. Use to monitor lengthy For-Loops, providing the minimal logged output of percentage progess to completion.



Import as:

   from wsatools.Logger import Logger

To log a message, just simply call:

   Logger.addMessage("My message")

When logging exception messages:

   except Exception as error:

To include a trace of where the exception occurred:

   except Exception as error:

If it's an exception that has been ignored:

   except Exception as error:

To save a log to a file, just create an instance of a Logger object, initialised with the log file name. The log will be written when the object loses scope - so make sure it remains in scope for the duration that the logging is required:

   log = Logger("event.log")

See Logger class documentation for more capabilities.

Monitoring For-Loops

Import as:

   from wsatools.Logger import ForLoopMonitor

To use, construct a ForLoopMonitor just before the start of the For-Loop, and call ForLoopMonitor.testForOutput() at the end of every loop:

   progress = ForLoopMonitor(aLongList)
   for entry in aLongList:
       # do stuff

To Do: Define the verbose CLI option here - need to be careful though to make sure that the scripts that inherit it don't already have -v options - also would be nice to make sure they all use it!

Author: I.A. Bond

Organization: WFAU, IfA, University of Edinburgh

Contributors: R.S. Collins, N.C. Hambly, E. Sutorius

Classes [hide private]
A monostate class for run-time logging of messages.
Monitors lengthy For-Loops by logging progress at 10% intervals.
Variables [hide private]
  __package__ = 'wsatools'