Skip to content

Commit

Permalink
Applied auto-formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bnazare committed Nov 11, 2024
1 parent 11f658b commit c74db80
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pycti/utils/opencti_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os

from pygelf import GelfUdpHandler, GelfTcpHandler
from pygelf import GelfTcpHandler, GelfUdpHandler
from pythonjsonlogger import jsonlogger


Expand Down Expand Up @@ -34,8 +34,15 @@ def filter(self, record):
return True


def logger(level, json_logging=True, graylog_host=None, graylog_port=None, graylog_adapter=None,
log_shipping_level=None, log_shipping_env_var_prefix=None):
def logger(
level,
json_logging=True,
graylog_host=None,
graylog_port=None,
graylog_adapter=None,
log_shipping_level=None,
log_shipping_env_var_prefix=None,
):
# Exceptions
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("pika").setLevel(logging.ERROR)
Expand All @@ -51,14 +58,21 @@ def logger(level, json_logging=True, graylog_host=None, graylog_port=None, grayl

if graylog_host is not None:
if graylog_adapter == "tcp":
shipping_handler = GelfTcpHandler(host=graylog_host, port=graylog_port, include_extra_fields=True)
shipping_handler = GelfTcpHandler(
host=graylog_host, port=graylog_port, include_extra_fields=True
)
else:
shipping_handler = GelfUdpHandler(host=graylog_host, port=graylog_port, include_extra_fields=True)
shipping_handler = GelfUdpHandler(
host=graylog_host, port=graylog_port, include_extra_fields=True
)
shipping_handler.setLevel(log_shipping_level)

if log_shipping_env_var_prefix is not None:
filtered_env = [(k.removeprefix(log_shipping_env_var_prefix), v) for k, v in os.environ.items()
if k.startswith(log_shipping_env_var_prefix)]
filtered_env = [
(k.removeprefix(log_shipping_env_var_prefix), v)
for k, v in os.environ.items()
if k.startswith(log_shipping_env_var_prefix)
]
shipping_filter = ContextFilter(filtered_env)
shipping_handler.addFilter(shipping_filter)

Expand Down

0 comments on commit c74db80

Please sign in to comment.