Skip to content
Snippets Groups Projects
Commit 8d930ac8 authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

replaced graylog with udp solution

parent b62e6a40
No related branches found
No related tags found
1 merge request!1Update index.test.js, examples/all-options.js, examples/log-to-file.js,...
...@@ -32,12 +32,8 @@ Note: The options Part may be omitted, as all parts are optional, but using the ...@@ -32,12 +32,8 @@ Note: The options Part may be omitted, as all parts are optional, but using the
file: 'File to Append Log to', file: 'File to Append Log to',
graylog: { graylog: {
active: 'true or false', active: 'true or false',
servers: [
{
server: 'graylog-server', server: 'graylog-server',
port: 'graylog-port' port: 'graylog-port'
}
]
}, },
path: 'Path Logfile located', path: 'Path Logfile located',
loglevel: 'Minimal LogLevel. Default: WARN' loglevel: 'Minimal LogLevel. Default: WARN'
......
const udp = require('dgram')
const buffer = require('buffer')
function Log (options) { function Log (options) {
this.levels = { this.levels = {
'DEBUG': 5, 'DEBUG': 5,
...@@ -44,11 +47,7 @@ function Log (options) { ...@@ -44,11 +47,7 @@ function Log (options) {
} }
} }
if (this.options.graylog && this.options.graylog.active) { if (this.options.graylog && this.options.graylog.active) {
this.graylog = require('gelf') this.graylog = udp.createSocket('udp4')
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.info = function (message) { this.info = function (message) {
...@@ -125,28 +124,7 @@ function Log (options) { ...@@ -125,28 +124,7 @@ function Log (options) {
}) })
} }
if (this.options.graylog && this.options.graylog.active) { if (this.options.graylog && this.options.graylog.active) {
switch (tag) { this.graylogSend(message, 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)
}
} }
return msg return msg
} }
...@@ -155,13 +133,14 @@ function Log (options) { ...@@ -155,13 +133,14 @@ function Log (options) {
var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1) var localISOTime = (new Date(Date.now() - tzoffset)).toISOString().slice(0, -1)
return localISOTime.split('.')[0].trim() return localISOTime.split('.')[0].trim()
} }
this.graylogEmit = function (message, level) { this.graylogSend = function (message, level) {
this.graylogger.emit('gelf.log', { this.graylog.send(Buffer.from(JSON.stringify({
"short_message": message, short_message: message,
"timestamp": Date.now() / 1000, timestamp: Date.now() / 1000,
"level": level, hostname: this.hostname,
"facility": this.name, facility: this.name,
}) level:level
})),this.graylog.port,this.graylog.server,function(error){})
} }
return this return this
} }
......
...@@ -12,9 +12,7 @@ ...@@ -12,9 +12,7 @@
"type": "git", "type": "git",
"url": "https://gitlab.br.de/general/log" "url": "https://gitlab.br.de/general/log"
}, },
"dependencies": { "dependencies": {},
"gelf": "^2.0.1"
},
"devDependencies": { "devDependencies": {
"jest": "^25.3.0" "jest": "^25.3.0"
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment