Metadata-Version: 2.1
Name: infi-logger
Version: 0.0.7
Summary: Logger package for infinity team
Author: Infinity Team
License: MIT
Description-Content-Type: text/markdown
Requires-Dist: certifi==2023.7.22; python_version >= "3.6"
Requires-Dist: colorama==0.4.6; sys_platform == "win32"
Requires-Dist: elastic-transport==8.10.0; python_version >= "3.6"
Requires-Dist: elasticsearch==8.10.1; python_version >= "3.6" and python_version < "4"
Requires-Dist: iniconfig==2.0.0; python_version >= "3.7"
Requires-Dist: packaging==23.2; python_version >= "3.7"
Requires-Dist: pluggy==1.3.0; python_version >= "3.8"
Requires-Dist: pytest==7.4.3; python_version >= "3.7"
Requires-Dist: python-dotenv==1.0.0; python_version >= "3.8"
Requires-Dist: urllib3==2.0.7; python_version >= "3.7"

# 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](dist/infi_logger-1.0-py3-none-any.whl) attached to this repository should be taken,
Attach to the project where it will be used
and install with:

```bash
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

```bash
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:

1. Import the `ElasticLogger` class:

    ```python
   from infi_logger import ElasticLogger
    ```

2. Create an instance of the ElasticLogger class, providing a service name, host, cert_fingerprint, name and password:
   
   ```python
    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:

    ```python
    logger = ElasticLogger("my-service")
    ```
   

3. Use the different log levels to send logs:

   ```python
    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


1. **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.

2. **Log Format**

   The logs sent to Elasticsearch have the following format:

   ```json
   {
    "timestamp": "<current_timestamp>",
    "message": "<log_message>",
    "level": "<log_level>",
    "service": "<service_name>"
    }
    ```

3. **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
