logging: Create a new level DEBUG_FILTERS
This is a cleaner approach that requires less configuration in other applications. This also easily allows us to have another color. Many checks were made on being exactly at the DEBUG level, they were fixed to also check on being below DEBUG (i.e. DEBUG_FILTERS).
This commit is contained in:
parent
822c1a3607
commit
7be9a6468b
12 changed files with 27 additions and 35 deletions
|
|
@ -240,7 +240,7 @@ class Monboob(ReplApplication):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
content = u'Unable to send message to %s:\n' % thread_id
|
content = u'Unable to send message to %s:\n' % thread_id
|
||||||
content += u'\n\t%s\n' % to_unicode(e)
|
content += u'\n\t%s\n' % to_unicode(e)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
content += u'\n%s\n' % to_unicode(get_backtrace(e))
|
content += u'\n%s\n' % to_unicode(get_backtrace(e))
|
||||||
self.send_email(backend, Message(thread,
|
self.send_email(backend, Message(thread,
|
||||||
0,
|
0,
|
||||||
|
|
|
||||||
|
|
@ -273,7 +273,7 @@ class MessagesManager(QWidget):
|
||||||
|
|
||||||
def _postReply_eb(self, backend, error, backtrace):
|
def _postReply_eb(self, backend, error, backtrace):
|
||||||
content = unicode(self.tr('Unable to send message:\n%s\n')) % to_unicode(error)
|
content = unicode(self.tr('Unable to send message:\n%s\n')) % to_unicode(error)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
content += '\n%s\n' % to_unicode(backtrace)
|
content += '\n%s\n' % to_unicode(backtrace)
|
||||||
QMessageBox.critical(self, self.tr('Error while posting reply'),
|
QMessageBox.critical(self, self.tr('Error while posting reply'),
|
||||||
content, QMessageBox.Ok)
|
content, QMessageBox.Ok)
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ class ContactThread(QWidget):
|
||||||
|
|
||||||
def _postReply_eb(self, backend, error, backtrace):
|
def _postReply_eb(self, backend, error, backtrace):
|
||||||
content = unicode(self.tr('Unable to send message:\n%s\n')) % to_unicode(error)
|
content = unicode(self.tr('Unable to send message:\n%s\n')) % to_unicode(error)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
content += '\n%s\n' % to_unicode(backtrace)
|
content += '\n%s\n' % to_unicode(backtrace)
|
||||||
QMessageBox.critical(self, self.tr('Error while posting reply'),
|
QMessageBox.critical(self, self.tr('Error while posting reply'),
|
||||||
content, QMessageBox.Ok)
|
content, QMessageBox.Ok)
|
||||||
|
|
@ -378,7 +378,7 @@ class ContactNotes(QWidget):
|
||||||
self.ui.textEdit.setEnabled(True)
|
self.ui.textEdit.setEnabled(True)
|
||||||
self.ui.saveButton.setEnabled(True)
|
self.ui.saveButton.setEnabled(True)
|
||||||
content = unicode(self.tr('Unable to load notes:\n%s\n')) % to_unicode(error)
|
content = unicode(self.tr('Unable to load notes:\n%s\n')) % to_unicode(error)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
content += '\n%s\n' % to_unicode(backtrace)
|
content += '\n%s\n' % to_unicode(backtrace)
|
||||||
QMessageBox.critical(self, self.tr('Error while loading notes'),
|
QMessageBox.critical(self, self.tr('Error while loading notes'),
|
||||||
content, QMessageBox.Ok)
|
content, QMessageBox.Ok)
|
||||||
|
|
@ -400,7 +400,7 @@ class ContactNotes(QWidget):
|
||||||
self.ui.saveButton.setEnabled(True)
|
self.ui.saveButton.setEnabled(True)
|
||||||
self.ui.textEdit.setEnabled(True)
|
self.ui.textEdit.setEnabled(True)
|
||||||
content = unicode(self.tr('Unable to save notes:\n%s\n')) % to_unicode(error)
|
content = unicode(self.tr('Unable to save notes:\n%s\n')) % to_unicode(error)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
content += '\n%s\n' % to_unicode(backtrace)
|
content += '\n%s\n' % to_unicode(backtrace)
|
||||||
QMessageBox.critical(self, self.tr('Error while saving notes'),
|
QMessageBox.critical(self, self.tr('Error while saving notes'),
|
||||||
content, QMessageBox.Ok)
|
content, QMessageBox.Ok)
|
||||||
|
|
@ -592,7 +592,7 @@ class ContactsWidget(QWidget):
|
||||||
|
|
||||||
def retrieveContact_eb(self, backend, error, backtrace):
|
def retrieveContact_eb(self, backend, error, backtrace):
|
||||||
content = unicode(self.tr('Unable to get contact:\n%s\n')) % to_unicode(error)
|
content = unicode(self.tr('Unable to get contact:\n%s\n')) % to_unicode(error)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
content += u'\n%s\n' % to_unicode(backtrace)
|
content += u'\n%s\n' % to_unicode(backtrace)
|
||||||
QMessageBox.critical(self, self.tr('Error while getting contact'),
|
QMessageBox.critical(self, self.tr('Error while getting contact'),
|
||||||
content, QMessageBox.Ok)
|
content, QMessageBox.Ok)
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ class MainWindow(QtMainWindow):
|
||||||
def _errorLoadPage(self, backend, error, backtrace):
|
def _errorLoadPage(self, backend, error, backtrace):
|
||||||
""" Error callback for loadPage """
|
""" Error callback for loadPage """
|
||||||
content = unicode(self.tr('Unable to load page:\n%s\n')) % to_unicode(error)
|
content = unicode(self.tr('Unable to load page:\n%s\n')) % to_unicode(error)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
content += '\n%s\n' % to_unicode(backtrace)
|
content += '\n%s\n' % to_unicode(backtrace)
|
||||||
QMessageBox.critical(self, self.tr('Error while loading page'),
|
QMessageBox.critical(self, self.tr('Error while loading page'),
|
||||||
content, QMessageBox.Ok)
|
content, QMessageBox.Ok)
|
||||||
|
|
@ -186,7 +186,7 @@ class MainWindow(QtMainWindow):
|
||||||
def _errorSavePage(self, backend, error, backtrace):
|
def _errorSavePage(self, backend, error, backtrace):
|
||||||
""" """
|
""" """
|
||||||
content = unicode(self.tr('Unable to save page:\n%s\n')) % to_unicode(error)
|
content = unicode(self.tr('Unable to save page:\n%s\n')) % to_unicode(error)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
content += '\n%s\n' % to_unicode(backtrace)
|
content += '\n%s\n' % to_unicode(backtrace)
|
||||||
QMessageBox.critical(self, self.tr('Error while saving page'),
|
QMessageBox.critical(self, self.tr('Error while saving page'),
|
||||||
content, QMessageBox.Ok)
|
content, QMessageBox.Ok)
|
||||||
|
|
@ -264,7 +264,7 @@ class MainWindow(QtMainWindow):
|
||||||
return
|
return
|
||||||
|
|
||||||
content = unicode(self.tr('Unable to load history:\n%s\n')) % to_unicode(error)
|
content = unicode(self.tr('Unable to load history:\n%s\n')) % to_unicode(error)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
content += '\n%s\n' % to_unicode(backtrace)
|
content += '\n%s\n' % to_unicode(backtrace)
|
||||||
QMessageBox.critical(self, self.tr('Error while loading history'),
|
QMessageBox.critical(self, self.tr('Error while loading history'),
|
||||||
content, QMessageBox.Ok)
|
content, QMessageBox.Ok)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import re
|
||||||
import sys
|
import sys
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from weboob.tools.log import getLogger
|
from weboob.tools.log import getLogger, DEBUG_FILTERS
|
||||||
from weboob.tools.ordereddict import OrderedDict
|
from weboob.tools.ordereddict import OrderedDict
|
||||||
from weboob.browser.pages import NextPage
|
from weboob.browser.pages import NextPage
|
||||||
|
|
||||||
|
|
@ -270,7 +270,7 @@ class ItemElement(AbstractElement):
|
||||||
self.logger.warning('Attribute %s raises %s' % (key, repr(e)))
|
self.logger.warning('Attribute %s raises %s' % (key, repr(e)))
|
||||||
raise
|
raise
|
||||||
logger = getLogger('b2filters')
|
logger = getLogger('b2filters')
|
||||||
logger.debug("%s.%s = %r" % (self._random_id, key, value))
|
logger.log(DEBUG_FILTERS, "%s.%s = %r" % (self._random_id, key, value))
|
||||||
setattr(self.obj, key, value)
|
setattr(self.obj, key, value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ from weboob.capabilities.base import empty
|
||||||
from weboob.tools.compat import basestring
|
from weboob.tools.compat import basestring
|
||||||
from weboob.exceptions import ParseError
|
from weboob.exceptions import ParseError
|
||||||
from weboob.browser.url import URL
|
from weboob.browser.url import URL
|
||||||
from weboob.tools.log import getLogger
|
from weboob.tools.log import getLogger, DEBUG_FILTERS
|
||||||
|
|
||||||
class NoDefault(object):
|
class NoDefault(object):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
@ -130,7 +130,7 @@ def debug(*args):
|
||||||
continue
|
continue
|
||||||
result += ", %s=%r" % (arg, getattr(self, arg))
|
result += ", %s=%r" % (arg, getattr(self, arg))
|
||||||
result += u')'
|
result += u')'
|
||||||
logger.debug(result)
|
logger.log(DEBUG_FILTERS, result)
|
||||||
res = function(self, value)
|
res = function(self, value)
|
||||||
return res
|
return res
|
||||||
return print_debug
|
return print_debug
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ class ModulesLoader(object):
|
||||||
if fp:
|
if fp:
|
||||||
fp.close()
|
fp.close()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
self.logger.exception(e)
|
self.logger.exception(e)
|
||||||
raise ModuleLoadError(module_name, e)
|
raise ModuleLoadError(module_name, e)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ class StandardBrowser(mechanize.Browser):
|
||||||
# display messages from httplib
|
# display messages from httplib
|
||||||
self.set_debug_http(True)
|
self.set_debug_http(True)
|
||||||
|
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
# Enable log messages from mechanize.Browser
|
# Enable log messages from mechanize.Browser
|
||||||
self.set_debug_redirects(True)
|
self.set_debug_redirects(True)
|
||||||
mech_logger = logging.getLogger("mechanize")
|
mech_logger = logging.getLogger("mechanize")
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ from weboob.core import Weboob, CallErrors
|
||||||
from weboob.core.backendscfg import BackendsConfig
|
from weboob.core.backendscfg import BackendsConfig
|
||||||
from weboob.tools.config.iconfig import ConfigError
|
from weboob.tools.config.iconfig import ConfigError
|
||||||
from weboob.exceptions import FormFieldConversionWarning
|
from weboob.exceptions import FormFieldConversionWarning
|
||||||
from weboob.tools.log import createColoredFormatter, getLogger, DebugFilter, settings as log_settings
|
from weboob.tools.log import createColoredFormatter, getLogger, DEBUG_FILTERS, settings as log_settings
|
||||||
from weboob.tools.misc import to_unicode
|
from weboob.tools.misc import to_unicode
|
||||||
from .results import ResultsConditionError
|
from .results import ResultsConditionError
|
||||||
|
|
||||||
|
|
@ -314,7 +314,7 @@ class Application(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
print(u'Error(%s): %s' % (backend.name, error), file=self.stderr)
|
print(u'Error(%s): %s' % (backend.name, error), file=self.stderr)
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
print(backtrace, file=self.stderr)
|
print(backtrace, file=self.stderr)
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
@ -354,7 +354,9 @@ class Application(object):
|
||||||
print(' '.join(items))
|
print(' '.join(items))
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if self.options.debug or self.options.save_responses:
|
if self.options.debug >= self.DEBUG_FILTER:
|
||||||
|
level = DEBUG_FILTERS
|
||||||
|
elif self.options.debug or self.options.save_responses:
|
||||||
level = logging.DEBUG
|
level = logging.DEBUG
|
||||||
elif self.options.verbose:
|
elif self.options.verbose:
|
||||||
level = logging.INFO
|
level = logging.INFO
|
||||||
|
|
@ -391,10 +393,6 @@ class Application(object):
|
||||||
self._handle_options()
|
self._handle_options()
|
||||||
self.handle_application_options()
|
self.handle_application_options()
|
||||||
|
|
||||||
if self.options.debug < self.DEBUG_FILTER:
|
|
||||||
for handler in handlers:
|
|
||||||
handler.addFilter(DebugFilter())
|
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
||||||
|
|
@ -572,7 +572,7 @@ class ConsoleApplication(Application):
|
||||||
print('New version of module %s has been installed. Retry to call the command.' % minfo.name)
|
print('New version of module %s has been installed. Retry to call the command.' % minfo.name)
|
||||||
return
|
return
|
||||||
|
|
||||||
if logging.root.level == logging.DEBUG:
|
if logging.root.level <= logging.DEBUG:
|
||||||
print(backtrace, file=self.stderr)
|
print(backtrace, file=self.stderr)
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,7 @@ class QtDo(QObject):
|
||||||
elif isinstance(error, UserError):
|
elif isinstance(error, UserError):
|
||||||
if not msg:
|
if not msg:
|
||||||
msg = type(error).__name__
|
msg = type(error).__name__
|
||||||
elif logging.root.level == logging.DEBUG:
|
elif logging.root.level <= logging.DEBUG:
|
||||||
msg += u'<br />'
|
msg += u'<br />'
|
||||||
ul_opened = False
|
ul_opened = False
|
||||||
for line in backtrace.split('\n'):
|
for line in backtrace.split('\n'):
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from logging import Filter, Formatter, getLogger as _getLogger
|
from logging import addLevelName, Formatter, getLogger as _getLogger
|
||||||
|
|
||||||
__all__ = ['getLogger', 'createColoredFormatter', 'settings']
|
__all__ = ['getLogger', 'createColoredFormatter', 'settings']
|
||||||
|
|
||||||
|
|
@ -35,8 +35,12 @@ COLORS = {
|
||||||
'WARNING': COLOR_SEQ % "\033[1;33m",
|
'WARNING': COLOR_SEQ % "\033[1;33m",
|
||||||
'ERROR': COLOR_SEQ % "\033[1;31m",
|
'ERROR': COLOR_SEQ % "\033[1;31m",
|
||||||
'CRITICAL': COLOR_SEQ % ("\033[1;33m\033[1;41m"),
|
'CRITICAL': COLOR_SEQ % ("\033[1;33m\033[1;41m"),
|
||||||
|
'DEBUG_FILTERS': COLOR_SEQ % "\033[0;35m",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DEBUG_FILTERS = 8
|
||||||
|
addLevelName(DEBUG_FILTERS, 'DEBUG_FILTERS')
|
||||||
|
|
||||||
|
|
||||||
# Global settings f logger.
|
# Global settings f logger.
|
||||||
settings = defaultdict(lambda: None)
|
settings = defaultdict(lambda: None)
|
||||||
|
|
@ -50,16 +54,6 @@ def getLogger(name, parent=None):
|
||||||
return logger
|
return logger
|
||||||
|
|
||||||
|
|
||||||
class DebugFilter(Filter):
|
|
||||||
"""
|
|
||||||
Allow a fine filtering of debug output
|
|
||||||
"""
|
|
||||||
def filter(self, record):
|
|
||||||
if record.name == "b2filters":
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class ColoredFormatter(Formatter):
|
class ColoredFormatter(Formatter):
|
||||||
"""
|
"""
|
||||||
Class written by airmind:
|
Class written by airmind:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue