Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
async-elastic-logger
Advanced tools
A custom asynchronous logging library with Elasticsearch integration.
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.
Install the package using pip:
pip install async_elastic_logger
Here’s an example of how to use AsyncLogger
in your Python application.
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"
get_logger
function to get the singleton loggerOnce 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")
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"
)
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.
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.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
A custom asynchronous logging library with Elasticsearch integration.
We found that async-elastic-logger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.