UNPKG

central-logger

Version:

Centralized logging. It is used to setup a server and a clients. Clients are able to send the logs to the server. Server will store the logs in different files based on its category.

26 lines (21 loc) 619 B
var dgram = require('dgram'); var client = dgram.createSocket('udp4'); function Client(serverHost,port){ this.host = serverHost; this.port = port; } function makeLogObject(level, message, category){ var log = { 'level' : level, 'message' : message, 'category' : category, 'timestamp' : new Date() } return log; } Client.prototype.log = function(level, message, category){ var log = makeLogObject(level, message, category); const msg = Buffer.from(JSON.stringify(log)); client.send(msg, 0, msg.length, this.port, this.host); } module.exports = Client;