У меня очень простая структура.Но только один из моих двух обработчиков журналов регистрирует мои модули:
program.py, support_module1.py, support_module2.py
#program.py
import support_module1 as SM1
import support_module1 as SM2
log = logging.getLogger(__name__)
logging.basicConfig(
filename='/logs/TestLog.log',
filemode='w',
level='DEBUG',
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
handlers=[logging.FileHandler(r'/logs/TestLog.log')])
stdout_handler = logging.StreamHandler(sys.stdout)
stdout_handler.setLevel(logging.INFO)
log.addHandler(stdout_handler)
log.debug("shows in file")
log.info("shows in file and in stdout")
SM1.function1()
SM2.function2()
Модули
#support_module1.py
mod1_log = logging.getLogger(__name__)
function1():
mod1_log.debug("shows in file")
mod1_log.info("should show in file and in stdout, but only goes to file")
#support_module2.py
mod2_log = logging.getLogger(__name__)
function2():
mod2_log.debug("shows in file")
mod2_log.info("should show in file and in stdout, but only goes to file")
Когда я бегу, я получаю:
shows in file and in stdout
Я ожидаю:
shows in file and in stdout
should show in file and in stdout, but only goes to file
should show in file and in stdout, but only goes to file
Кто-нибудь скажет мне, что я делаю неправильно?