mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #46867 from terminalmage/unicode-logging-normalization
Backport string arg normalization to 2017.7 branch
This commit is contained in:
commit
d9770bf3f8
@ -337,15 +337,16 @@ class SaltLoggingClass(six.with_metaclass(LoggingMixInMeta, LOGGING_LOGGER_CLASS
|
||||
# If nothing else is in extra, make it None
|
||||
extra = None
|
||||
|
||||
salt_system_encoding = __salt_system_encoding__
|
||||
if salt_system_encoding == 'ascii':
|
||||
# Encoding detection most likely failed, let's use the utf-8
|
||||
# value which we defaulted before __salt_system_encoding__ was
|
||||
# implemented
|
||||
salt_system_encoding = 'utf-8'
|
||||
|
||||
# Let's try to make every logging message unicode
|
||||
if isinstance(msg, six.string_types) \
|
||||
and not isinstance(msg, six.text_type):
|
||||
salt_system_encoding = __salt_system_encoding__
|
||||
if salt_system_encoding == 'ascii':
|
||||
# Encoding detection most likely failed, let's use the utf-8
|
||||
# value which we defaulted before __salt_system_encoding__ was
|
||||
# implemented
|
||||
salt_system_encoding = 'utf-8'
|
||||
try:
|
||||
_msg = msg.decode(salt_system_encoding, 'replace')
|
||||
except UnicodeDecodeError:
|
||||
@ -353,11 +354,23 @@ class SaltLoggingClass(six.with_metaclass(LoggingMixInMeta, LOGGING_LOGGER_CLASS
|
||||
else:
|
||||
_msg = msg
|
||||
|
||||
_args = []
|
||||
for item in args:
|
||||
if isinstance(item, six.string_types) \
|
||||
and not isinstance(item, six.text_type):
|
||||
try:
|
||||
_args.append(item.decode(salt_system_encoding, 'replace'))
|
||||
except UnicodeDecodeError:
|
||||
_args.append(item.decode(salt_system_encoding, 'ignore'))
|
||||
else:
|
||||
_args.append(item)
|
||||
_args = tuple(_args)
|
||||
|
||||
if six.PY3:
|
||||
logrecord = _LOG_RECORD_FACTORY(name, level, fn, lno, _msg, args,
|
||||
logrecord = _LOG_RECORD_FACTORY(name, level, fn, lno, _msg, _args,
|
||||
exc_info, func, sinfo)
|
||||
else:
|
||||
logrecord = _LOG_RECORD_FACTORY(name, level, fn, lno, _msg, args,
|
||||
logrecord = _LOG_RECORD_FACTORY(name, level, fn, lno, _msg, _args,
|
||||
exc_info, func)
|
||||
|
||||
if extra is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user