Skip to content

File handler

This page is auto-generated for HandlerType.File.

Spec

  • Handler type: File (file)
  • Handler class: FileHandler
  • Handler class FQDN: logging.FileHandler
  • Factory: _build_file_handler
  • Factory FQDN: daqpytools.logging.handlers._build_file_handler
  • Fallback types: file
  • Summary: Build a file handler.

Factory API

daqpytools.logging.handlers._build_file_handler(path=None, **_)

Build a file handler.

Parameters:

Name Type Description Default
path str | None

Path to the output log file. This is typically forwarded from get_daq_logger(..., file_handler_path=...) as path.

None
**_ object

Additional forwarded keyword arguments. Ignored by this factory.

{}

Returns:

Type Description
Handler

A configured logging.FileHandler.

Raises:

Type Description
ValueError

If path is not provided.

Source code in daqpytools/logging/handlers.py
def _build_file_handler(path: str | None = None, **_: object) -> logging.Handler:
    """Build a file handler.

    Args:
        path: Path to the output log file. This is typically forwarded from
            ``get_daq_logger(..., file_handler_path=...)`` as ``path``.
        **_: Additional forwarded keyword arguments. Ignored by this factory.

    Returns:
        A configured ``logging.FileHandler``.

    Raises:
        ValueError: If ``path`` is not provided.
    """
    if not path:
        err_msg = "path is required for file handler"
        raise ValueError(err_msg)
    handler = logging.FileHandler(filename=path)
    handler.setFormatter(LoggingFormatter())

    return handler