Skip to content
Snippets Groups Projects
Commit 3f639daf authored by Jan David Mol's avatar Jan David Mol
Browse files

Removed straying dev code, use our logging format

parent e5f6d371
No related branches found
No related tags found
1 merge request!7Resolve #2021 "03 16 branched from master elk stack"
...@@ -489,13 +489,4 @@ def main(args=None, **kwargs): ...@@ -489,13 +489,4 @@ def main(args=None, **kwargs):
if __name__ == '__main__': if __name__ == '__main__':
x = Device.error_stream
def new_error_stream(self, *args, **kwargs):
print("logging to python")
logger.error(*args, **kwargs)
print("logging to tango")
x.error_stream(self, *args, **kwargs)
Device.error_stream = new_error_stream
main() main()
import logging import logging
from functools import wraps from functools import wraps
# Always also log the hostname because it makes the origin of the log clear.
import socket
hostname = socket.gethostname()
def configure_logger(logger: logging.Logger, log_extra=None): def configure_logger(logger: logging.Logger, log_extra=None):
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
...@@ -16,6 +20,15 @@ def configure_logger(logger: logging.Logger, log_extra=None): ...@@ -16,6 +20,15 @@ def configure_logger(logger: logging.Logger, log_extra=None):
# install the handler # install the handler
logger.addHandler(handler) logger.addHandler(handler)
# for now, also log to stderr
# Set up logging in a way that it can be understood by a human reader, be
# easily grep'ed, be parsed with a couple of shell commands and
# easily fed into an Kibana/Elastic search system.
handler = logging.StreamHandler()
formatter = logging.Formatter(fmt = '%(asctime)s.%(msecs)d %(levelname)s - HOST="{}" PID="%(process)d" TNAME="%(threadName)s" TID="%(thread)d" FILE="%(pathname)s" LINE="%(lineno)d" FUNC="%(funcName)s" MSG="%(message)s"'.format(hostname), datefmt = '%Y-%m-%dT%H:%M:%S')
handler.setFormatter(formatter)
logger.addHandler(handler)
except Exception: except Exception:
logger.exception("Cannot import or configure logstash_async module, not forwarding logs to ELK stack.") logger.exception("Cannot import or configure logstash_async module, not forwarding logs to ELK stack.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment