Skip to content

Elasticsearch ​

ElasticsearchSink indexes log entries into Elasticsearch. Uses the official client if available, otherwise falls back to raw HTTP.

Installation ​

This integration requires the elasticsearch package.

bash
uv add logly[elasticsearch]
bash
pip install "logly[elasticsearch]"
bash
uv add elasticsearch
bash
pip install elasticsearch

Missing Dependency

If elasticsearch is not installed, you'll see:

ModuleNotFoundError: No module named 'elasticsearch'

Usage ​

python
from logly import logger
from logly.integrations.elasticsearch import ElasticsearchSink

logger.add(
    ElasticsearchSink(
        "http://localhost:9200",
        index="logs-{time:YYYY.MM.DD}",
    ),
    level="WARNING",
)

Configuration ​

ParameterDefaultDescription
endpointhttp://localhost:9200Elasticsearch URL
indexlogly-logsIndex name pattern
timeout5.0HTTP request timeout in seconds
usernameNoneOptional basic auth username
passwordNoneOptional basic auth password

Full Example ​

python
from logly import logger
from logly.integrations.elasticsearch import ElasticsearchSink

logger.add(
    ElasticsearchSink(
        endpoint="http://elasticsearch:9200",
        index="myapp-logs-{time:YYYY.MM.DD}",
        timeout=10.0,
        username="elastic",
        password="changeme",
    ),
    level="INFO",
)

logger.info("User registered", user_id=456)
logger.error("Checkout failed", cart_id="cart-789")

Released under the MIT License.