mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 04:32:07 +02:00
18.0 vanilla
This commit is contained in:
parent
d72e748793
commit
0a7ae8db93
337 changed files with 399651 additions and 232598 deletions
|
|
@ -23,6 +23,11 @@ from .modules import module
|
|||
_logger = logging.getLogger(__name__)
|
||||
|
||||
def log(logger, level, prefix, msg, depth=None):
|
||||
warnings.warn(
|
||||
"odoo.netsvc.log is deprecated starting Odoo 18, use normal logging APIs",
|
||||
category=DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
indent=''
|
||||
indent_after=' '*len(prefix)
|
||||
for line in (prefix + pprint.pformat(msg, depth=depth)).split('\n'):
|
||||
|
|
@ -62,7 +67,7 @@ class PostgreSQLHandler(logging.Handler):
|
|||
with contextlib.suppress(Exception), tools.mute_logger('odoo.sql_db'), sql_db.db_connect(dbname, allow_uri=True).cursor() as cr:
|
||||
# preclude risks of deadlocks
|
||||
cr.execute("SET LOCAL statement_timeout = 1000")
|
||||
msg = tools.ustr(record.msg)
|
||||
msg = str(record.msg)
|
||||
if record.args:
|
||||
msg = msg % record.args
|
||||
traceback = getattr(record, 'exc_text', '')
|
||||
|
|
@ -110,9 +115,13 @@ LEVEL_COLOR_MAPPING = {
|
|||
}
|
||||
|
||||
class PerfFilter(logging.Filter):
|
||||
|
||||
def format_perf(self, query_count, query_time, remaining_time):
|
||||
return ("%d" % query_count, "%.3f" % query_time, "%.3f" % remaining_time)
|
||||
|
||||
def format_cursor_mode(self, cursor_mode):
|
||||
return cursor_mode or '-'
|
||||
|
||||
def filter(self, record):
|
||||
if hasattr(threading.current_thread(), "query_count"):
|
||||
query_count = threading.current_thread().query_count
|
||||
|
|
@ -120,8 +129,13 @@ class PerfFilter(logging.Filter):
|
|||
perf_t0 = threading.current_thread().perf_t0
|
||||
remaining_time = time.time() - perf_t0 - query_time
|
||||
record.perf_info = '%s %s %s' % self.format_perf(query_count, query_time, remaining_time)
|
||||
if tools.config['db_replica_host'] is not False:
|
||||
cursor_mode = threading.current_thread().cursor_mode
|
||||
record.perf_info = f'{record.perf_info} {self.format_cursor_mode(cursor_mode)}'
|
||||
delattr(threading.current_thread(), "query_count")
|
||||
else:
|
||||
if tools.config['db_replica_host'] is not False:
|
||||
record.perf_info = "- - - -"
|
||||
record.perf_info = "- - -"
|
||||
return True
|
||||
|
||||
|
|
@ -136,9 +150,18 @@ class ColoredPerfFilter(PerfFilter):
|
|||
return (
|
||||
colorize_time(query_count, "%d", 100, 1000),
|
||||
colorize_time(query_time, "%.3f", 0.1, 3),
|
||||
colorize_time(remaining_time, "%.3f", 1, 5)
|
||||
colorize_time(remaining_time, "%.3f", 1, 5),
|
||||
)
|
||||
|
||||
def format_cursor_mode(self, cursor_mode):
|
||||
cursor_mode = super().format_cursor_mode(cursor_mode)
|
||||
cursor_mode_color = (
|
||||
RED if cursor_mode == 'ro->rw'
|
||||
else YELLOW if cursor_mode == 'rw'
|
||||
else GREEN
|
||||
)
|
||||
return COLOR_PATTERN % (30 + cursor_mode_color, 40 + DEFAULT, cursor_mode)
|
||||
|
||||
class DBFormatter(logging.Formatter):
|
||||
def format(self, record):
|
||||
record.pid = os.getpid()
|
||||
|
|
@ -151,35 +174,36 @@ class ColoredFormatter(DBFormatter):
|
|||
record.levelname = COLOR_PATTERN % (30 + fg_color, 40 + bg_color, record.levelname)
|
||||
return DBFormatter.format(self, record)
|
||||
|
||||
_logger_init = False
|
||||
def init_logger():
|
||||
global _logger_init
|
||||
if _logger_init:
|
||||
return
|
||||
_logger_init = True
|
||||
|
||||
old_factory = logging.getLogRecordFactory()
|
||||
def record_factory(*args, **kwargs):
|
||||
record = old_factory(*args, **kwargs)
|
||||
record.perf_info = ""
|
||||
return record
|
||||
logging.setLogRecordFactory(record_factory)
|
||||
class LogRecord(logging.LogRecord):
|
||||
def __init__(self, name, level, pathname, lineno, msg, args, exc_info, func=None, sinfo=None):
|
||||
super().__init__(name, level, pathname, lineno, msg, args, exc_info, func, sinfo)
|
||||
self.perf_info = ""
|
||||
|
||||
|
||||
showwarning = None
|
||||
def init_logger():
|
||||
global showwarning # noqa: PLW0603
|
||||
if logging.getLogRecordFactory() is LogRecord:
|
||||
return
|
||||
|
||||
logging.setLogRecordFactory(LogRecord)
|
||||
|
||||
logging.captureWarnings(True)
|
||||
# must be after `loggin.captureWarnings` so we override *that* instead of
|
||||
# the other way around
|
||||
showwarning = warnings.showwarning
|
||||
warnings.showwarning = showwarning_with_traceback
|
||||
|
||||
# enable deprecation warnings (disabled by default)
|
||||
warnings.simplefilter('default', category=DeprecationWarning)
|
||||
if sys.version_info[:2] == (3, 9):
|
||||
# recordsets are both sequence and set so trigger warning despite no issue
|
||||
# Only applies to 3.9 as it was fixed in 3.10 see https://bugs.python.org/issue42470
|
||||
warnings.filterwarnings('ignore', r'^Sampling from a set', category=DeprecationWarning, module='odoo')
|
||||
# https://github.com/urllib3/urllib3/issues/2680
|
||||
warnings.filterwarnings('ignore', r'^\'urllib3.contrib.pyopenssl\' module is deprecated.+', category=DeprecationWarning)
|
||||
# ofxparse use an html parser to parse ofx xml files and triggers a warning since bs4 4.11.0
|
||||
# https://github.com/jseutter/ofxparse/issues/170
|
||||
try:
|
||||
with contextlib.suppress(ImportError):
|
||||
from bs4 import XMLParsedAsHTMLWarning
|
||||
warnings.filterwarnings('ignore', category=XMLParsedAsHTMLWarning)
|
||||
except ImportError:
|
||||
pass
|
||||
# ignore a bunch of warnings we can't really fix ourselves
|
||||
for module in [
|
||||
'babel.util', # deprecated parser module, no release yet
|
||||
|
|
@ -203,6 +227,13 @@ def init_logger():
|
|||
# need to be adapted later but too muchwork for this pr.
|
||||
warnings.filterwarnings('ignore', r'^datetime.datetime.utcnow\(\) is deprecated and scheduled for removal in a future version.*', category=DeprecationWarning)
|
||||
|
||||
# pkg_ressouce is used in google-auth < 1.23.0 (removed in https://github.com/googleapis/google-auth-library-python/pull/596)
|
||||
# unfortunately, in ubuntu jammy and noble, the google-auth version is 1.5.1
|
||||
# starting from noble, the default pkg_ressource version emits a warning on import, triggered when importing
|
||||
# google-auth
|
||||
warnings.filterwarnings('ignore', r'pkg_resources is deprecated as an API.+', category=DeprecationWarning)
|
||||
warnings.filterwarnings('ignore', r'Deprecated call to \`pkg_resources.declare_namespace.+', category=DeprecationWarning)
|
||||
|
||||
# This warning is triggered library only during the python precompilation which does not occur on readonly filesystem
|
||||
warnings.filterwarnings("ignore", r'invalid escape sequence', category=DeprecationWarning, module=".*vobject")
|
||||
warnings.filterwarnings("ignore", r'invalid escape sequence', category=SyntaxWarning, module=".*vobject")
|
||||
|
|
@ -305,10 +336,6 @@ PSEUDOCONFIG_MAPPER = {
|
|||
|
||||
logging.RUNBOT = 25
|
||||
logging.addLevelName(logging.RUNBOT, "INFO") # displayed as info in log
|
||||
logging.captureWarnings(True)
|
||||
# must be after `loggin.captureWarnings` so we override *that* instead of the
|
||||
# other way around
|
||||
showwarning = warnings.showwarning
|
||||
IGNORE = {
|
||||
'Comparison between bytes and int', # a.foo != False or some shit, we don't care
|
||||
}
|
||||
|
|
@ -328,7 +355,6 @@ def showwarning_with_traceback(message, category, filename, lineno, file=None, l
|
|||
file=file,
|
||||
line=''.join(traceback.format_list(filtered))
|
||||
)
|
||||
warnings.showwarning = showwarning_with_traceback
|
||||
|
||||
def runbot(self, message, *args, **kws):
|
||||
self.log(logging.RUNBOT, message, *args, **kws)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue