9.2. Logging¶
9.2.1. Configuration example¶
With this option one can set the verbosity of the logging. By default all the logs on info level will be logged to standard error. On Safeguard for privileged sessions, the standard error will be forwarded to the system logs.
Possible log levels are the following:
debug
info
warning
error
critical
[logging]
# One of 'debug', 'info', 'warning', 'error', 'critical'
log_level = info
9.2.2. Configuring the logger service¶
from safeguard.sessions.plugin import logging
from safeguard.sessions.plugin import PluginConfiguration
class Plugin:
def __init__(self, configuration):
self._plugin_config = PluginConfiguration(configuration)
logging.configure(self._plugin_config)
9.2.3. Acquiring a logger¶
from safeguard.sessions.plugin.logging import get_logger
class Plugin:
def __init__(self, configuration):
self._log = get_logger(__name__)
9.2.4. Usage example¶
from safeguard.sessions.plugin import logging
from safeguard.sessions.plugin import PluginConfiguration
class Plugin:
def __init__(self, configuration):
self._plugin_config = PluginConfiguration(configuration)
logging.configure(self._plugin_config)
self._log = logging.get_logger(__name__)
def do_some_logging(self):
self._log.debug('This is a debug level log')
self._log.info('This is an info level log')
self._log.warning('This is a warning level log')
self._log.error('This is an error level log')
self._log.critical('This is a critical level log')
-
safeguard.sessions.plugin.logging.
get_logger
(name=None)¶ The
get_logger()
method acquires a Python Logger object of the given name.- Parameters
name (str) – name of the logger
- Returns
logger with specific name
- Return type
logger.RootLogger or logger.Logger
-
safeguard.sessions.plugin.logging.
configure
(configuration, log_level=None)¶ The
configure()
method sets the log level of root logger from the given plugin configuration.- Parameters
configuration (
safeguard.sessions.plugin.pluginconfig.PluginConfig
) – Configuration containing the desired log levellog_level (str) – log level to set on the root logger
- Returns
None
- Return type
NoneType
- Raises