Skip to main content

Async Logger

Async Logger is a custom Python logging library designed to log messages asynchronously to both the console and Elasticsearch. It is built on top of Python's logging module and integrates with Elasticsearch using the AsyncElasticsearch client. This allows for non-blocking, asynchronous logging in distributed environments.

Features

  • Asynchronous logging to Elasticsearch.
  • Buffered log messages with periodic flushing to avoid performance hits.
  • Customizable logging levels (DEBUG, INFO, WARNING, ERROR, CRITICAL).
  • Integrated console logging.

Installation

Install the package using pip:

pip install async_elastic_logger

Usage

Here’s an example of how to use AsyncLogger in your Python application.

1. Define your configuration class using pydantic

You'll need to use pydantic to define a settings class that contains your Elasticsearch configurations.

from pydantic import BaseSettings

class ElasticLoggerConfig(BaseSettings):
    elastic_url: str
    elastic_username: str
    elastic_password: str
    elastic_log_level: str = "WARNING"
    elastic_log_index_name: str = "logs"

2. Use the get_logger function to get the singleton logger

Once you have the configuration, you can get the logger instance using the get_logger function. The logger is created as a singleton, so the same instance will be returned every time you call get_logger.

from async_logger.logger import get_logger, ElasticLoggerConfig

# Define your Elasticsearch logger configurations
config = ElasticLoggerConfig(
    elastic_url="https://your-elasticsearch-url",
    elastic_username="your-username",
    elastic_password="your-password",
    elastic_log_level="INFO",  # or DEBUG, ERROR, etc.
    elastic_log_index_name="your-log-index"
)

# Get the singleton logger instance
logger = get_logger(config)

# Log messages
await logger.info("This is an info message")
await logger.error("This is an error message")
await logger.debug("This is a debug message")

3. Handling log levels

You can specify the logging level for Elasticsearch logs using the elastic_log_level field in your configuration. It accepts values like DEBUG, INFO, WARNING, ERROR, or CRITICAL.

For example:

config = ElasticLoggerConfig(
    elastic_url="https://your-elasticsearch-url",
    elastic_username="your-username",
    elastic_password="your-password",
    elastic_log_level="DEBUG",  # Logs at DEBUG level
    elastic_log_index_name="your-log-index"
)

4. Configuration flexibility

You can easily switch the log level or Elasticsearch index by updating the configuration parameters. This allows you to fine-tune logging based on the environment or the level of detail you want in your logs.

5. Singleton behavior

Once the logger is instantiated with the configuration, subsequent calls to get_logger will return the same instance, ensuring that logging across your application is handled consistently.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Metadata

Release files for async-elastic-logger 0.4.5.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-elastic-logger 0.4.5.1.4
File Size Uploaded Provenance
async_elastic_logger-0.4.5.1.4.tar.gz 5.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for async-elastic-logger 0.4.5.1.4
File Interpreter ABI Platform
async_elastic_logger-0.4.5.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / async_elastic_logger-0.4.5.1.4.tar.gz

Download URL async_elastic_logger-0.4.5.1.4.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
716741ed6811f01a6840899be8e12e1f2507f5605392b912b31e8ff6fa876532
BLAKE2b-256 checksum
How to use checksums
41695a3cb2f9cdbc7f46d3edf9d521a506fce33461e623e989784083aeb38a98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / async_elastic_logger-0.4.5.1.4-py3-none-any.whl

Download URL async_elastic_logger-0.4.5.1.4-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f322ed57e105a527cb992512fb5ac7b96ec7d9f42d0d170fb38de39329e4ff5
BLAKE2b-256 checksum
How to use checksums
ad6daba5b5d3f319ded406c97b0fa038e55820a0e94fb8bfa03b676139dad71a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Security for async-elastic-logger 0.4.5.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page