Logger package for infinity team
Project description
infinity-elastic-logs
This project is a Python logging library that integrates with Elasticsearch for centralized logging. It provides a simple and convenient way to send logs to Elasticsearch with different log levels.
Installation
The binary installation file attached to this repository should be taken, Attach to the project where it will be used and install with:
pip install path_to_this_project/dist/infi_logger-1.0-py3-none-any.whl
Alternatively, you can move in cmd to this project and just write in
pip install .
Replace path_to_this_project with the path where the file is located in your project.
Usage
To use the logging library, follow these steps:
-
Import the
ElasticLogger
class:from infi_logger import ElasticLogger
-
Create an instance of the ElasticLogger class, providing a service name, host, cert_fingerprint, name and password:
HOST = "${Ip:Port}" CERT_FINGERPRINT = "${fingerprint}" NAME = "${Username}" PASSWORD = "${Password}" INDEX = "${IndexName}" # Replace with the index you want to work with # logger = ElasticLogger("my-service") logger = ElasticLogger("elastic-service", HOST, CERT_FINGERPRINT, NAME, PASSWORD, INDEX)
Alternatively, you can create an instance of the ElasticLogger class that will not connect Elastic, providing a service name only:
logger = ElasticLogger("my-service")
-
Use the different log levels to send logs:
logger.debug("This is a debug log") logger.info("This is an info log") logger.warning("This is a warning log") logger.error("This is an error log") logger.critical("This is a critical log")
Configuration
-
Elasticsearch Connection
The ElasticsearchConnection class handles the connection to Elasticsearch. Ensure that the environment variables mentioned above are correctly set before running the project. The connect_elasticsearch method establishes a connection to Elasticsearch using the provided credentials. If the connection fails, an exception will be raised.
-
Log Format
The logs sent to Elasticsearch have the following format:
{ "timestamp": "<current_timestamp>", "message": "<log_message>", "level": "<log_level>", "service": "<service_name>" }
-
Environment Variables
You can set the location of log files in case Elastic failed/not connected by setting global environment of "LOG_FILE". If not chosen, it will default to "logs/log.log" in your current directory
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file infi_logger-0.0.7.tar.gz
.
File metadata
- Download URL: infi_logger-0.0.7.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd2018e62a43796f8e9db5113e76bf4f1937b66e025116add66e203704cbbb22 |
|
MD5 | 522eb0480e87ee1c120f8e195b8fd780 |
|
BLAKE2b-256 | bacb27f5b95536f85643ca8477c0383e8cf31880389e64cd612ae049fffb5712 |
File details
Details for the file infi_logger-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: infi_logger-0.0.7-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2b4ccdae85dda7717c10e4f6ad500ac5a3e87fdaf4db0727675b8a6b668d901 |
|
MD5 | 6c046ab2e2633890e3ca03a7b432d7c8 |
|
BLAKE2b-256 | e9a275ab7a2b7f57d1d8e9b99e86d5313deda7fbe483508f65570d554f9fad1f |