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'
setNullLoggers()[source]

Helper method to set both of our loggers to Null handlers

_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.

clearSingleWarnings()[source]

Reset the single warned list so we get messages again.

warningReport()[source]

Summarize all warnings for the run.

getLogVerbosityRank(level)[source]

Return integer verbosity rank given the string verbosity name.

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
getVerbosity()[source]

Return the global runLog verbosity.

restoreStandardStreams()[source]

Set the system stderr back to its default (as it was when the run started).

startLog(name)[source]

Initialize the streams when parallel processing

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.

armi.runLog.raw(msg)[source]

Print raw text without any special functionality.

armi.runLog.extra(msg, single=False, label=None)[source]
armi.runLog.debug(msg, single=False, label=None)[source]
armi.runLog.info(msg, single=False, label=None)[source]
armi.runLog.important(msg, single=False, label=None)[source]
armi.runLog.warning(msg, single=False, label=None)[source]
armi.runLog.error(msg, single=False, label=None)[source]
armi.runLog.header(msg, single=False, label=None)[source]
armi.runLog.warningReport()[source]
armi.runLog.setVerbosity(level)[source]
armi.runLog.getVerbosity()[source]
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.

filter(record)[source]

Determine if the specified record is to be logged.

Returns True if the record should be logged, or False otherwise. If deemed appropriate, the record may be modified in-place.

class armi.runLog.RunLogger(*args, **kwargs)[source]

Bases: logging.Logger

Custom Logger to support:

  1. Giving users the option to de-duplicate warnings

  2. 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

write(msg, **kwargs)[source]

the redirect method that allows to do stderr piping

flush(*args, **kwargs)[source]

stub, purely to allow stderr piping

close()[source]

helper method, to shutdown and delete a Logger

getDuplicatesFilter()[source]

This object should have a no-duplicates filter. If it exists, find it.

warningReport()[source]

Summarize all warnings for the run.

setVerbosity(intLevel)[source]

A helper method to try to partially support the local, historical method of the same name

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.

addHandler(*args, **kwargs)[source]

ensure this STAYS a null logger

armi.runLog.logFactory()[source]

Create the default logging object.