Skip to content

Log

getLogger()

Returns an logger depending on the environment: - Testing: returns a logger from the logging package - Prefect Flow: returns the logger from the prefect flow run context - Prefect error callback: there might not be a logger available, falls back to a logger from logging package

Source code in backend/archiver/utils/log.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def getLogger():
    """
    Returns an logger depending on the environment:
    - Testing: returns a logger from the logging package
    - Prefect Flow: returns the logger from the prefect flow run context
    - Prefect error callback: there might not be a logger available, falls back to
        a logger from logging package
    """
    if "PYTEST_CURRENT_TEST" in os.environ:
        return logging.getLogger(name="TestLogger")
    else:
        try:
            prefect_logger = prefect.get_run_logger()
            return prefect_logger
        except MissingContextError:
            return logging.getLogger(name="FallbackLogger")
        except Exception:
            return logging.getLogger(name="FallbackLogger")