cement.ext.ext_logging
Cement logging extension module.
- class cement.ext.ext_logging.LoggingLogHandler(*args: Any, **kw: Any)[source]
Bases:
LogHandler
This class is an implementation of the Log interface, and sets up the logging facility using the standard Python logging module.
- class Meta[source]
Bases:
Meta
Handler meta-data.
- clear_loggers: List[str] = []
List of logger namespaces to clear. Useful when imported software also sets up logging and you end up with duplicate log entries.
Changes in Cement 2.1.3. Previous versions only supported clear_loggers as a boolean, but did fully support clearing non-app logging namespaces.
- config_defaults: Dict[str, Any] | None = {'file': None, 'level': 'INFO', 'max_bytes': 512000, 'max_files': 4, 'rotate': False, 'to_console': True}
The default configuration dictionary to populate the
log
section.
- console_format = '%(levelname)s: %(message)s'
The logging format for the consoler logger.
- debug_format = '%(asctime)s (%(levelname)s) %(namespace)s : %(message)s'
The logging format for both file and console if
debug==True
.
- file_format = '%(asctime)s (%(levelname)s) %(namespace)s : %(message)s'
The logging format for the file logger.
- log_level_argument: List[str] | None = None
List of arguments to use for the cli options (ex: [
-l
,--list
]). If a log-level argument is not wanted, set toNone
(default).
- log_level_argument_help = 'logging level'
The help description for the log level argument
- namespace: str = None
The logging namespace.
Note: Although Meta.namespace defaults to None, Cement will set this to the application label (App.Meta.label) if not set during setup.
- propagate = False
Whether or not to propagate logs up to parents. Likely should always be
False
, but is here in the off chance this breaks something. Setting toFalse
resolves situations where duplicate logs appear with other libraries who logged to the root logger.Note, if attempting to use PyTest
caplog
fixture, this may need to be set toTrue
.See:
tests.ext.test_ext_colorlog.test_colorlog
.
- _setup(app_obj: App) None [source]
Called during application initialization and must
setup
the handler object making it ready for the framework or the application to make further calls to it.- Parameters:
app (instance) – The application object.
- critical(msg: str, namespace: str | None = None, **kw: Any) None [source]
Log to the CRITICAL facility.
- error(msg: str, namespace: str | None = None, **kw: Any) None [source]
Log to the ERROR facility.
- Args:
msg (str): The message to log.
- Keyword Arguments:
namespace (str) – A log prefix, generally the module
__name__
that the log is coming from. Will default toself._meta.namespace
if none is passed.- Parameters:
kwargs – Keyword arguments are passed on to the backend logging system.
- fatal(msg: str, namespace: str | None = None, **kw: Any) None [source]
Log to the FATAL (aka CRITICAL) facility.
As of Cement 3.0.10, this method is deprecated and will be removed in future versions of Cement. Please us critical() instead.
- set_level(level: str) None [source]
Set the log level. Must be one of the log levels configured in self.levels which are
['INFO', 'WARNING', 'ERROR', 'DEBUG', 'FATAL', 'CRITICAL]
.As of Cement 3.0.10, the FATAL facility is deprecated and will be removed in future versions of Cement. Please us CRITICAL instead.
- Parameters:
level – The log level to set.