Bases: logging.Logger
This class is used to set up the Astropy logging.
The main functionality added by this class over the built-in logging.Logger class is the ability to keep track of the origin of the messages, the ability to enable logging of warnings.warn calls and exceptions, and the addition of colorized output and context managers to easily capture messages to a file or list.
Initialize the logger with a name and an optional level.
Methods Summary
disable_color() | Disable colorized output |
disable_exception_logging() | Disable logging of exceptions Once called, any uncaught exceptions will no longer be emitted by this logger. |
disable_warnings_logging() | Disable logging of warnings.warn() calls Once called, any subsequent calls to warnings.warn() are no longer redirected to this logger. |
enable_color() | Enable colorized output |
enable_exception_logging() | Enable logging of exceptions Once called, any uncaught exceptions will be emitted with level ERROR by this logger, before being raised. |
enable_warnings_logging() | Enable logging of warnings.warn() calls Once called, any subsequent calls to warnings.warn() are redirected to this logger and emitted with level WARN. |
exception_logging_enabled() | Determine if the exception-logging mechanism is enabled. |
log_to_file(*args, **kwds) | Context manager to temporarily log messages to a file. |
log_to_list(*args, **kwds) | Context manager to temporarily log messages to a list. |
makeRecord(name, level, pathname, lineno, ...) | |
setLevel(level) | Set the logging level of this logger. |
warnings_logging_enabled() |
Methods Documentation
Disable colorized output
Disable logging of exceptions
Once called, any uncaught exceptions will no longer be emitted by this logger.
This can be re-enabled with enable_exception_logging.
Disable logging of warnings.warn() calls
Once called, any subsequent calls to warnings.warn() are no longer redirected to this logger.
This can be re-enabled with enable_warnings_logging.
Enable colorized output
Enable logging of exceptions
Once called, any uncaught exceptions will be emitted with level ERROR by this logger, before being raised.
This can be disabled with disable_exception_logging.
Enable logging of warnings.warn() calls
Once called, any subsequent calls to warnings.warn() are redirected to this logger and emitted with level WARN. Note that this replaces the output from warnings.warn.
This can be disabled with disable_warnings_logging.
Determine if the exception-logging mechanism is enabled.
Returns: | exclog : bool
|
---|
Context manager to temporarily log messages to a file.
Parameters: | filename : str
filter_level : str
filter_origin : str
|
---|
Notes
By default, the logger already outputs log messages to a file set in the Astropy configuration file. Using this context manager does not stop log messages from being output to that file, nor does it stop log messages from being printed to standard output.
Examples
The context manager is used as:
with logger.log_to_file('myfile.log'):
# your code here
Context manager to temporarily log messages to a list.
Parameters: | filename : str
filter_level : str
filter_origin : str
|
---|
Notes
Using this context manager does not stop log messages from being output to standard output.
Examples
The context manager is used as:
with logger.log_to_list() as log_list:
# your code here
Set the logging level of this logger.