Logger
Module for logging configuration.
- class AuditFilter(name='')[source]
Filter to separate audit logs from regular 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.
- class AuditFormatter(fmt=None, datefmt=None)[source]
Custom formatter that handles user-specific logging configuration.
Initialize the formatter with config.
- Parameters:
- _get_extra_fields(record)[source]
Extract additional fields from the record.
- _get_syslog_priority(levelno)[source]
Convert Python logging levels to syslog priorities.
- format(record)[source]
Format the record as JSON for journald consumption.
- Return type:
- Parameters:
record (logging.LogRecord) – The log record to format
- Returns:
JSON formatted log message
- Return type:
- DEFAULT_DATE_FORMATTER: str = '%m/%d/%Y %I:%M:%S %p'
Default date formatter string for systemd/terminal
- DEFAULT_FORMATTER: str = '[%(asctime)s] [%(filename)s:%(lineno)d] %(levelname)s: %(message)s'
Default formatter string for systemd/terminal
- EXTRAS_TO_SKIP = ('args', 'asctime', 'created', 'exc_info', 'exc_text', 'filename', 'funcName', 'levelname', 'levelno', 'lineno', 'taskName', 'module', 'server', 'thread', 'process', 'processName', 'msecs', 'msg', 'name', 'pathname', 'relativeCreated', 'stack_info', 'threadName', 'audit', 'user_id')
Set of keys to skip during auditting. If any of those needs to be in the audit log, simply remove them from this list.
- LOGGING_CONFIG_DICTIONARY = {'disable_existing_loggers': False, 'filters': {'audit_only': {'()': 'command_line_assistant.logger.AuditFilter'}, 'non_audit_only': {'()': 'command_line_assistant.logger.NonAuditFilter'}}, 'formatters': {'audit': {'()': 'command_line_assistant.logger.AuditFormatter', 'datefmt': '%m/%d/%Y %I:%M:%S %p', 'format': '[%(asctime)s] [%(filename)s:%(lineno)d] %(levelname)s: %(message)s'}, 'systemd': {'datefmt': '%m/%d/%Y %I:%M:%S %p', 'format': '[%(asctime)s] [%(filename)s:%(lineno)d] %(levelname)s: %(message)s'}, 'terminal': {'datefmt': '%m/%d/%Y %I:%M:%S %p', 'format': '\x1f[%(asctime)s] [%(filename)s:%(lineno)d] %(levelname)s: %(message)s'}}, 'handlers': {'audit': {'class': 'logging.StreamHandler', 'filters': ['audit_only'], 'formatter': 'audit', 'stream': 'ext://sys.stdout'}, 'systemd': {'class': 'logging.StreamHandler', 'filters': ['non_audit_only'], 'formatter': 'systemd', 'stream': 'ext://sys.stdout'}, 'terminal': {'class': 'logging.StreamHandler', 'filters': ['non_audit_only'], 'formatter': 'terminal', 'stream': 'ext://sys.stdout'}}, 'level': 'INFO', 'loggers': {'root': {'handlers': [], 'level': 'INFO'}}, 'version': 1}
Define the dictionary configuration for the logger instance
- class NonAuditFilter(name='')[source]
Filter to separate regular logs from audit 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.
- _setup_logging(logging_level, handlers)[source]
Internal method to handle logging configuration and initialization.
- setup_client_logging()[source]
Setup basic logging functionality.
- Return type:
Note
This is intended to be called by the client to initialize their logging routine.