mqttloghandler


Namemqttloghandler JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/DanEdens/mqttloghandler
SummaryA custom logging handler that publishes messages to an MQTT broker.
upload_time2024-10-23 16:26:10
maintainerNone
docs_urlNone
authorDan Edens
requires_python>=3.7
licenseMIT
keywords mqtt logging handler
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # mqttlogger

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

## Features

- Publish log messages to an MQTT broker.
- Configurable MQTT connection settings.
- Supports logging to both MQTT and local files.

## Installation

You can install `mqttlogger` via pip:

```
pip install mqttlogger
```

## Usage

Here's a basic example of how to use `mqttlogger` in your Python application:

```python
import logging
from mqttlogger import makeLogger

# Create a logger
logger = makeLogger(name='myapp', log_to_file=True, log_level='DEBUG')

# Log messages
logger.info("This is an info message")
logger.debug("This is a debug message")
logger.warning("This is a warning message")
```

## Singleton Logger

The `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.

To retrieve the logger again, simply call `logging.getLogger` with the same name:

```python
# Retrieve the existing logger instance
logger = logging.getLogger('myapp')

# Continue logging
logger.info("Continuing to log with the same logger instance")
```

## Testing

To test `mqttlogger` with a local Mosquitto broker, follow these steps:

### Prerequisites

Ensure that Mosquitto is installed on your system. You can install it using a package manager:

- **On Ubuntu/Debian**:
  ```bash
  sudo apt-get update
  sudo apt-get install mosquitto mosquitto-clients
  ```

- **On macOS** (using Homebrew):
  ```bash
  brew install mosquitto
  ```

### Running the Test

1. **Start the Mosquitto Broker**: The test script will automatically start a local Mosquitto broker.

2. **Run the Test Script**: Execute the test script to verify that `mqttlogger` is working correctly with the Mosquitto broker.

   ```bash
   python test_mqttlogger.py
   ```

   This script will start the broker, send a test log message, and then stop the broker.

## Configuration

The `mqttHandler` class allows you to configure various MQTT connection settings, such as:

- `hostname`: The MQTT broker's hostname or IP address.
- `port`: The port number to connect to the MQTT broker.
- `topic`: The MQTT topic to publish messages to.
- `qos`: The quality of service level for message delivery.
- `retain`: Whether the broker should retain the last message sent to the topic.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue.

## Author

Dan Edens - [your.email@example.com](mailto:your.email@example.com)

## Acknowledgments

- [paho-mqtt](https://pypi.org/project/paho-mqtt/) for MQTT client functionality.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/DanEdens/mqttloghandler",
    "name": "mqttloghandler",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "mqtt logging handler",
    "author": "Dan Edens",
    "author_email": "danedens31@gmail.com",
    "download_url": null,
    "platform": null,
    "description": "# 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",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A custom logging handler that publishes messages to an MQTT broker.",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/DanEdens/mqttloghandler"
    },
    "split_keywords": [
        "mqtt",
        "logging",
        "handler"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2c2f419618522633121955ab5a538f9fda424bc06f20be1388562cec9dc398b4",
                "md5": "c0d2ccf58a5023db2d8049b85bdff93e",
                "sha256": "981e38e0d8f714670c10553ca03a5ece12073e986c638c34b920a7d3e6d67efe"
            },
            "downloads": -1,
            "filename": "mqttloghandler-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c0d2ccf58a5023db2d8049b85bdff93e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 2646,
            "upload_time": "2024-10-23T16:26:10",
            "upload_time_iso_8601": "2024-10-23T16:26:10.005113Z",
            "url": "https://files.pythonhosted.org/packages/2c/2f/419618522633121955ab5a538f9fda424bc06f20be1388562cec9dc398b4/mqttloghandler-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-23 16:26:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "DanEdens",
    "github_project": "mqttloghandler",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mqttloghandler"
}
        
Elapsed time: 0.36162s