Logconfig

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)

Adds 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)

Adds a hostname field to the log record with the value of the node() function from the platform module.

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)

Converts 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)

Sets 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='9847d443b1b1.log', json=True, appname='')

Configures 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 (Optional[str], default: None) – Default log level (defaults to ‘DEBUG’).

  • logdir (Optional[str], default: None) – Path to the directory where the log file will be stored. If not provided, no FileHandler will be added.

  • logfile (str, default: '9847d443b1b1.log') – Name of the log file (defaults to ‘{node()}.log’).

  • json (bool, default: True) – Flag to enable or disable JSON format (defaults to True).

  • appname (str, default: '') – Application name to be filtered (defaults to “”).

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.