I have a python module and I want to set a logger to be available through the package.
- I initiate the logger in the
__init__.py
- run the code with
python -m
- call a function in another file which needs logger from
__init__.py
then I ger this error
name 'logger' is not defined
__init__.py
:
import logging
logging.basicConfig(format='%(msg)s')
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
from .code import log
log()
code.py
:
def log():
logger.debug('test')