klay-music / klay-beam

Our Apache Beam Transforms and Pipelines
1 stars 0 forks source link

Instantiate logger with format #40

Open mxkrn opened 1 year ago

mxkrn commented 1 year ago

Implement these helper functions.

import logging

def init_logger(
    name: str = "klay_beam",  # or other package name
    level: int = logging.INFO,
    format: str = DEFAULT_LOG_FORMAT,
) -> logging.Logger:
    logger = logging.getLogger(name)
    logger.setLevel(level)

    if not logger.hasHandlers():
        formatter = logging.Formatter(format)
        streamHandler = logging.StreamHandler()
        streamHandler.setFormatter(formatter)
        logger.addHandler(streamHandler)

    return logger

def get_logger(name: str) -> logging.Logger:
    return logging.getLogger(name)

Logger instances can then be called in modules using: get_logger(__name__)

CharlesHolbrow commented 1 year ago

Sounds good. We just have to double check that there is a nice way to tell the GCP Dataflow runner to use a named logger.