21 from StringIO import StringIO |
21 from StringIO import StringIO |
22 from urllib import quote as urlquote, unquote as urlunquote |
22 from urllib import quote as urlquote, unquote as urlunquote |
23 |
23 |
24 from logilab.common.decorators import cached |
24 from logilab.common.decorators import cached |
25 |
25 |
26 |
|
27 LLDEBUG = 5 |
|
28 logging.addLevelName(LLDEBUG, 'LLDEBUG') |
|
29 |
|
30 class CubicWebLogger(logging.Logger): |
|
31 |
|
32 def lldebug(self, msg, *args, **kwargs): |
|
33 """ |
|
34 Log 'msg % args' with severity 'DEBUG'. |
|
35 |
|
36 To pass exception information, use the keyword argument exc_info with |
|
37 a true value, e.g. |
|
38 |
|
39 logger.debug("Houston, we have a %s", "thorny problem", exc_info=1) |
|
40 """ |
|
41 if self.manager.disable >= LLDEBUG: |
|
42 return |
|
43 if LLDEBUG >= self.getEffectiveLevel(): |
|
44 self._log(LLDEBUG, msg, args, **kwargs) |
|
45 |
|
46 logging.setLoggerClass(CubicWebLogger) |
|
47 |
|
48 def set_log_methods(cls, logger): |
26 def set_log_methods(cls, logger): |
49 """bind standart logger's methods as static methods on the class |
27 """bind standart logger's methods as static methods on the class |
50 """ |
28 """ |
51 cls._logger = logger |
29 cls._logger = logger |
52 for attr in ('lldebug', 'debug', 'info', 'warning', 'error', 'critical', 'exception'): |
30 for attr in ('debug', 'info', 'warning', 'error', 'critical', 'exception'): |
53 setattr(cls, attr, getattr(logger, attr)) |
31 setattr(cls, attr, getattr(logger, attr)) |
54 |
32 |
55 if os.environ.get('APYCOT_ROOT'): |
33 if os.environ.get('APYCOT_ROOT'): |
56 logging.basicConfig(level=logging.CRITICAL) |
34 logging.basicConfig(level=logging.CRITICAL) |
57 else: |
35 else: |