From 280d20613e80b9c2e11a77eed74591174708e5ae Mon Sep 17 00:00:00 2001 From: Dominik Sigmund <dominik.sigmund@br.de> Date: Fri, 8 May 2020 09:16:04 +0200 Subject: [PATCH] revisit --- index.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 1491b5c..90e2a5a 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ const udp = require('dgram') const buffer = require('buffer') +const graylog = udp.createSocket('udp4') function Log (options) { this.levels = { @@ -46,10 +47,6 @@ function Log (options) { } } } - if (this.options.graylog && this.options.graylog.active) { - this.graylog = udp.createSocket('udp4') - } - this.info = function (message) { if (this.loglevel >= this.levels.INFO) { return this.log('INFO', message) @@ -124,7 +121,13 @@ function Log (options) { }) } if (this.options.graylog && this.options.graylog.active) { - this.graylogSend(message, tag) + graylog.send(Buffer.from(JSON.stringify({ + short_message: message, + timestamp: Date.now() / 1000, + hostname: this.hostname, + facility: this.name, + level:tag + })), this.options.graylog.port, this.options.graylog.server, function(error){}) } return msg } @@ -133,15 +136,6 @@ function Log (options) { var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1) return localISOTime.split('.')[0].trim() } - this.graylogSend = function (message, level) { - this.graylog.send(Buffer.from(JSON.stringify({ - short_message: message, - timestamp: Date.now() / 1000, - hostname: this.hostname, - facility: this.name, - level:level - })),this.options.graylog.port,this.options.graylog.server,function(error){}) - } return this } module.exports = Log -- GitLab