Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic (i.e. Runtime Configurable) Log Configuration for Django + Celery based application
    primarykey
    data
    text
    <p>We have a need to customize the log levels on the server at runtime. We are building a SAAS application using Django, and we have to be able to enable logging per tenant eventually. I am trying to find the best way of doing it. </p> <p>As a first step, I created a way to dynamically change log levels (for the whole application). I see there are no examples of doing it. I am note sure if one one tried something like this so far, and what are the pitfalls I should be watching out for.</p> <p>Here is my code so far. Appreciate if anyone can shed light on specific pitfalls I am going to run into. Also appreciate any input on how to control logging per tenant and module, short of creating logger per tenant per module: </p> <pre><code>import threading import logging.config import time import os import traceback class LogConfigWatcher(threading.Thread): def __init__(self, storage, location): self.last_known_time = None self.storage = storage self.location = location threading.Thread.__init__(self) def run(self): while True: mod_time = os.path.getmtime(self.location) if(mod_time != self.last_known_time): try: with file(self.location) as f: print("Configuring logging . . .") config = eval(f.read()) logging.config.dictConfig(config['handler_config']) logging.config.dictConfig(config['logger_config']) self.last_known_time = mod_time except: traceback.print_exc() print "Failed to Configure the log" pass time.sleep(5) class LogConfigHolder(object): def __init__(self, storage, location): self.storage = storage self.location = location self.initialize(storage, location) def initialize(self, storage, location): self.pid = os.getpid() print "Starting thread for %s" % self.pid self.thread = LogConfigWatcher(storage, location) self.thread.setDaemon(True) self.thread.start() def is_alive(self): if os.getpid() != self.pid: return False return self.thread.isAlive() def restart(self): if not self.is_alive(): self.initialize(self.storage, self.location) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload