Source code for server.web.logging
"""Logging configuration for jobmon server applications.
This module provides the standard logging configuration used by
server startup and API initialization.
The module supports both legacy dict-based configs and new template-based
configurations. Server logs are automatically captured by OTLP when
enabled (handled by the server configuration overrides).
"""
from __future__ import annotations
import os
import sys
from typing import Dict
# Legacy default configuration - used as fallback only
[docs]
_DEFAULT_LOG_FORMAT = (
"%(asctime)s [%(name)-12s] %(module)s %(levelname)-8s: %(message)s"
)
[docs]
default_config: Dict = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"default": {"format": _DEFAULT_LOG_FORMAT, "datefmt": "%Y-%m-%d %H:%M:%S"}
},
"handlers": {
"default": {
"level": "INFO",
"class": "logging.StreamHandler",
"formatter": "default",
"stream": sys.stdout,
}
},
}
# Module-level flag to prevent duplicate configuration
[docs]
def configure_server_logging() -> None:
"""Configure server logging with template and user override support.
This is the primary interface for configuring server logging. It supports:
1. Default template-based configuration
2. User file overrides via logging.server_logconfig_file
3. User section overrides via logging.server.*
4. Environment variable overrides
Configuration precedence:
1. Custom file (logging.server_logconfig_file)
2. Section overrides (logging.server.formatters/handlers/loggers)
3. Default template (logconfig_server.yaml)
4. Basic fallback configuration
Note: Server OTLP is handled separately by the server OTLP manager.
"""
global _server_logging_configured
# Prevent duplicate configuration in multi-worker environments
if _server_logging_configured:
return
from jobmon.core.config.logconfig_utils import configure_logging_with_overrides
# Get default template path
current_dir = os.path.dirname(__file__)
default_template_path = os.path.join(current_dir, "config/logconfig_server.yaml")
# Configure Python stdlib logging with override support
configure_logging_with_overrides(
default_template_path=default_template_path,
config_section="server",
fallback_config=default_config,
)
# Configure structlog to integrate with stdlib loggers
# This must come AFTER stdlib logging is configured
from jobmon.core.config.structlog_config import configure_structlog
configure_structlog(component_name="server")
_server_logging_configured = True