ConsoleUser

Copyright (c) 2010-2023 Skaion Corporarion, www.skaion.com

This project was developed in part by numerous sponsorships from the U.S. Government. The U.S. Government is authorized to reproduce and distribute reprints of Governmental purposes notwithstanding any copyright notation thereon.

All content reflects those of the authors and should not be interpreted as necessarily representing the official policies or endorsements, either expressed or implied, of the U.S. Government or Skaion Corporation.

class Logger.Logger(out_file=None, do_rotates=True)

Handle all the logging with different levels that can be specified at runtime to turn on the or off various types of printouts

Parameters:

  • file: Optionally the path to the file to write

debug(msg)

If debug messages are enabled log this message with a debug prefix and some stacktrace information about the function which is responsible for this call.

Parameters:

  • msg: the string to log

doStderr(err)

Should we print error messages to stderr as well as to a log file or not

Parameters:

  • err: True if error prints should also print to stderr in addition to being logged

elog(msg)

Write an error message prefixed with an indicator to either the error log or the standard log, and if doStderr was called with a true value also print it to stderr

Parameters:

  • msg: the string to write to the log file

getDebug()

Return whether or not debug logging is enabled

getTrace()

Return whether or not trace logging is enabled

getVerbose()

Return whether or not verbose level logging is enabled

get_null()

Return: whether or not this Logger is a “null” logger

get_path()

Getter for the path to the file this is using

log(msg)

Write the given message to the log file if there is one or stderr otherwise. Calls to this method can result in the current log file needs to be rotated (and rotating it if it does need it).

Parameters:

  • msg: the string to be logged

openErr(path)

Open a file to write error messages to, they will no longer go to the standard log file if you call this, though you can still have them printed to stderr if you like with a call to doStderr

Parameters:

  • file: the path to write error messages to

openLog(path)

Open a file to write our log messages to

Parameters:

  • file: the path to the file to write log messages to

setDebug(debug_val)

Set whether debug prints will be displayed or not

Parameters:

  • debug_val: True if debug level prints should be logged, False otherwise

setTrace(trace_val)

Set whether or not trace level outputs should be logged. If this is passed True it will enable debug and higher prints as well. Passing False will not disable other levels of logging.

Parameters:

  • trace_val: True if trace level prints should be logged, False otherwise

setVerbose(verbose)

Set whether verbose prints will be displayed or not

Parameters:

  • verbose: True if verbose level prints should be logged, False otherwise

set_null(val)

Set whether or not this Logger object should be a “null” object which will still accept all the function calls, but will not produce any output

trace(msg)

Write the message iff the trace level of logging was enabled.

Parameters:

  • msg: the message to log

vlog(msg)

Alternate spelling of vprint for more consistency

Parameters:

  • msg: the string to possibly log

vprint(msg)

If verbose printing is enabled log this message otherwise ignore it

Parameters:

  • msg: the string to possibly log

wlog(msg)

Write the message to the log with a prefix indicating it is a warning message

Parameters:

  • msg: the string to write to the log file

Logger.debug(msg)

If debug messages are enabled log this message with a debug prefix and a suffix from a stacktrace indicating the function which initiated this call

Parameters:

  • msg: the string to log

Logger.doStderr(val)

Set whether error messages should always be printed to stderr as well as logged.

Parameters:

  • val: whether or not error messages should also go to stderr

Logger.elog(msg)

Write an error message prefixed with an indicator to either the error log or the standard log, and if doStderr was called with a true value also print it to stderr

Parameters:

  • msg: the string to log

Logger.getDebug()

Get whether or not the deault logger is in debug mode

Logger.getTrace()

Get whether or not TRACE level messages are being logged by the default logger

Logger.getVerbose()

Get whether or not the deault logger is in verbose mode

Logger.init(path)

Create a new logger who logs messages to the given path

Parameters:

  • path: the path to write log messages to

Logger.load_config()

Load the configuration for how loggers should operate

Logger.log(msg)

Write the given message to the log file if there is one or stderr otherwise

Parameters:

  • msg: the string to log

Logger.openErr(path)

Open a file to write error messages to, they will no longer go to the standard log file if you call this, though you can still have them printed to stderr if you like with a call to doStderr

Parameters:

  • path: the path to the file to log error messages to

Logger.openLog(path)

Open a log file for these log messages to be written to

Parameters:

  • path: the path to the file to write log messages to

Logger.setDebug(val)

Set whether debug messages are logged or not. If True verbose will also be enabled. If False, trace will be disabled.

Parameters:

  • val: the new value for whether or not debug messages should be logged

Logger.setTrace(val)

Set whether or not trace level messages should be logged. If True debug and higher levels will also be enabled. If False no other levels will be disabled.

Parameters:

  • val: the new value for whether or not trace messages should be logged

Logger.setVerbose(val)

Set whether verbose prints are logged or not. If set to False, Debug and lower levels will also be disabled. If True no other levels will be changed.

Parameters:

  • val: the new value for whether or not verbose messages should be logged

Logger.trace(msg)

If trace level messages are enabled, log this message with a trace prefix.

Parameters:

  • msg: the trace message to log

Logger.trace_and_prep(func)

This is a decorator that will call the starting and ending trace messages surrounding invoking the instance method.

Logger.trace_instance(func)

This is a decorator that will call the starting and ending trace messages surrounding invoking the instance method.

Logger.vlog(msg)

Alternate spelling of vprint for greater consistency

Parameters:

  • msg: the string to log

Logger.vprint(msg)

If verbose printing is enabled log this message otherwise ignore it

Parameters:

  • msg: the string to log

Logger.wlog(msg)

Write the message to the log with a prefix indicating it is a warning message

Parameters:

  • msg: the string to log