Here is an example using app with “Schedule”

This is using the Schedule Python module

Docs for Schedule Module – has own logger

Solution – is just to add the same handler instance to the 2nd logger.

logger = logging.getLogger('weather_obs_f')
ch = logging.StreamHandler(stream=sys.stdout)
ch_format = logging.Formatter('weather_obs - %(message)s'
ch.setFormatter(ch_format)
ch.setLevel(logging.INFO)
pid = os.getpid()
fhandler = TimedRotatingFileHandler('weather_obs.' + str(pid) + '.log',
                                     when="d",
                                     interval=1,
                                     backupCount=5)
formatter_f = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fhandler.setFormatter(formatter_f)                          
fhandler.setLevel(logging.DEBUG)
logger.addHandler(fhandler)
logger.addHandler(ch)
logger.addHandler(logging.NullHandler())
# also put the schedule logger to file
schedule_logger = logging.getLogger('schedule')
schedule_logger.setLevel(level=logging.DEBUG)
schedule_logger.addHandler(fhandler)

 

Leave a Reply