Created
February 22, 2021 09:24
-
-
Save cham11ng/f68eb9e51f0688efc23a4f1d75f95a28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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