In my app.py module I set up a logger with console and file handlers like this:
import logging
logger = logging.getLogger('app')
logger.setLevel(logging.DEBUG)
console_handler = logging.StreamHandler()
file_handler = logging.FileHandler('gsam_log.txt')
console_handler.setLevel(logging.INFO)
file_handler.setLevel(logging.INFO)
c_formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
f_formatter = logging.Formatter('%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
console_handler.setFormatter(c_formatter)
file_handler.setFormatter(f_formatter)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
If I work in Python Console and I do: from app import logger it works as expected - printing both to console and the file. I would like to use this logger to log from my xlwings subs (decorated with @xw.sub). But for some reason the logs are only sent to console and not to the file. Below is the code from test.py module, which I import as UDF module via xlwings.
from app import logger
import xlwings as xw
@xw.sub
def test():
logger.debug('test')
logger.info('test')
logger.warning('test')
from why xlwings suppresses logging to a file
No comments:
Post a Comment