From 975ba2772304c66adf8be66a353fab529ada9c35 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Thu, 26 Mar 2020 08:37:42 +0000 Subject: [PATCH] [FIX] core: enable logger.runbot() when importing odoo as a library Before this commit, trying to use Odoo as a library without initializing the logging features would result in a crash because `Logger.runbot()` is monkey-patched inside the function `init_logger()`, which is de facto necessary for using Odoo as a lib. With this commit, we do the monkey-patch at the module-level so whenever the `netsvc` package is imported the patch is applied, which should be well before the loading of the registry starts. closes odoo/odoo#48396 Signed-off-by: Raphael Collet (rco) --- odoo/netsvc.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/odoo/netsvc.py b/odoo/netsvc.py index b731eb347bd..9025532f32f 100644 --- a/odoo/netsvc.py +++ b/odoo/netsvc.py @@ -125,14 +125,6 @@ def init_logger(): return record logging.setLogRecordFactory(record_factory) - logging.RUNBOT = 25 - logging.addLevelName(logging.RUNBOT, "INFO") # displayed as info in log - logging.captureWarnings(True) - - def runbot(self, message, *args, **kws): - self.log(logging.RUNBOT, message, *args, **kws) - logging.Logger.runbot = runbot - # enable deprecation warnings (disabled by default) warnings.filterwarnings('once', category=DeprecationWarning) # ignore deprecation warnings from invalid escape (there's a ton and it's @@ -242,3 +234,11 @@ PSEUDOCONFIG_MAPPER = { 'error': ['odoo:ERROR', 'werkzeug:ERROR'], 'critical': ['odoo:CRITICAL', 'werkzeug:CRITICAL'], } + +logging.RUNBOT = 25 +logging.addLevelName(logging.RUNBOT, "INFO") # displayed as info in log +logging.captureWarnings(True) + +def runbot(self, message, *args, **kws): + self.log(logging.RUNBOT, message, *args, **kws) +logging.Logger.runbot = runbot