diff --git a/SDP/SDP/SDP.py b/SDP/SDP/SDP.py index ee3209e07c141d3b029198bb148c5d15d920eb4c..88408be0444a98218baa6e73e2e0a43891396561 100644 --- a/SDP/SDP/SDP.py +++ b/SDP/SDP/SDP.py @@ -489,13 +489,4 @@ def main(args=None, **kwargs): 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() diff --git a/SDP/SDP/lofar_logging.py b/SDP/SDP/lofar_logging.py index 5c3996dddeb5094621659b99e8ccae03a263f387..cf43235eb4d56d729f2e690125cd15a9ba884b57 100644 --- a/SDP/SDP/lofar_logging.py +++ b/SDP/SDP/lofar_logging.py @@ -1,6 +1,10 @@ import logging 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): logger.setLevel(logging.DEBUG) @@ -16,6 +20,15 @@ def configure_logger(logger: logging.Logger, log_extra=None): # install the 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: logger.exception("Cannot import or configure logstash_async module, not forwarding logs to ELK stack.")