Per-file loggers
The compliant logging provided by shrike works nicely with Python-style per-file loggers.
Given an entry script run.py:
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
from a import a_method
import logging
import sys
from shrike.compliant_logging import enable_compliant_logging, DataCategory
enable_compliant_logging()
log = logging.getLogger(__name__)
if __name__ == "__main__":
a_method()
log.info("hi from entry point", category=DataCategory.PUBLIC)
a_method()
from script a.py:
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import logging
import sys
from shrike.compliant_logging import DataCategory
def a_method():
log = logging.getLogger(__name__)
log.info("hi from a", category=DataCategory.PUBLIC)
SystemLog:INFO:a:hi from a
SystemLog:INFO:__main__:hi from entry point
To ensure that per-file loggers work properly, you must:
1. in the entry script, call log = logging.getLogger(__name__)
after enable_compliant_logging()
;
2. for methods you want to import, call log.logging.getLogger(__name__)
inside method definitions, e.g. (a.py)