[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) <rco@openerp.com>
This commit is contained in:
Adrian Torres
2020-03-26 09:25:15 +00:00
committed by Raphael Collet
parent 34227348f0
commit 975ba27723
+8 -8
View File
@@ -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