Skip to content

Configurable logging #686

@janosh

Description

@janosh

run_locally allows toggling a python std lib logger

log: bool = True,

whose settings are hard-coded in initialize_logger. would be great if run_locally accepted a list of custom handlers. we run DFT in containers on cloud infra and would like to send our logs to ElasticSearch which currently seems to require a lot of hackery

def initialize_logger(level: int = logging.INFO) -> logging.Logger:
"""Initialize the default logger.
Parameters
----------
level
The log level.
Returns
-------
Logger
A logging instance with customized formatter and handlers.
"""
import sys
log = logging.getLogger("jobflow")
log.setLevel(level)
log.handlers = [] # reset logging handlers if they already exist
fmt = logging.Formatter("%(asctime)s %(levelname)s %(message)s")
screen_handler = logging.StreamHandler(stream=sys.stdout)
screen_handler.setFormatter(fmt)
log.addHandler(screen_handler)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestuxUser experience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions