python client for https://github.com/ausward/QTLogs
Project description
QT Py Logs
A Python client for publishing log messages to an MQTT broker, designed to work with the QTLogs project. 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:
poetry add qt-py-logs
Or using pip:
pip install qt-py-logs
Usage
The SetupLogger function allows you to configure the logger. You can either pass in all the configuration details directly as arguments or provide a path to a YAML configuration file.
Option 1: Configuring with Python arguments
Set up the logger with your MQTT broker details by passing the topic, broker, port, and source directly:
from qt_py_logs import SetupLogger
logger = SetupLogger(
topic="your/mqtt/topic",
broker="your_mqtt_broker.com",
port=1883,
source="your_application_name"
)
Option 2: Configuring with a YAML file
Alternatively, you can configure the logger using a YAML file. Create a config.yaml file (or any other name) with the following structure:
topic: "your/mqtt/topic"
broker: "your_mqtt_broker.com"
port: 1883
source: "your_application_name"
Then, set up the logger by providing the path to your YAML configuration file using the config_path argument:
from qt_py_logs import SetupLogger
logger = SetupLogger(config_path="path/to/your/config.yaml")
The logger will automatically watch for changes in the YAML file and reload the configuration in real-time, so you don't need to restart your application.
Once the logger is set up using either method, you can use the logger instance to log messages from anywhere in your application:
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:
{
"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 file for details.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qt_py_logs-0.2.0.tar.gz.
File metadata
- Download URL: qt_py_logs-0.2.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/25.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26e2f91fb9a600025aa3d723f46239c0b699b2e682ed62dc799bb2722e5ad376
|
|
| MD5 |
e1332b79bfaa538ca86adec085a947a5
|
|
| BLAKE2b-256 |
4646f61e33cea966f7d20fbee10019d762ccb34a28041f1413c5c81ea5f5f9df
|
File details
Details for the file qt_py_logs-0.2.0-py3-none-any.whl.
File metadata
- Download URL: qt_py_logs-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.14.0 Darwin/25.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e7eea23760d14e812a15c87d9ffc65141b52b48ea4f6362cb63aa957476c4e1
|
|
| MD5 |
7f19c85ee18ca9de865f0671a94b4f84
|
|
| BLAKE2b-256 |
e5128c696d6e3a5f3721822ff301098f99ab7fafd4f25769a21d8f781df28fda
|