I have a Flask application with Redis worker (worker.py) running in the background. There is a separate module (selenium.py) that just runs Selenium to do some tasks. This module gets queued via Redis in order to perform jobs. I'm trying to log all processes into one file. However, Redis prints all logs from (selenium.py) into the console instead of putting them into the log file that I have designated.
The log configuration is in the main Flask file (app.py):
import logging
from logging.handlers import RotatingFileHandler
import logging.config
from rq import Queue
from rq.job import Job
from worker import conn
logging.config.fileConfig('logging.conf')
logger = logging.getLogger('app')
logger.warning('Started app.py!')
worker.py:
import os
import redis
from rq import Worker, Queue, Connection
listen = ['default']
redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')
conn = redis.from_url(redis_url)
if __name__ == '__main__':
with Connection(conn):
worker = Worker(list(map(Queue, listen)))
worker.work()
selenium.py
import logging
logger = logging.getLogger('app')
logger.info('Selenium ran successfully!')
...Selenium Code Here...
logging.conf
[loggers]
keys=root
[handlers]
keys=logfile
[formatters]
keys=logfileformatter
[logger_root]
level=INFO
handlers=logfile
[handler_logfile]
class=handlers.RotatingFileHandler
level=NOTSET
args=('logs/my_log.log','a',100000,50)
formatter=logfileformatter
[formatter_logfileformatter]
format=%(asctime)s %(name)-12s: %(levelname)s %(message)s
Console Output (for worker.py):
Selenium ran successfully!
Log Output:
Started app.py!
Expected Log Output (what I want):
Started app.py!
Selenium ran successfully!
So given Flask and Redis. How do I combine my logs into one output file with Python's logging system?