pluto/handler/lib/logstash.py

32 lines
577 B
Python
Raw Normal View History

2022-06-19 17:24:22 +00:00
# Other library imports
import logging
2022-07-15 10:09:54 +00:00
from json import dumps
2022-06-19 17:24:22 +00:00
2022-07-15 10:09:54 +00:00
import logstash
2023-02-09 07:20:00 +00:00
2022-06-19 17:24:22 +00:00
# Project imports
from settings import settings
logger = None
def init_logstash():
global logger
logger = logging.getLogger("ingest")
logger.setLevel(logging.INFO)
logger.addHandler(
logstash.TCPLogstashHandler(
settings.Logstash.Host,
int(settings.Logstash.Port),
version=1,
)
)
def send_logstash(text):
global logger
if logger is not None:
logger.info(dumps(text))
return True
return False