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

Add example log rerouting to Kibana (and Python) to SDP device

parent a2e7d5f5
No related branches found
No related tags found
1 merge request!7Resolve #2021 "03 16 branched from master elk stack"
......@@ -26,10 +26,11 @@ import numpy
from wrappers import only_in_states, only_when_on, fault_on_error
from opcua_connection import OPCUAConnection
from lofar_logging import PythonLoggingMixin
__all__ = ["SDP", "main"]
class SDP(Device):
class SDP(Device, PythonLoggingMixin):
"""
**Properties:**
......@@ -485,4 +486,13 @@ 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()
import logging
def configured_logger(name=''):
logger = logging.getLogger(name)
logger.setLevel(logging.DEBUG)
try:
from logstash_async.handler import AsynchronousLogstashHandler
logger.addHandler(AsynchronousLogstashHandler("elk", 5959, database_path='logstash_test.db'))
except Exception:
logger.exception("Cannot import or configure logstash_async module, not forwarding logs to ELK stack.")
return logger
logger = configured_logger()
class PythonLoggingMixin(object):
""" Also inherit this class to have your Tango Device log to python instead. """
# Monkey patch the python logger to replace the tango logger
debug_stream = logger.debug
info_stream = logger.info
warn_stream = logger.warning
warning_stream = logger.warning
error_stream = logger.error
fatal_stream = logger.fatal
critical_stream = logger.critical
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