logger_utils.py#
Miscellaneous utilities related to logging.
- class openmdao.utils.logger_utils.TestLogger[source]
Bases:
object
A logger that saves messages in lists.
- Attributes:
- _msgsdict
Stores lists of messages under ‘error’, ‘warning’, and ‘info’ keys.
- __init__()[source]
Initialize the message dict.
- contains(typ, message)[source]
Do any of the stored messages of a specific type equal the given message.
- Parameters:
- typstr
Type of messages (‘error’, ‘warning’, ‘info’) to be returned.
- messagestr
The message to match.
- Returns:
- bool
True if any of the lines of stored messages of a specific type equal the line.
- error(msg)[source]
Collect an error message.
- Parameters:
- msgstr
An error message.
- find_in(typ, message)[source]
Find the given message among the stored messages.
Raises an exception if the given message isn’t found.
- Parameters:
- typstr
Type of messages (‘error’, ‘warning’, ‘info’) to be searched.
- messagestr
The message to match.
- find_match_in(typ, pattern)[source]
Find a message with the given pattern among the stored messages.
Raises an exception if a message with the given pattern isn’t found.
- Parameters:
- typstr
Type of messages (‘error’, ‘warning’, ‘info’) to be searched.
- patternstr
The pattern to match.
- get(typ)[source]
Return all stored messages of a specific type.
- Parameters:
- typstr
Type of messages (‘error’, ‘warning’, ‘info’) to be returned.
- Returns:
- list of str
Any messages of that type that have been written to the logger.
- info(msg)[source]
Collect an informational message.
- Parameters:
- msgstr
An informational message.
- warning(msg)[source]
Collect a warning message.
- Parameters:
- msgstr
A warning message.
- openmdao.utils.logger_utils.get_logger(name='default_logger', level=20, use_format=False, out_stream='stdout', out_file=None, lock=None)[source]
Return a logger that writes to an I/O stream.
- Parameters:
- namestr
Name of the logger to be returned, will be created if it doesn’t exist.
- levelint
Logging level for this logger. Default is logging.INFO (level 20). (applied only when creating a new logger or setting a new stream).
- use_formatbool
Set to True to use the openmdao format “Level: message”. (applied only when creating a new logger or setting a new stream).
- out_stream‘stdout’, ‘stderr’ or file-like
Output stream to which logger output will be directed.
- out_filestr or None
If not None, add a FileHandler to write to this file.
- lockbool
If True, do not allow the handler to be changed until unlocked. If False, unlock the handler for the logger.
- Returns:
- <logging.Logger>
Logger that writes to a stream and adheres to requested settings.