Logconfig
Utility functions for configuring logging.
- class vibe_core.logconfig.AppFilter(app)
Bases:
Filter
Filter class to add app field to the log record.
- Parameters:
app (str) – The name of the application.
- filter(record)
Add an app field to the log record with the value of the app attribute.
- Parameters:
record (LogRecord) – The log record to be filtered.
- Returns:
True.
- class vibe_core.logconfig.HostnameFilter(name='')
Bases:
Filter
Filter class to add hostname field to the log record.
- filter(record)
Add a hostname field to the log record with the value of the node() from the platform.
- Parameters:
record (LogRecord) – The log record to be filtered.
- Returns:
True.
- class vibe_core.logconfig.JsonMessageFilter(name='')
Bases:
Filter
Log filter to convert messages to JSON.
- filter(record)
Convert the message of the log record to JSON.
- Parameters:
record (LogRecord) – The log record to be filtered.
- Returns:
True.
- vibe_core.logconfig.change_logger_level(loggername, level)
Set the default log level for a logger.
- Parameters:
loggername (str) – The name of the logger for which to set the log level.
level (str) – The desired log level (e.g. INFO, DEBUG, WARNING).
- vibe_core.logconfig.configure_logging(default_level=None, logdir=None, max_log_file_bytes=None, log_backup_count=None, logfile='7a1fc3ac09e4.log', json=True, appname='')
Configure logging for the calling process.
This method will create a logger and set its level to the given default_level argument. It will also create a StreamHandler and FileHandler if the logdir argument is provided, with the respective logfile name. It will add filters for the application name, hostname and json message, and set the formatter to JSON_FORMAT if json is True, or LOG_FORMAT otherwise.
- Parameters:
default_level (str | None) – Default log level.
logdir (str | None) – Path to the directory where the log file will be stored. If not provided, no FileHandler will be added.
max_log_file_bytes (int | None) – Maximum size of the log file in bytes.
log_backup_count (int | None) – Number of log files to keep.
logfile (str) – Name of the log file.
json (bool) – Flag to enable or disable JSON format.
appname (str) – Application name to be filtered.
- vibe_core.logconfig.DEFAULT_LOGGER_LEVELS: Dict[str, str] = {'aiohttp_retry': 'INFO', 'azure': 'WARNING', 'fiona': 'INFO', 'gdal': 'INFO', 'matplotlib': 'INFO', 'rasterio': 'INFO', 'urllib3': 'INFO', 'urllib3.connectionpool': 'DEBUG', 'uvicorn': 'WARNING', 'werkzeug': 'INFO'}
The default log levels for the different loggers.
- vibe_core.logconfig.JSON_FORMAT = '{"app_id": "%(app)s", "instance": "%(hostname)s", "level": "%(levelname)s", "msg": %(json_message)s, "scope": "%(name)s", "time": "%(asctime)s", "type": "log", "ver": "dev"}'
JSON log format.
- vibe_core.logconfig.LOG_FORMAT = '[%(asctime)s] [%(hostname)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s'
The default log format.