diff options
author | Tulio Casagrande <tcasagra@thoughtworks.com> | 2017-02-07 14:52:43 -0200 |
---|---|---|
committer | Tulio Casagrande <tcasagra@thoughtworks.com> | 2017-02-07 14:52:43 -0200 |
commit | d4ef82a55053a0a672935104dda2a06eae8579ac (patch) | |
tree | 07237139979caeeb9ae9a4815ce62ac3b1b6721c | |
parent | 674999874136714be031db8c31432eb2a4d50c2e (diff) |
[#952] Log events even when formatting errors occur
-rw-r--r-- | service/pixelated/config/logger.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/service/pixelated/config/logger.py b/service/pixelated/config/logger.py index c4d2dc76..6a4b76d0 100644 --- a/service/pixelated/config/logger.py +++ b/service/pixelated/config/logger.py @@ -42,11 +42,14 @@ def init(debug=False): logging.getLogger('gnupg').addFilter(PrivateKeyFilter()) def formatter(event): - event['log_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(event['log_time'])) - event['log_level'] = event['log_level'].name.upper() - event['log_format'] = event.get('log_format') or '' - logstring = u'{log_time} [{log_namespace}] {log_level} ' + event['log_format'] + '\n' - return logstring.format(**event) + try: + event['log_time'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(event['log_time'])) + event['log_level'] = event['log_level'].name.upper() + event['log_format'] = event.get('log_format') or '' + logstring = u'{log_time} [{log_namespace}] {log_level} ' + event['log_format'] + '\n' + return logstring.format(**event) + except Exception as e: + return "Error while formatting log event: {!r}\nOriginal event: {!r}\n".format(e, event) observers = [FileLogObserver(sys.stdout, formatter)] globalLogBeginner.beginLoggingTo(observers) |