Skip to content

conf

log_panel.conf

reset_backend_cache()

Reset the cached backend instance — use in tests and after settings changes.

Source code in log_panel/conf.py
def reset_backend_cache() -> None:
    """Reset the cached backend instance — use in tests and after settings changes."""
    global _backend_cache
    _backend_cache = _UNSET

get_user_config()

Return the user configuration dict from Django settings, or an empty dict.

Source code in log_panel/conf.py
def get_user_config() -> dict[str, Any]:
    """Return the user configuration dict from Django settings, or an empty dict."""
    return getattr(settings, "LOG_PANEL", {})

get_setting(key)

Return a value from LOG_PANEL in Django settings, falling back to DEFAULTS.

Source code in log_panel/conf.py
def get_setting(key: str) -> Any:
    """Return a value from LOG_PANEL in Django settings, falling back to DEFAULTS."""
    user_config: dict[str, Any] = get_user_config()
    return user_config.get(key, DEFAULTS[key])

get_thresholds()

Return per-level alert thresholds, merging user config with defaults.

Source code in log_panel/conf.py
def get_thresholds() -> dict[str, int | None]:
    """Return per-level alert thresholds, merging user config with defaults."""
    user_config: dict[str, Any] = get_user_config()
    user_thresholds: dict[str, int | None] = user_config.get("THRESHOLDS", {})
    return {**DEFAULTS["THRESHOLDS"], **user_thresholds}

get_ignored_logger_prefixes()

Return namespace logger prefixes skipped by the database handler.

Source code in log_panel/conf.py
def get_ignored_logger_prefixes() -> tuple[str, ...]:
    """Return namespace logger prefixes skipped by the database handler."""
    user_config: dict[str, Any] = get_user_config()
    user_prefixes: tuple[str, ...] = tuple(
        user_config.get("IGNORED_LOGGER_PREFIXES", ())
    )
    return tuple(dict.fromkeys((*DEFAULTS["IGNORED_LOGGER_PREFIXES"], *user_prefixes)))

get_ignored_logger_names()

Return exact logger names skipped by the database handler.

Source code in log_panel/conf.py
def get_ignored_logger_names() -> tuple[str, ...]:
    """Return exact logger names skipped by the database handler."""
    return tuple(get_setting(key="IGNORED_LOGGER_NAMES"))

get_ignored_message_substrings()

Return message substrings skipped by the database handler.

Source code in log_panel/conf.py
def get_ignored_message_substrings() -> tuple[str, ...]:
    """Return message substrings skipped by the database handler."""
    return tuple(get_setting(key="IGNORED_MESSAGE_SUBSTRINGS"))

get_ranges()

Return timeline range settings normalised into typed configs.

Source code in log_panel/conf.py
def get_ranges() -> dict[str, RangeConfig]:
    """Return timeline range settings normalised into typed configs."""
    raw_ranges: dict[str, RangeConfig | dict[str, Any]] = get_setting(key="RANGES")
    return {key: RangeConfig.from_value(value) for key, value in raw_ranges.items()}

get_database_alias()

Return the database alias to use for log storage, or None if not configured.

Source code in log_panel/conf.py
def get_database_alias() -> str | None:
    """Return the database alias to use for log storage, or None if not configured."""
    return get_setting(key="DATABASE_ALIAS")

get_backend()

Instantiate and return the configured backend, or None if not configured.

The result is cached for the lifetime of the process so that the underlying connection pool is reused across requests.

Resolution order: 1. LOG_PANEL['BACKEND'] dotted class path (explicit override). 2. OrmBackend if LOG_PANEL['DATABASE_ALIAS'] is set. 3. None — admin will show an unconfigured state.

Returns:

Type Description

A LogsBackend instance, or None.

