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

revisit

parent 9328f5a6
Branches
Tags
1 merge request!1Update index.test.js, examples/all-options.js, examples/log-to-file.js,...
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment