armi.runLog module¶
This module handles logging of console output (e.g. warnings, information, errors) during an armi run.
The default way of calling and the global armi logger is to just import it:
from armi import runLog
You may want a logger specific to a single module, say to provide debug logging for only one module. That functionality is provided by a global override of logging imports:
import logging
runLog = logging.getLogger(__name__)
In either case, you can then log things the same way:
runLog.info('information here')
runLog.error('extra error info here')
raise SomeException # runLog.error() implies that the code will crash!
Or change the log level the same way:
runLog.setVerbosity('debug')
-
class
armi.runLog.
_RunLog
(mpiRank=0)[source]¶ Bases:
object
Handles all the logging For the parent process, things are allowed to print to stdout and stderr, but the stdout prints are formatted like log statements. For the child processes, everything is piped to log files.
Build a log object
- Parameters
mpiRank (int) – If this is zero, we are in the parent process, otherwise child process. The default of 0 means we assume the parent process. This should not be adjusted after instantiation.
-
STDERR_NAME
= '{0}.{1:04d}.stderr'¶
-
STDOUT_NAME
= '{0}.{1:04d}.stdout'¶
-
_setLogLevels
()[source]¶ Here we fill the logLevels dict with custom strings that depend on the MPI rank
-
log
(msgType, msg, single=False, label=None)[source]¶ This is a wrapper around logger.log() that does most of the work and is used by all message passers (e.g. info, warning, etc.).
In this situation, we do the mangling needed to get the log level to the correct number. And we do some custom string manipulation so we can handle de-duplicating warnings.
-
getDuplicatesFilter
()[source]¶ The top-level ARMI logger should have a no duplicates filter If it exists, find it.
-
setVerbosity
(level)[source]¶ Sets the minimum output verbosity for the logger.
Any message with a higher verbosity than this will be emitted.
- Parameters
level (int or str) – The level to set the log output verbosity to. Valid numbers are 0-50 and valid strings are keys of logLevels
Examples
>>> setVerbosity('debug') -> sets to 0 >>> setVerbosity(0) -> sets to 0
-
armi.runLog.
close
(mpiRank=None)[source]¶ End use of the log. Concatenate if needed and restore defaults
-
armi.runLog.
concatenateLogs
(logDir=None)[source]¶ Concatenate the armi run logs and delete them.
Should only ever be called by parent.
-
class
armi.runLog.
DeduplicationFilter
(*args, **kwargs)[source]¶ Bases:
logging.Filter
Important logging filter
allow users to turn off duplicate warnings
handles special indentation rules for our logs
Initialize a filter.
Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.
-
class
armi.runLog.
RunLogger
(*args, **kwargs)[source]¶ Bases:
logging.Logger
Custom Logger to support:
Giving users the option to de-duplicate warnings
Piping stderr to a log file
Initialize the logger with a name and an optional level.
-
FMT
= '%(levelname)s%(message)s'¶
-
log
(msgType, msg, single=False, label=None)[source]¶ This is a wrapper around logger.log() that does most of the work and is used by all message passers (e.g. info, warning, etc.).
In this situation, we do the mangling needed to get the log level to the correct number. And we do some custom string manipulation so we can handle de-duplicating warnings.
-
_log
(*args, **kwargs)[source]¶ Wrapper around the standard library Logger._log() method
The primary goal here is to allow us to support the deduplication of warnings.
Note
All of the
*args
and**kwargs
logic here are mandatory, as the standard library implementation of this method has been changing the number of kwargs between Python v3.4 and v3.9.
-
allowStopDuplicates
()[source]¶ helper method to allow us to safely add the deduplication filter at any time
-
class
armi.runLog.
NullLogger
(name, isStderr=False)[source]¶ Bases:
armi.runLog.RunLogger
This is really just a placeholder for logging before or after the span of a normal armi run. It will forward all logging to stdout/stderr, as you’d normally expect. But it will preserve the formatting and duplication tools of the armi library.
Initialize the logger with a name and an optional level.