Source code in log_panel/conf.py
def get_backend():
    """
    Instantiate and return the configured backend, or None if not configured.

    The result is cached for the lifetime of the process so that the underlying
    connection pool is reused across requests.

    Resolution order:
    1. LOG_PANEL['BACKEND'] dotted class path (explicit override).
    2. OrmBackend if LOG_PANEL['DATABASE_ALIAS'] is set.
    3. None — admin will show an unconfigured state.

    Returns:
        A LogsBackend instance, or None.
    """
    global _backend_cache
    if _backend_cache is not _UNSET:
        return _backend_cache

    from log_panel.backends.base import LogsBackend

    explicit: str | None = get_setting(key="BACKEND")
    if explicit:
        from importlib import import_module

        module_path, class_name = explicit.rsplit(".", 1)
        module: ModuleType = import_module(name=module_path)
        cls: Any = getattr(module, class_name)

        backend: LogsBackend = cls()
        _backend_cache = backend
        return _backend_cache

    if get_database_alias():
        from log_panel.backends.sql import OrmBackend

        _backend_cache = OrmBackend()
        return _backend_cache

    _backend_cache = None
    return None

get_buffer_size()

Return the buffer size for BufferedDatabaseHandler, or None if buffering is disabled.

Source code in log_panel/conf.py
def get_buffer_size() -> int | None:
    """Return the buffer size for BufferedDatabaseHandler, or None if buffering is disabled."""
    return get_setting(key="BUFFER_SIZE")

get_buffer_flush_interval()

Return the timer interval in seconds between periodic buffer flushes.

Source code in log_panel/conf.py
def get_buffer_flush_interval() -> float:
    """Return the timer interval in seconds between periodic buffer flushes."""
    return float(get_setting(key="BUFFER_FLUSH_INTERVAL"))

get_buffer_flush_level()

Return the log level name that triggers an immediate buffer flush.

Source code in log_panel/conf.py
def get_buffer_flush_level() -> str:
    """Return the log level name that triggers an immediate buffer flush."""
    return get_setting(key="BUFFER_FLUSH_LEVEL")

get_level_colors()

Return the level color map used for both CSS generation and the filter dropdown.

Merges user-configured LOG_PANEL['LEVEL_COLORS'] with defaults, so only overridden or added levels need to be specified.

Source code in log_panel/conf.py
def get_level_colors() -> dict[str, str]:
    """
    Return the level color map used for both CSS generation and the filter dropdown.

    Merges user-configured ``LOG_PANEL['LEVEL_COLORS']`` with defaults, so only
    overridden or added levels need to be specified.
    """
    user_config: dict[str, Any] = getattr(settings, "LOG_PANEL", {})
    user_colors: dict[str, str] = user_config.get("LEVEL_COLORS", {})
    return {**DEFAULTS["LEVEL_COLORS"], **user_colors}

get_permission_callback()

Return the configured permission callable, or None.

The setting must be a dotted path to a callable (request: HttpRequest) -> bool. When not configured, the panel falls back to allowing any active staff user.

Raises:

Type Description
ImproperlyConfigured

if the dotted path is set but cannot be imported.

Source code in log_panel/conf.py
def get_permission_callback():
    """
    Return the configured permission callable, or None.

    The setting must be a dotted path to a callable ``(request: HttpRequest) -> bool``.
    When not configured, the panel falls back to allowing any active staff user.

    Raises:
        ImproperlyConfigured: if the dotted path is set but cannot be imported.
    """
    from django.core.exceptions import ImproperlyConfigured

    dotted: str | None = get_setting(key="PERMISSION_CALLBACK")
    if not dotted:
        return None
    try:
        from importlib import import_module

        module_path, func_name = dotted.rsplit(".", 1)
        module: ModuleType = import_module(name=module_path)
        return getattr(module, func_name)
    except (ImportError, AttributeError, ValueError) as exc:
        raise ImproperlyConfigured(
            f"LOG_PANEL['PERMISSION_CALLBACK'] = {dotted!r} could not be imported: {exc}"
        ) from exc