Update log translation hacking rule
Starting with the Pike series, OpenStack no longer supports log translation. Update hacking rule to prevent log translation in all log level instead of only debug level. Change-Id: I4c6d720b2aa91a883bbf974d390028218357e1e4
This commit is contained in:
parent
f589965688
commit
e181a9c0ff
16
HACKING.rst
16
HACKING.rst
|
@ -1,12 +1,12 @@
|
||||||
Sahara Style Commandments
|
Sahara Style Commandments
|
||||||
==========================
|
=========================
|
||||||
|
|
||||||
- Step 1: Read the OpenStack Style Commandments
|
- Step 1: Read the OpenStack Style Commandments
|
||||||
http://docs.openstack.org/developer/hacking/
|
http://docs.openstack.org/developer/hacking/
|
||||||
- Step 2: Read on
|
- Step 2: Read on
|
||||||
|
|
||||||
Sahara Specific Commandments
|
Sahara Specific Commandments
|
||||||
-----------------------------
|
----------------------------
|
||||||
|
|
||||||
Commit Messages
|
Commit Messages
|
||||||
---------------
|
---------------
|
||||||
|
@ -30,19 +30,11 @@ Dictionaries/Lists
|
||||||
- [S368] Must use a dict comprehension instead of a dict constructor with a
|
- [S368] Must use a dict comprehension instead of a dict constructor with a
|
||||||
sequence of key-value pairs. For more information, please refer to
|
sequence of key-value pairs. For more information, please refer to
|
||||||
http://legacy.python.org/dev/peps/pep-0274/
|
http://legacy.python.org/dev/peps/pep-0274/
|
||||||
=======
|
|
||||||
Logs
|
Logs
|
||||||
----
|
----
|
||||||
|
|
||||||
- [S369] Check LOG.info translations
|
- [S373] Don't translate logs
|
||||||
|
|
||||||
- [S370] Check LOG.error translations
|
|
||||||
|
|
||||||
- [S371] Check LOG.warning translations
|
|
||||||
|
|
||||||
- [S372] Check LOG.critical translation
|
|
||||||
|
|
||||||
- [S373] LOG.debug never used for translations
|
|
||||||
|
|
||||||
- [S374] You used a deprecated log level
|
- [S374] You used a deprecated log level
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ def factory(register):
|
||||||
register(import_checks.hacking_import_groups)
|
register(import_checks.hacking_import_groups)
|
||||||
register(import_checks.hacking_import_groups_together)
|
register(import_checks.hacking_import_groups_together)
|
||||||
register(dict_constructor_with_list_copy)
|
register(dict_constructor_with_list_copy)
|
||||||
register(logging_checks.no_translate_debug_logs)
|
register(logging_checks.no_translate_logs)
|
||||||
register(logging_checks.accepted_log_levels)
|
register(logging_checks.accepted_log_levels)
|
||||||
register(use_jsonutils)
|
register(use_jsonutils)
|
||||||
register(no_mutable_default_args)
|
register(no_mutable_default_args)
|
||||||
|
|
|
@ -13,23 +13,21 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
# NOTE(Kezar): this checks was copied from cinder/nova and should be one day
|
_all_log_levels = "info|exception|warning|critical|error|debug"
|
||||||
# appear at general hacking checks. So we need to try remember it and remove it
|
|
||||||
# when it'll be happened.
|
_accepted_log_level = re.compile(
|
||||||
# FIXME(Kezar): may be it will be better to right in the way that introduced in
|
r"(.)*LOG\.(%(levels)s)\(" % {'levels': _all_log_levels})
|
||||||
# keystone but it will need additional work and total checks refactoring.
|
|
||||||
|
# Since _Lx() have been removed, we just need to check _()
|
||||||
|
_translated_log = re.compile(
|
||||||
|
r"(.)*LOG\.(%(levels)s)\(\s*_\(" % {'levels': _all_log_levels})
|
||||||
|
|
||||||
|
|
||||||
accepted_log_level = re.compile(
|
def no_translate_logs(logical_line, filename):
|
||||||
r"^LOG\.(debug|info|exception|warning|error|critical)\(")
|
"""Check for 'LOG.*(_('
|
||||||
|
|
||||||
|
Translators don't provide translations for log messages, and operators
|
||||||
def no_translate_debug_logs(logical_line, filename):
|
asked not to translate them.
|
||||||
"""Check for 'LOG.debug(_('
|
|
||||||
|
|
||||||
As per our translation policy,
|
|
||||||
https://wiki.openstack.org/wiki/LoggingStandards#Log_Translation
|
|
||||||
we shouldn't translate debug level logs.
|
|
||||||
|
|
||||||
* This check assumes that 'LOG' is a logger.
|
* This check assumes that 'LOG' is a logger.
|
||||||
* Use filename so we can start enforcing this in specific folders instead
|
* Use filename so we can start enforcing this in specific folders instead
|
||||||
|
@ -37,9 +35,9 @@ def no_translate_debug_logs(logical_line, filename):
|
||||||
S373
|
S373
|
||||||
"""
|
"""
|
||||||
|
|
||||||
msg = "S373 Don't translate debug level logs"
|
msg = "S373 Don't translate logs"
|
||||||
if logical_line.startswith("LOG.debug(_("):
|
if _translated_log.match(logical_line):
|
||||||
yield(0, msg)
|
yield (0, msg)
|
||||||
|
|
||||||
|
|
||||||
def accepted_log_levels(logical_line, filename):
|
def accepted_log_levels(logical_line, filename):
|
||||||
|
@ -47,7 +45,7 @@ def accepted_log_levels(logical_line, filename):
|
||||||
|
|
||||||
This check is needed because we don't want new contributors to
|
This check is needed because we don't want new contributors to
|
||||||
use deprecated log levels.
|
use deprecated log levels.
|
||||||
S373
|
S374
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# NOTE(Kezar): sahara/tests included because we don't require translations
|
# NOTE(Kezar): sahara/tests included because we don't require translations
|
||||||
|
@ -59,8 +57,8 @@ def accepted_log_levels(logical_line, filename):
|
||||||
for directory in ignore_dirs:
|
for directory in ignore_dirs:
|
||||||
if directory in filename:
|
if directory in filename:
|
||||||
return
|
return
|
||||||
msg = ("S373 You used deprecated log level. Accepted log levels are "
|
msg = ("S374 You used deprecated log level. Accepted log levels are "
|
||||||
"debug|info|warning|error|critical")
|
"%(levels)s" % {'levels': _all_log_levels})
|
||||||
if logical_line.startswith("LOG."):
|
if logical_line.startswith("LOG."):
|
||||||
if not accepted_log_level.search(logical_line):
|
if not _accepted_log_level.search(logical_line):
|
||||||
yield(0, msg)
|
yield(0, msg)
|
||||||
|
|
Loading…
Reference in New Issue