Browse Source

Debuging logger for multicontext environment

Before we were calling the logging.getLogger function without argument. The result was
that all contexts were sharing the same logger (and every message were logged X time with
X the number of loaded context).
Now getLogger is called with the context id as argument, each context has its own logger.
Yann Weber 8 years ago
parent
commit
fc7c74660b
1 changed files with 4 additions and 3 deletions
  1. 4
    3
      lodel/logger.py

+ 4
- 3
lodel/logger.py View File

@@ -13,8 +13,9 @@ handlers = dict() # Handlers list (generated from settings)
13 13
 ##@brief Stores sent messages until module is able to be initialized
14 14
 msg_buffer = []
15 15
 
16
-# Fetching default root logger
17
-logger = logging.getLogger()
16
+# Fetching logger for current context
17
+from lodel.context import LodelContext
18
+logger = logging.getLogger(LodelContext.get_name())
18 19
 
19 20
 ##@brief Module initialisation from settings
20 21
 #@return True if inited else False
@@ -52,7 +53,7 @@ def __init_from_settings():
52 53
 # @param name str : The handler name
53 54
 # @param logging_opt dict : dict containing options ( see above )
54 55
 def add_handler(name, logging_opt):
55
-    logger = logging.getLogger()
56
+    logger = logging.getLogger(LodelContext.get_name())
56 57
     if name in handlers:
57 58
         raise KeyError("A handler named '%s' allready exists")
58 59
     

Loading…
Cancel
Save