Skip to content

Commit d145252

Browse files
committed
base_rest: turn off deprecation logging on demand
Disable logging for deprecation. You might have big projects, with tons of services with no specific decorator, that are well tested and very stable and you don't want to touch them. Especially if you plan already to move to v16. Since this logging can bloat your CI and your log collecting tools, here is a way to prevent that and get only a msg at boot. Once enabled, you'll see this msg in the logs only at start up: 'odoo.addons.base_rest.components.service: REST_API_METHOD_FIX_DECORATOR_DEPRECATE_LOG_DISABLE enabled: implicit service methods are deprecated. Disable this env key and enable debug level to have more details.'
1 parent 71ec29b commit d145252

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

base_rest/components/service.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
import logging
6+
import os
67

78
from werkzeug.exceptions import NotFound
89

@@ -17,6 +18,23 @@
1718
_logger = logging.getLogger(__name__)
1819

1920

21+
# Disable logging for deprecation.
22+
# You might have big projects, with tons of services with no specific decorator,
23+
# that are well tested and very stable and you don't want to touch them.
24+
# Especially if you plan already to move to v16.
25+
# Since this logging can bloat your CI and your log collecting tools,
26+
# here is a way to prevent that and get only a msg at boot.
27+
DISABLE_DEPRECATE_LOG_KEY = "REST_API_METHOD_FIX_DECORATOR_DEPRECATE_LOG_DISABLE"
28+
DISABLE_DEPRECATE_LOG = os.getenv(DISABLE_DEPRECATE_LOG_KEY)
29+
if DISABLE_DEPRECATE_LOG:
30+
msg = (
31+
"%s enabled: "
32+
"implicit service methods are deprecated. "
33+
"Disable this env key and enable debug level to have more details."
34+
)
35+
_logger.warning(msg, DISABLE_DEPRECATE_LOG_KEY)
36+
37+
2038
def to_int(val):
2139
# The javascript VM ducktape only use float and so pass float
2240
# to the api, the werkzeug request interpret params as unicode
@@ -127,7 +145,7 @@ def _prepare_response(self, method, result):
127145
return result
128146
routing = getattr(method, ROUTING_DECORATOR_ATTR, None)
129147
output_param = routing["output_param"]
130-
if not output_param:
148+
if not output_param and not DISABLE_DEPRECATE_LOG:
131149
_logger.warning(
132150
"DEPRECATED: You must define an output schema for method %s "
133151
"in service %s",

0 commit comments

Comments
 (0)