node-live-log
v2.0.2
Published
Module to generate logs in real time through socket.io
Downloads
84
Maintainers
Readme
Node live log
Module to generate logs in real time through socket.io.
Install
npm i node-live-log
Usage
In your application
const log = require("node-live-log")("Your module name or identifier");
log.info("Log with args", "Arg1", "Arg2", "...Args");
log.warn(`Warn log`);
log.error("Error log");
log.debug("Debug log");
To view the logs generated by your application you need to write a client. Basically you can do:
const io = require("socket.io-client");
const client = io("ws://localhost:3010");
client.on("log-info", (msg) => {
console.log(msg);
});
client.on("log-warn", (msg) => {
console.log(msg);
});
client.on("log-error", (msg) => {
console.log(msg);
});
client.on("log-debug", (msg) => {
console.log(msg);
});
You can consult a more advanced example at this link advanced client
Advanced Settings
(this is optional) You can create a .env.log
file in the root of your project with the following options:
LOG_PORT=3010 # Port that the log server will open for client connections, by default its is 3010
LOG_HOST='127.0.0.1' # Host address where the server will run, by default it is localhost.
LOG_DATE_FORMAT='DD-MM-YYYY HH:mm:ss.SSS' # Date format that the log will display, by default it is 'dd-MM-YYYY HH:mm:ss.SSS'
LOG_LEVEL='error' # log level that the console should display, default is error.