This is a lightweight and efficient logger designed for Node.js applications, utilizing MQTT to provide centralized log management. It's particularly suitable for distributed systems where traceability and log persistence are crucial. The logger ensures easy integration with any MQTT client and offers a straightforward interface for initializing the logger and logging messages.
- Centralized Logging: Utilizes MQTT for log management, enabling centralized storage and analysis.
- Easy Integration: Compatible with any standard MQTT client.
- Scalable: Designed to handle high throughput and large volumes of log data efficiently.
- Singleton Pattern: Prevents multiple instances to ensure consistent logging throughout the application.
Install the package via npm:
npm install node-log-mqtt
Here is a quick guide on how to use the Node MQTT Logger in your project:
First, import the package into your Node.js application:
const { Logger, MQTTClient } = require('node-log-mqtt');
Create and configure the MQTT client as follows:
const mqttClient = new MQTTClient();
mqttClient.host = 'mqtt.fabris.io';
mqttClient.port = 8883;
mqttClient.protocol = MQTTClient.Protocol.MQTTS;
mqttClient.certificateManager.loadCertificates(
'authority.pem',
'certificate.pem',
'key.pem'
);
mqttClient.connect();
Initialize the logger with the configured MQTT client:
Logger.initialize(mqttClient);
To log messages, simply call the log
method:
Logger.log('This is a test message', '/debug');
The logger will prepend a timestamp to your message and publish it to the MQTT topic specified.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Paolo Fabris - Initial work - ubyte.it
See also the list of contributors who participated in this project.
This project is licensed under the MIT License. See the LICENSE file for details.