Metadata-Version: 2.4
Name: qt-py-logs
Version: 0.1.3
Summary: python client for https://github.com/ausward/QTLogs
License: CC NC SA
License-File: LICENSE
Author: Austin
Author-email: 71802516+ausward@users.noreply.github.com
Requires-Python: >=3.8
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
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: Topic :: System :: Logging
Requires-Dist: paho-mqtt (>=2.1.0)
Project-URL: Bug Tracker, https://github.com/ausward/qt-py-logs/issues
Project-URL: Homepage, https://github.com/ausward/qt-py-logs
Project-URL: Repository, https://github.com/ausward/qt-py-logs
Description-Content-Type: text/markdown

# QT Py Logs

A Python client for publishing log messages to an MQTT broker, designed to work with the [QTLogs project](https://github.com/ausward/QTLogs). This package provides a simple, singleton logger that can be used across a Python application to send structured log messages to a specified MQTT topic.

## Installation

Install the package using poetry:

```bash
poetry add qt-py-logs
```

Or using pip:

```bash
pip install qt-py-logs
```

## Usage

First, set up the logger with your MQTT broker details. This only needs to be done once per application.

```python
from qt_py_logs import SetupLogger

logger = SetupLogger(
    topic="your/mqtt/topic",
    broker="your_mqtt_broker.com",
    port=1883,
    source="your_application_name"
)
```

Then, you can use the logger instance to log messages from anywhere in your application:

```python
from qt_py_logs import QTlogger

# Get the logger instance
logger = QTlogger()

# Log a message
logger.log("INFO", "This is an informational message.")
logger.log("ERROR", "This is an error message.")

# If you want to add additional fields to the log message
extra_data = {"user_id": 1234, "operation": "data_processing"}
logger.log("DEBUG", "This is a debug message with extra data.", Extra=extra_data)
```

The log messages will be published to the specified MQTT topic in a JSON format:

```json
{
    "from": "your_application_name",
    "payload": "This is an informational message.",
    "level": "INFO",
    "timestamp": "2025-11-24 10:00:00",
    "caller": "your_function_name"
}
```

## License

This project is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. See the [LICENSE](LICENSE) file for details.

