diff options
-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 a1e825a6..bc4ab8d4 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() - 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'] = str(event['log_format']) + '\n' if event.get('log_format') else '' + logstring = u'{log_time} [{log_namespace}] {log_level} ' + event['log_format'] + 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) |