diff --git a/README.md b/README.md index 6e26a203bf8f69e6c1b99d2d4882e39cec7aed9f..945bf0e219bb35ed249fb68ac88d6958f18ca2c0 100644 --- a/README.md +++ b/README.md @@ -32,14 +32,10 @@ Note: The options Part may be omitted, as all parts are optional, but using the file: 'File to Append Log to', graylog: { active: 'true or false', - servers: [ - { - server: 'graylog-server', - port: 'graylog-port' - } - ] + server: 'graylog-server', + port: 'graylog-port' }, path: 'Path Logfile located', loglevel: 'Minimal LogLevel. Default: WARN' } -``` \ No newline at end of file +``` diff --git a/index.js b/index.js index a4ce8b15ba487b5a9850879ed213253c2054b3ae..2006486532307905dab8acacb677791117fd19be 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,6 @@ +const udp = require('dgram') +const buffer = require('buffer') + function Log (options) { this.levels = { 'DEBUG': 5, @@ -44,11 +47,7 @@ function Log (options) { } } if (this.options.graylog && this.options.graylog.active) { - this.graylog = require('gelf') - this.graylogger = new this.graylog({ // eslint-disable-line new-cap - graylogHostname: this.options.graylog.servers[0].host, - graylogPort: this.options.graylog.servers[0].port - }) + this.graylog = udp.createSocket('udp4') } this.info = function (message) { @@ -125,28 +124,7 @@ function Log (options) { }) } if (this.options.graylog && this.options.graylog.active) { - switch (tag) { - case 'INFO': - this.graylogEmit(message, 1) - break - case 'NOTICE': - this.graylogEmit(message, 2) - break - case 'WARN': - this.graylogEmit(message, 3) - break - case 'ERROR': - this.graylogEmit(message, 4) - break - case 'FATAL': - this.graylogEmit(message, 5) - break - case 'DEBUG': - this.graylogEmit(message, 0) - break - default: - this.graylogEmit(message, 1) - } + this.graylogSend(message, tag) } return msg } @@ -155,13 +133,14 @@ function Log (options) { var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1) return localISOTime.split('.')[0].trim() } - this.graylogEmit = function (message, level) { - this.graylogger.emit('gelf.log', { - "short_message": message, - "timestamp": Date.now() / 1000, - "level": level, - "facility": this.name, - }) + 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.graylog.port,this.graylog.server,function(error){}) } return this } diff --git a/package.json b/package.json index 0f1958c472f602ac8c98620c810362f078184457..50b872d723a4fd073b1bdf1e6db49f85e8b95740 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,7 @@ "type": "git", "url": "https://gitlab.br.de/general/log" }, - "dependencies": { - "gelf": "^2.0.1" - }, + "dependencies": {}, "devDependencies": { "jest": "^25.3.0" },