{"id":25198029,"url":"https://github.com/danedens/mqttloghandler","last_synced_at":"2025-05-08T22:42:19.668Z","repository":{"id":259232082,"uuid":"877411642","full_name":"DanEdens/mqttloghandler","owner":"DanEdens","description":"An example project for adding an mqtt log handler to the python logging lib ","archived":false,"fork":false,"pushed_at":"2024-10-23T16:30:21.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T22:42:16.551Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanEdens.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-23T15:50:33.000Z","updated_at":"2024-10-23T16:30:24.000Z","dependencies_parsed_at":"2024-10-23T18:32:39.025Z","dependency_job_id":"a32973df-7947-47ad-b995-794fd877cf46","html_url":"https://github.com/DanEdens/mqttloghandler","commit_stats":null,"previous_names":["danedens/mqttloghandler"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanEdens%2Fmqttloghandler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanEdens%2Fmqttloghandler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanEdens%2Fmqttloghandler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanEdens%2Fmqttloghandler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanEdens","download_url":"https://codeload.github.com/DanEdens/mqttloghandler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253160727,"owners_count":21863624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-10T02:40:33.204Z","updated_at":"2025-05-08T22:42:19.648Z","avatar_url":"https://github.com/DanEdens.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mqttlogger\n\n`mqttlogger` is a Python package that provides a custom logging handler to publish log messages to an MQTT broker. This is useful for centralizing log messages from distributed systems for monitoring and debugging purposes.\n\n## Features\n\n- Publish log messages to an MQTT broker.\n- Configurable MQTT connection settings.\n- Supports logging to both MQTT and local files.\n\n## Installation\n\nYou can install `mqttlogger` via pip:\n\n```\npip install mqttlogger\n```\n\n## Usage\n\nHere's a basic example of how to use `mqttlogger` in your Python application:\n\n```python\nimport logging\nfrom mqttlogger import makeLogger\n\n# Create a logger\nlogger = makeLogger(name='myapp', log_to_file=True, log_level='DEBUG')\n\n# Log messages\nlogger.info(\"This is an info message\")\nlogger.debug(\"This is a debug message\")\nlogger.warning(\"This is a warning message\")\n```\n\n## Singleton Logger\n\nThe `makeLogger` function returns a logger that acts as a singleton. This means that once a logger is created with specific setup values, you can retrieve the same logger instance elsewhere in your application without needing to re-specify those values. This is particularly useful for maintaining consistent logging behavior across different modules or components of your application.\n\nTo retrieve the logger again, simply call `logging.getLogger` with the same name:\n\n```python\n# Retrieve the existing logger instance\nlogger = logging.getLogger('myapp')\n\n# Continue logging\nlogger.info(\"Continuing to log with the same logger instance\")\n```\n\n## Testing\n\nTo test `mqttlogger` with a local Mosquitto broker, follow these steps:\n\n### Prerequisites\n\nEnsure that Mosquitto is installed on your system. You can install it using a package manager:\n\n- **On Ubuntu/Debian**:\n  ```bash\n  sudo apt-get update\n  sudo apt-get install mosquitto mosquitto-clients\n  ```\n\n- **On macOS** (using Homebrew):\n  ```bash\n  brew install mosquitto\n  ```\n\n### Running the Test\n\n1. **Start the Mosquitto Broker**: The test script will automatically start a local Mosquitto broker.\n\n2. **Run the Test Script**: Execute the test script to verify that `mqttlogger` is working correctly with the Mosquitto broker.\n\n   ```bash\n   python test_mqttlogger.py\n   ```\n\n   This script will start the broker, send a test log message, and then stop the broker.\n\n## Configuration\n\nThe `mqttHandler` class allows you to configure various MQTT connection settings, such as:\n\n- `hostname`: The MQTT broker's hostname or IP address.\n- `port`: The port number to connect to the MQTT broker.\n- `topic`: The MQTT topic to publish messages to.\n- `qos`: The quality of service level for message delivery.\n- `retain`: Whether the broker should retain the last message sent to the topic.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request or open an issue.\n\n## Author\n\nDan Edens - [your.email@example.com](mailto:your.email@example.com)\n\n## Acknowledgments\n\n- [paho-mqtt](https://pypi.org/project/paho-mqtt/) for MQTT client functionality.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanedens%2Fmqttloghandler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanedens%2Fmqttloghandler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanedens%2Fmqttloghandler/lists"}