Metadata-Version: 2.4
Name: muxu-io-mqtt-logger
Version: 1.3.0
Summary: A logger that logs messages to an MQTT topic with systemd journal integration
Home-page: https://github.com/muxu-io/mqtt-logger
Author: Alex Gonzalez
Author-email: Alex Gonzalez <alex@muxu.io>
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Logging
Classifier: Topic :: Communications
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: paho-mqtt>=1.6.1
Requires-Dist: systemd-python<235,>=234
Requires-Dist: muxu-io-mqtt-connector
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: bandit[toml]>=1.7.0; extra == "dev"
Requires-Dist: pip-audit>=2.6.0; extra == "dev"
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# MQTT Logger

MQTT Logger is a Python package designed for logging messages to an MQTT topic. It provides an easy-to-use interface for connecting to an MQTT broker and logging messages at various levels (debug, info, warning, error, critical). The logger supports batching of log messages and can be used both as a standalone logger and as an asynchronous context manager.

## Features

- Log messages to an MQTT topic.
- Support for multiple logging levels.
- Automatic batching of log messages.
- Asynchronous operation with support for context management.
- Metrics tracking for logging performance.
- Systemd journal integration for structured logging.
- Optional file-based logging.

## Requirements

- Python 3.7+
- systemd development libraries (for systemd journal integration)
- MQTT broker access

## Installation

### System Dependencies

On Ubuntu/Debian systems, install the required systemd development libraries:

```bash
sudo apt-get install libsystemd-dev pkg-config
```

On CentOS/RHEL/Fedora systems:

```bash
sudo yum install systemd-devel pkgconfig
# or on newer versions:
sudo dnf install systemd-devel pkgconfig
```

### Python Package

To install the MQTT Logger package, you can use pip:

```bash
pip install .
```

Note: This package depends on the `muxu-io-mqtt-connector` PyPI package and requires systemd to be available.

Make sure to run this command in the root directory of the project where the `setup.py` file is located.

## Usage

### Basic Usage

You can use the `MqttLogger` class to log messages as follows:

```python
from mqtt_logger.logger import MqttLogger

async def main():
    logger = MqttLogger(
        mqtt_broker="mqtt.example.com",
        mqtt_port=1883,
        mqtt_topic="logs/myapp",
        log_file="app.log"
    )
    await logger.connect_mqtt()
    logger.info("Application started")
    await logger.shutdown()
```

### Context Manager Usage

The `MqttLogger` can also be used as an asynchronous context manager:

```python
from mqtt_logger.logger import MqttLogger

async def main():
    async with MqttLogger(
        mqtt_broker="mqtt.example.com",
        mqtt_port=1883,
        mqtt_topic="logs/myapp"
    ) as logger:
        logger.info("In context manager")
```

## Running Tests

To run the tests for the MQTT Logger, you can use the following command:

```bash
python3 -m venv .venv
source .venv/bin/activate && pip install -r requirements.txt
pytest tests/
```

## License

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