Logging

Mechanica has a detailed logging system. Many internal methods will log extensive details to either the clog (typically stderr) or a user specified file path. The logging system can be configured to log events at various levels of detail. All methods of the Logger are static, they are available immediately upon loading the Mechanica package.

To display logging at the lowest level (TRACE), where every logging message is displayed, is as simple as,

import mechanica as mx
mx.Logger.setLevel(mx.Logger.TRACE)

Enabling logging to terminal and disabling are also single commands,

mx.Logger.enableConsoleLogging(mx.Logger.DEBUG)
...
mx.Logger.disableConsoleLogging()

Messages can also be added to the log by logging level.

mx.Logger.log(mx.Logger.FATAL, "A fatal message. This is the highest priority.")
mx.Logger.log(mx.Logger.CRITICAL, "A critical message")
mx.Logger.log(mx.Logger.ERROR, "An error message")
mx.Logger.log(mx.Logger.WARNING, "A warning message")
mx.Logger.log(mx.Logger.NOTICE, "A notice message")
mx.Logger.log(mx.Logger.INFORMATION, "An informational message")
mx.Logger.log(mx.Logger.DEBUG, "A debugging message.")
mx.Logger.log(mx.Logger.TRACE,  "A tracing message. This is the lowest priority.")
mechanica.Logger

alias of MxLogger

class mechanica.MxLogger

The Mechanica logger.

A set of static method for setting the logging level.

static setLevel(level: int = 0) void

Set the Level objectsets the logging level to one a value from Logger::Level

Parameters

level (int) – logging level

static getLevel() int

Get the Level objectget the current logging level.

Return type

int

Returns

int

static disableLogging() void

Suppresses all logging output

static enableConsoleLogging(level: int = 0) void

turns on console logging at the given level.

Parameters

level (int) – logging level

static disableConsoleLogging() void

stops logging to the console, but file logging may continue.

static enableFileLogging(*args, **kwargs) void

turns on file logging to the given file as the given level.

If fileName is an empty string, then nothing occurs.

Parameters
  • fileName (string) – path to log file

  • level (int) – logging level

static disableFileLogging() void

turns off file logging, but has no effect on console logging.

static getCurrentLevelAsString() std::string

get the textural form of the current logging level.

Return type

string

Returns

std::string

static getFileName() std::string

Get the File Name objectget the name of the currently used log file.

Return type

string

Returns

std::string

static levelToString(level: int) std::string

gets the textual form of a logging level Enum for a given value.

static stringToLevel(str: std::string const &) MxLogLevel

parses a string and returns a Logger::Level

static log(level: MxLogLevel, msg: std::string const &) void

logs a message to the log.

Parameters
  • level (int) – logging level

  • msg (string) – log message