[openstack-dev] Less of coding standard for i18n of LOG messages
Eric Windisch
eric at cloudscaling.com
Wed Nov 7 18:10:50 UTC 2012
>
> It can't match strings that have already been formatted. It can only do
> so unformatted.
>
> We have more information in HACKING.rst about why the order matters.
>
I was implying that we could have the logging system do the formatting and i18n for us, rather than just the formatting. Clearly, the i18n would have to be applied before formatting. Perhaps it is better we do this explicitly, but we're also seeing that developers just aren't doing it consistently.
For example in openstack.common.log, we could do something like:
+class IntlLogRecord(LogRecord):
+ def getMessage(self):
+ return _(self.msg) % self.args
+
+
+class IntlLogger(logging.Logger):
+ def makeRecord(*args):
+ rv = IntlLogRecord(None, None, "", 0, "", (), None, None) + rv.__dict__.update(dict) + return rv
+
+
def setup(product_name):
"""Setup logging."""
sys.excepthook = _create_logging_excepthook(product_name)
+ logging.setLoggerClass(IntlLogger)
if CONF.log_config:
try:
logging.config.fileConfig(CONF.log_config)
except Exception:
traceback.print_exc()
raise
else:
_setup_logging_from_conf(product_name)
Regards,
Eric Windisch
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20121107/5a9e74e4/attachment-0001.html>
More information about the OpenStack-dev
mailing list