Logging with fabric and python -
how use python logging
module fabric?
i've set tests in fabfile.py
, configured logger, etc, because it's using local()
execute, guess logging never gets set in tests or function module calls.
here's example of fabfile.py
:
from fabric.api import local import logging import module def unittest(name='all'): logger = logging.getlogger(__name__) logger.setlevel(logging.info) fh = logging.filehandler('logs/unittest.log') formatter = logging.formatter('%(asctime)s - %(name)s - %(levelname)s - ' + '%(message)s') fh.setformatter(formatter) logger.addhandler(fh) logger.info('unittest started.') local('py.test module')
and in module, module.py
import pytest import logging def test_main(): logger = getlogger(__name__) logger.info('function started.')
the log filled message fabfile.py
nothing module.py
your module.py has error on line:
logger = getlogger(__name__)
it should be:
logger = logging.getlogger(__name__)
after you're right: logger in module.py independent 1 in fabfile. if set logger test case inside pytest session ok.
Comments
Post a Comment