Skip to content

Instantly share code, notes, and snippets.

@cham11ng
Created February 22, 2021 09:24
Show Gist options
  • Save cham11ng/f68eb9e51f0688efc23a4f1d75f95a28 to your computer and use it in GitHub Desktop.
Save cham11ng/f68eb9e51f0688efc23a4f1d75f95a28 to your computer and use it in GitHub Desktop.
""" Logging utility module. """
import logging
# import logstash
from logstash_async.handler import AsynchronousLogstashHandler
from elasticecslogging.handlers import ElasticECSHandler
from laudio import config
logging.basicConfig(level=config["logging"]["level"], format=config["logging"]["format"])
def get_logger(name=None, **kwargs):
""" Get logger instance. """
logger = logging.getLogger(name)
logger.addHandler(
ElasticECSHandler(
hosts=[{"host": "localhost", "port": 9200}],
auth_type=ElasticECSHandler.AuthType.NO_AUTH,
es_index_name=f"laudio-{kwargs.get('env')}",
es_additional_fields={**kwargs}
)
)
return logger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment