annotate src/core/log_config.py @ 1116:ee450d7c88a7

core (logging): logging is added to stdout in nodaemon mode (it was already the case in debug mode)
author Goffi <goffi@goffi.org>
date Thu, 21 Aug 2014 02:14:24 +0200
parents a836b6da2c5c
children 64ff259d3cbb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
991
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SàT: a XMPP client
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """High level logging functions"""
1005
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
21 # XXX: this module use standard logging module when possible, but as SàT can work in different cases where logging is not the best choice (twisted, pyjamas, etc), it is necessary to have a dedicated module. Additional feature like environment variables and colors are also managed.
991
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
22
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.constants import Const as C
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
24 from sat.core import log
991
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
26
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
27 class TwistedLogger(log.Logger):
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
28 colors = True
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
29 force_colors = False
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
30
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
31 def __init__(self, *args, **kwargs):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
32 super(TwistedLogger, self).__init__(*args, **kwargs)
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
33 from twisted.python import log as twisted_log
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
34 self.twisted_log = twisted_log
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
35
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
36 def out(self, message, level=None):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
37 """Actually log the message
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
38
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
39 @param message: formatted message
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
40 """
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
41 self.twisted_log.msg(message.encode('utf-8', 'ignore'), sat_logged=True, level=level)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
42
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
43
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
44 class ConfigureBasic(log.ConfigureBase):
1005
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
45
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
46 def configureColors(self, colors, force_colors):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
47 if colors:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
48 import sys
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
49 if force_colors or sys.stdout.isatty(): # FIXME: isatty should be tested on each handler, not globaly
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
50 # we need colors
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
51 log.Logger.post_treat = lambda self, level, message: self.ansiColors(level, message)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
52 elif force_colors:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
53 raise ValueError("force_colors can't be used if colors is False")
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
54
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
55 @staticmethod
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
56 def getProfile():
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
57 """Try to find profile value using introspection"""
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
58 import inspect
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
59 stack = inspect.stack()
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
60 current_path = stack[0][1]
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
61 for frame_data in stack[:-1]:
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
62 if frame_data[1] != current_path:
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
63 if log.backend == C.LOG_BACKEND_STANDARD and "/logging/__init__.py" in frame_data[1]:
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
64 continue
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
65 break
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
66
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
67 frame = frame_data[0]
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
68 args = inspect.getargvalues(frame)
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
69 try:
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
70 profile = args.locals.get('profile') or args.locals['profile_key']
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
71 except (TypeError, KeyError):
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
72 try:
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
73 try:
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
74 profile = args.locals['self'].profile
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
75 except AttributeError:
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
76 try:
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
77 profile = args.locals['self'].parent.profile
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
78 except AttributeError:
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
79 profile = args.locals['self'].host.profile # used in quick_frontend for single profile configuration
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
80 except Exception:
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
81 # we can't find profile, we return an empty value
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
82 profile = ''
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
83 return profile
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
84
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
85
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
86 class ConfigureTwisted(ConfigureBasic):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
87 LOGGER_CLASS = TwistedLogger
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
88
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
89 def changeObserver(self, observer, can_colors=False):
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
90 """Install a hook on observer to manage SàT specificities
1005
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
91
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
92 @param observer: original observer to hook
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
93 @param can_colors: True if observer can display ansi colors
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
94 """
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
95 def observer_hook(event):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
96 """redirect non SàT log to twisted_logger, and add colors when possible"""
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
97 if 'sat_logged' in event: # we only want our own logs, other are managed by twistedObserver
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
98 # we add colors if possible
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
99 if (can_colors and self.LOGGER_CLASS.colors) or self.LOGGER_CLASS.force_colors:
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
100 message = event.get('message', tuple())
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
101 level = event.get('level', C.LOG_LVL_INFO)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
102 if message:
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
103 event['message'] = (self.ansiColors(level, ''.join(message)),) # must be a tuple
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
104 observer(event) # we can now call the original observer
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
105
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
106 return observer_hook
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
107
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
108 def changeFileLogObserver(self, observer):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
109 """Install SàT hook for FileLogObserver
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
110
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
111 if the output is a tty, we allow colors, else we don't
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
112 @param observer: original observer to hook
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
113 """
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
114 log_obs = observer.__self__
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
115 log_file = log_obs.write.__self__
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
116 try:
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
117 can_colors = log_file.isatty()
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
118 except AttributeError:
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
119 can_colors = False
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
120 return self.changeObserver(observer, can_colors=can_colors)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
121
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
122 def installObserverHook(self, observer):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
123 """Check observer type and install SàT hook when possible
991
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
124
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
125 @param observer: observer to hook
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
126 @return: hooked observer or original one
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
127 """
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
128 if hasattr(observer, '__self__'):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
129 ori = observer
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
130 if isinstance(observer.__self__, self.twisted_log.FileLogObserver):
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
131 observer = self.changeFileLogObserver(observer)
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
132 elif isinstance(observer.__self__, self.twisted_log.DefaultObserver):
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
133 observer = self.changeObserver(observer, can_colors=True)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
134 else:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
135 # we use print because log system is not fully initialized
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
136 print("Unmanaged observer [%s]" % observer)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
137 return observer
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
138 self.observers[ori] = observer
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
139 return observer
991
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
140
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
141 def preTreatment(self):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
142 """initialise needed attributes, and install observers hooks"""
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
143 self.observers = {}
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
144 from twisted.python import log as twisted_log
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
145 self.twisted_log = twisted_log
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
146 self.log_publisher = twisted_log.msg.__self__
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
147 def addObserverObserver(self_logpub, other):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
148 """Install hook so we know when a new observer is added"""
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
149 other = self.installObserverHook(other)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
150 return self_logpub._originalAddObserver(other)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
151 def removeObserverObserver(self_logpub, ori):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
152 """removeObserver hook fix
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
153
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
154 As we wrap the original observer, the original removeObserver may want to remove the original object instead of the wrapper, this method fix this
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
155 """
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
156 if ori in self.observers:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
157 self_logpub._originalRemoveObserver(self.observers[ori])
1005
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
158 else:
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
159 try:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
160 self_logpub._originalRemoveObserver(ori)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
161 except ValueError:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
162 try:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
163 ori in self.cleared_observers
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
164 except AttributeError:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
165 raise ValueError("Unknown observer")
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
166
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
167 # we replace addObserver/removeObserver by our own
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
168 twisted_log.LogPublisher._originalAddObserver = twisted_log.LogPublisher.addObserver
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
169 twisted_log.LogPublisher._originalRemoveObserver = twisted_log.LogPublisher.removeObserver
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
170 import types # see https://stackoverflow.com/a/4267590 (thx Chris Morgan/aaronasterling)
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
171 twisted_log.addObserver = types.MethodType(addObserverObserver, self.log_publisher, twisted_log.LogPublisher)
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
172 twisted_log.removeObserver = types.MethodType(removeObserverObserver, self.log_publisher, twisted_log.LogPublisher)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
173
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
174 # we now change existing observers
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
175 for idx, observer in enumerate(self.log_publisher.observers):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
176 self.log_publisher.observers[idx] = self.installObserverHook(observer)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
177
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
178 def configureLevel(self, level):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
179 self.LOGGER_CLASS.level = level
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
180 super(ConfigureTwisted, self).configureLevel(level)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
181
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
182 def configureOutput(self, output):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
183 import sys
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
184 if output is None:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
185 output = C.LOG_OPT_OUTPUT_SEP + C.LOG_OPT_OUTPUT_DEFAULT
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
186 self.manageOutputs(output)
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
187 addObserver = self.twisted_log.addObserver
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
188
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
189 if C.LOG_OPT_OUTPUT_DEFAULT in log.handlers:
1116
ee450d7c88a7 core (logging): logging is added to stdout in nodaemon mode (it was already the case in debug mode)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
190 # default output is already managed, we just add output to stdout if we are in debug or nodaemon mode
ee450d7c88a7 core (logging): logging is added to stdout in nodaemon mode (it was already the case in debug mode)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
191
ee450d7c88a7 core (logging): logging is added to stdout in nodaemon mode (it was already the case in debug mode)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
192 # XXX: this hack is to know if we are in debug or nodaemon mode
ee450d7c88a7 core (logging): logging is added to stdout in nodaemon mode (it was already the case in debug mode)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
193 # any better method welcomed
ee450d7c88a7 core (logging): logging is added to stdout in nodaemon mode (it was already the case in debug mode)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
194 from twisted.scripts import twistd
ee450d7c88a7 core (logging): logging is added to stdout in nodaemon mode (it was already the case in debug mode)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
195 options = twistd.ServerOptions()
ee450d7c88a7 core (logging): logging is added to stdout in nodaemon mode (it was already the case in debug mode)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
196 options.parseOptions()
ee450d7c88a7 core (logging): logging is added to stdout in nodaemon mode (it was already the case in debug mode)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
197 if options.get('nodaemon', False) or options.get('debug', False):
ee450d7c88a7 core (logging): logging is added to stdout in nodaemon mode (it was already the case in debug mode)
Goffi <goffi@goffi.org>
parents: 1021
diff changeset
198 addObserver(self.twisted_log.FileLogObserver(sys.stdout).emit)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
199 else:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
200 # \\default is not in the output, so we remove current observers
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
201 self.cleared_observers = self.log_publisher.observers
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
202 self.observers.clear()
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
203 del self.log_publisher.observers[:]
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
204 # and we forbid twistd to add any observer
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
205 self.twisted_log.addObserver = lambda other: None
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
206
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
207 if C.LOG_OPT_OUTPUT_FILE in log.handlers:
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
208 from twisted.python import logfile
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
209 for path in log.handlers[C.LOG_OPT_OUTPUT_FILE]:
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
210 log_file = sys.stdout if path == '-' else logfile.LogFile.fromFullPath(path)
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
211 addObserver(self.twisted_log.FileLogObserver(log_file).emit)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
212
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
213 if C.LOG_OPT_OUTPUT_MEMORY in log.handlers:
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
214 raise NotImplementedError("Memory observer is not implemented in Twisted backend")
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
215
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
216 def configureColors(self, colors, force_colors):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
217 self.LOGGER_CLASS.colors = colors
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
218 self.LOGGER_CLASS.force_colors = force_colors
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
219 if force_colors and not colors:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
220 raise ValueError('colors must be True if force_colors is True')
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
221
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
222 def postTreatment(self):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
223 """Install twistedObserver which manage non SàT logs"""
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
224 def twistedObserver(event):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
225 """Observer which redirect log message not produced by SàT to SàT logging system"""
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
226 if not 'sat_logged' in event:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
227 # this log was not produced by SàT
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
228 from twisted.python import log as twisted_log
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
229 text = twisted_log.textFromEventDict(event)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
230 if text is None:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
231 return
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
232 twisted_logger = log.getLogger(C.LOG_TWISTED_LOGGER)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
233 log_method = twisted_logger.error if event.get('isError', False) else twisted_logger.info
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
234 log_method(text.decode('utf-8'))
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
235
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
236 self.log_publisher._originalAddObserver(twistedObserver)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
237
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
238
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
239 class ConfigureStandard(ConfigureBasic):
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
240
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
241 def __init__(self, level=None, fmt=None, output=None, logger=None, colors=False, force_colors=False):
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
242 if fmt is None:
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
243 fmt = C.LOG_OPT_FORMAT[1]
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
244 if output is None:
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
245 output = C.LOG_OPT_OUTPUT[1]
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
246 super(ConfigureStandard, self).__init__(level, fmt, output, logger, colors, force_colors)
991
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
247
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
248 def preTreatment(self):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
249 """We use logging methods directly, instead of using Logger"""
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
250 import logging
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
251 log.getLogger = logging.getLogger
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
252 log.debug = logging.debug
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
253 log.info = logging.info
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
254 log.warning = logging.warning
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
255 log.error = logging.error
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
256 log.critical = logging.critical
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
257
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
258 def configureLevel(self, level):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
259 if level is None:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
260 level = C.LOG_LVL_DEBUG
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
261 self.level = level
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
262
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
263 def configureFormat(self, fmt):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
264 import logging
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
265
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
266 class SatFormatter(logging.Formatter):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
267 u"""Formatter which manage SàT specificities"""
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
268 _format = fmt
1013
11409a6c16c7 core (log/standard backend): added "%(profile)s" format management
Goffi <goffi@goffi.org>
parents: 1012
diff changeset
269 _with_profile = '%(profile)s' in fmt
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
270
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
271 def __init__(self, can_colors=False):
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
272 super(SatFormatter, self).__init__(self._format)
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
273 self.can_colors = can_colors
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
274
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
275 def format(self, record):
1013
11409a6c16c7 core (log/standard backend): added "%(profile)s" format management
Goffi <goffi@goffi.org>
parents: 1012
diff changeset
276 if self._with_profile:
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
277 record.profile = ConfigureStandard.getProfile()
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
278 s = super(SatFormatter, self).format(record)
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
279 if self.with_colors and (self.can_colors or self.force_colors):
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
280 s = ConfigureStandard.ansiColors(record.levelname, s)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
281 return s
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
282
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
283 self.formatterClass = SatFormatter
1006
325fd230c15d core (log): added advanced feature to basic backend (colors/formatting/level and logger filtering)
Goffi <goffi@goffi.org>
parents: 1005
diff changeset
284
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
285 def configureOutput(self, output):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
286 self.manageOutputs(output)
1006
325fd230c15d core (log): added advanced feature to basic backend (colors/formatting/level and logger filtering)
Goffi <goffi@goffi.org>
parents: 1005
diff changeset
287
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
288 def configureLogger(self, logger):
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
289 self.name_filter = log.FilterName(logger) if logger else None
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
290
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
291 def configureColors(self, colors, force_colors):
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
292 self.formatterClass.with_colors = colors
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
293 self.formatterClass.force_colors = force_colors
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
294 if not colors and force_colors:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
295 raise ValueError("force_colors can't be used if colors is False")
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
296
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
297 def _addHandler(self, root_logger, hdlr, can_colors=False):
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
298 hdlr.setFormatter(self.formatterClass(can_colors))
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
299 root_logger.addHandler(hdlr)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
300 root_logger.setLevel(self.level)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
301 if self.name_filter is not None:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
302 hdlr.addFilter(self.name_filter)
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
303
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
304 def postTreatment(self):
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
305 import logging
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
306 root_logger = logging.getLogger()
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
307 if len(root_logger.handlers) == 0:
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
308 for handler, options in log.handlers.items():
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
309 if handler == C.LOG_OPT_OUTPUT_DEFAULT:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
310 hdlr = logging.StreamHandler()
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
311 try:
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
312 can_colors = hdlr.stream.isatty()
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
313 except AttributeError:
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
314 can_colors = False
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
315 self._addHandler(root_logger, hdlr, can_colors=can_colors)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
316 elif handler == C.LOG_OPT_OUTPUT_MEMORY:
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
317 from logging.handlers import BufferingHandler
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
318 class SatMemoryHandler(BufferingHandler):
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
319 def emit(self, record):
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
320 super(SatMemoryHandler, self).emit(self.format(record))
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
321 hdlr = SatMemoryHandler(options)
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
322 log.handlers[handler] = hdlr # we keep a reference to the handler to read the buffer later
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
323 self._addHandler(root_logger, hdlr, can_colors=False)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
324 elif handler == C.LOG_OPT_OUTPUT_FILE:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
325 import os.path
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
326 for path in options:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
327 hdlr = logging.FileHandler(os.path.expanduser(path))
1012
c8771279497e core(log): standard backend: colors are now checked on a per handler basis
Goffi <goffi@goffi.org>
parents: 1010
diff changeset
328 self._addHandler(root_logger, hdlr, can_colors=False)
1007
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
329 else:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
330 raise ValueError("Unknown handler type")
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
331 else:
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
332 root_logger.warning(u"Handlers already set on root logger")
a7d33c7a8277 core (log): refactoring + twisted backend:
Goffi <goffi@goffi.org>
parents: 1006
diff changeset
333
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
334 @staticmethod
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
335 def memoryGet(size=None):
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
336 """Return buffered logs
1006
325fd230c15d core (log): added advanced feature to basic backend (colors/formatting/level and logger filtering)
Goffi <goffi@goffi.org>
parents: 1005
diff changeset
337
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
338 @param size: number of logs to return
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
339 """
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
340 mem_handler = log.handlers[C.LOG_OPT_OUTPUT_MEMORY]
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
341 return (log_msg for log_msg in mem_handler.buffer[size if size is None else -size:])
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
342
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
343
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
344 log.configure_cls[C.LOG_BACKEND_BASIC] = ConfigureBasic
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
345 log.configure_cls[C.LOG_BACKEND_TWISTED] = ConfigureTwisted
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
346 log.configure_cls[C.LOG_BACKEND_STANDARD] = ConfigureStandard
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
347
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
348 def configure(backend, **options):
1006
325fd230c15d core (log): added advanced feature to basic backend (colors/formatting/level and logger filtering)
Goffi <goffi@goffi.org>
parents: 1005
diff changeset
349 """Configure logging behaviour
991
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 @param backend: can be:
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 C.LOG_BACKEND_STANDARD: use standard logging module
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 C.LOG_BACKEND_TWISTED: use twisted logging module (with standard logging observer)
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 C.LOG_BACKEND_BASIC: use a basic print based logging
1017
0ea97f483464 core (log): added "custom" backend
Goffi <goffi@goffi.org>
parents: 1016
diff changeset
354 C.LOG_BACKEND_CUSTOM: use a given Logger subclass
991
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 """
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
356 return log.configure(backend, **options)
991
05e02f8b7eb4 core: logging refactoring, first step:
Goffi <goffi@goffi.org>
parents:
diff changeset
357
994
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
358 def _parseOptions(options):
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
359 """Parse string options as given in conf or environment variable, and return expected python value
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
360
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
361 @param options (dict): options with (key: name, value: string value)
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
362 """
1005
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
363 COLORS = C.LOG_OPT_COLORS[0]
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
364 LEVEL = C.LOG_OPT_LEVEL[0]
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
365
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
366 if COLORS in options:
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
367 if options[COLORS].lower() in ('1', 'true'):
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
368 options[COLORS] = True
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
369 elif options[COLORS] == 'force':
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
370 options[COLORS] = True
994
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
371 options['force_colors'] = True
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
372 else:
1005
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
373 options[COLORS] = False
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
374 if LEVEL in options:
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
375 level = options[LEVEL].upper()
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
376 if level not in C.LOG_LEVELS:
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
377 level = C.LOG_LVL_INFO
b4af31a8a4f2 core (logs): added formatting, name filter and outputs management:
Goffi <goffi@goffi.org>
parents: 994
diff changeset
378 options[LEVEL] = level
994
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
379
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
380 def satConfigure(backend=C.LOG_BACKEND_STANDARD, const=None):
994
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
381 """Configure logging system for SàT, can be used by frontends
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
382
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
383 logs conf is read in SàT conf, then in environment variables. It must be done before Memory init
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
384 @param backend: backend to use, it can be:
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
385 - C.LOG_BACKEND_BASIC: print based backend
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
386 - C.LOG_BACKEND_TWISTED: Twisted logging backend
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
387 - C.LOG_BACKEND_STANDARD: standard logging backend
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
388 @param const: Const class to use instead of sat.core.constants.Const (mainly used to change default values)
994
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
389 """
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
390 if const is not None:
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
391 global C
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
392 C = const
1021
a836b6da2c5c core (log): moved configuration to core.log_config; this avoid import issues with pyjamas.
Goffi <goffi@goffi.org>
parents: 1017
diff changeset
393 log.C = const
994
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
394 import ConfigParser
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
395 import os
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
396 log_conf = {}
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
397 config = ConfigParser.SafeConfigParser()
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
398 config.read(C.CONFIG_FILES)
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
399 for opt_name, opt_default in C.LOG_OPTIONS():
994
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
400 try:
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
401 log_conf[opt_name] = os.environ[''.join((C.ENV_PREFIX, C.LOG_OPT_PREFIX.upper(), opt_name.upper()))]
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
402 except KeyError:
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
403 try:
1010
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
404 log_conf[opt_name] = config.get(C.LOG_OPT_SECTION, C.LOG_OPT_PREFIX + opt_name)
73a0b7f94674 primitivus: use of new logging system:
Goffi <goffi@goffi.org>
parents: 1008
diff changeset
405 except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
994
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
406 log_conf[opt_name] = opt_default
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
407
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
408 _parseOptions(log_conf)
652c01ca69b1 core (log): configuration and environment variables are now checked for log level and colors:
Goffi <goffi@goffi.org>
parents: 992
diff changeset
409 configure(backend, **log_conf)