-
-
Notifications
You must be signed in to change notification settings - Fork 1
Quick Start
Eduardo Aguilar Yépez edited this page Jun 26, 2021
·
1 revision
Elasticlogger use the standard python logging package and the python_json_logger package to get a standardized logger that can be compatible with Elastic Search.
The way to create a simple logger is by following the next example:
import logging
from elasticlogger import Logger
logger = Logger("test-logger", level=logging.DEBUG)
This will create a logger instance with DEBUG level and you can simply log like this:
logger.debug("test logger message")
# {"message": "test logger message", "levelname": "DEBUG", "name": "test-logger"}
To enable the Elastic Search integration you need to call the next function with params
url
and index
, where endpoint is the elastic cluster url and the index will be
the default index where the logs will be stored.
# Setup the ElasticSearch endpoint of your cluster and the default index
logger.enable_elastic(url="https://elastic-cluster.com", index="test-index")
# You can simply call the function and the data will be take from the env vars
# ELASTICSEARCH_URL and ELASTICSEARCH_INDEX
logger.enable_elastic()