title: Writing to same log file with Pyramid and rq
body: <p>I am using Pyramid and <a href="http://python-rq.org/" rel="noreferrer">rq</a> and I would like to log rq worker jobs in the same file as my Pyramid application.</p>
  
  <p>My setup looks like this:</p>
  
  <p><strong>development.ini</strong></p>
  
  <pre><code># regular pyramid setup here...
  
  [loggers]
  keys = root, main
  
  [handlers]
  keys = console, debuglog
  
  [formatters]
  keys = generic
  
  [logger_root]
  level = DEBUG
  handlers = console, debuglog
  
  [logger_main]
  level = DEBUG
  handlers =
  qualname = main
  
  [handler_debuglog]
  class = handlers.RotatingFileHandler
  args = ('%(here)s/__logs/pyramid_debug.log','a')
  level = DEBUG
  formatter = generic
  
  [formatter_generic]
  format = %(asctime)s %(levelname)-8s [%(name)s][%(threadName)s] %(message)s
  </code></pre>
  
  <p><strong>main.py</strong></p>
  
  <pre><code>from bunch import Bunch
  from redis import Redis
  from rq import Queue, Worker
  from helpers.rqworker import run_worker
  from helpers.log import write_log
  
  write_log('info', 'APP STARTED.')
  q = Queue(connection=Redis())
  req_obj = Bunch()
  req_obj.remote_addr = self.request.remote_addr
  job = q.enqueue(run_worker, req_obj, {'some_other': 'data'})
  write_log('info', 'APP ENDED.')
  </code></pre>
  
  <p><strong>helpers/rqworker.py</strong></p>
  
  <pre><code>from helpers.log import write_log
  
  def run_worker(req, data):
      write_log(req, 'debug', 'WORKER STARTED', separator=True)
  </code></pre>
  
  <p><strong>helpers/log.py</strong></p>
  
  <pre><code>import logging
  log = logging.getLogger(__name__)
  
  
  def write_log(request, loglevel, message=None, **kwargs):
      msg = '[{0}] {1}'.format(request.remote_addr, message)
      level = logging.getLevelName(loglevel.upper())
  
      if 'separator' in kwargs:
          log.log(level, '='*40)
  
      if message:
          log.log(level, msg)
  
      if 'stack' in kwargs:
          log.log(level, '{0} EXCEPTION {0}'.format('*'*15))
          log.log(level, kwargs['stack'])
          log.log(level, '{0} EXCEPTION END {0}'.format('*'*13))
  </code></pre>
  
  <p>When I run my app, I cannot see logs from <code>rqworker.py</code> (probably because it is a separate thread) so I'm wondering how can I (and is it possible to) achieve writing to same log file?</p>