diff options
author | Tulio Casagrande <tcasagra@thoughtworks.com> | 2016-10-05 19:14:10 -0300 |
---|---|---|
committer | Tulio Casagrande <tcasagra@thoughtworks.com> | 2016-10-05 19:14:10 -0300 |
commit | f23945eea7d2716c61d6c1a057ea620b49662afc (patch) | |
tree | 55e106b7a9c6ef3a7ee9c2f39dd43fb96fc6aadd | |
parent | e63f6cfb89a40c7f547d6b75fa208e9a0bc05f36 (diff) |
Setup twisted logger and formatter
-rw-r--r-- | service/pixelated/config/logger.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/service/pixelated/config/logger.py b/service/pixelated/config/logger.py index 47760270..5921a1ca 100644 --- a/service/pixelated/config/logger.py +++ b/service/pixelated/config/logger.py @@ -16,7 +16,9 @@ import logging import os -from twisted.logger import globalLogBeginner, STDLibLogObserver +import sys +import time +from twisted.logger import globalLogBeginner, FileLogObserver class PrivateKeyFilter(logging.Filter): @@ -38,6 +40,12 @@ def init(debug=False): logging.getLogger('gnupg').addFilter(PrivateKeyFilter()) - observers = [STDLibLogObserver()] + 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) + + observers = [FileLogObserver(sys.stdout, formatter)] globalLogBeginner.beginLoggingTo(observers) |