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

Switch to Graylog HTTPS

parent 45d1f197
No related branches found
No related tags found
1 merge request!1Update index.test.js, examples/all-options.js, examples/log-to-file.js,...
...@@ -25,8 +25,7 @@ function Log (options) { ...@@ -25,8 +25,7 @@ function Log (options) {
this.hostname = os.hostname() this.hostname = os.hostname()
} }
if (this.options.graylog && this.options.graylog.active) { if (this.options.graylog && this.options.graylog.active) {
this.udp = require('dgram') this.https = require('https')
this.udpclient = this.udp.createSocket('udp4')
} }
if (this.options.file) { if (this.options.file) {
this.fs = require('fs') this.fs = require('fs')
...@@ -120,18 +119,26 @@ function Log (options) { ...@@ -120,18 +119,26 @@ function Log (options) {
}) })
} }
if (this.options.graylog && this.options.graylog.active) { if (this.options.graylog && this.options.graylog.active) {
let buffed = Buffer.from(JSON.stringify({ let data = JSON.stringify({
short_message: msg, short_message: msg,
timestamp: Date.now() / 1000, timestamp: Date.now() / 1000,
hostname: this.hostname, hostname: this.hostname,
facility: this.name, facility: this.name,
level: tag level: tag
}))
this.udpclient.send(buffed, 0, buffed.length, this.options.graylog.port, this.options.graylog.server, (error) => {
if (error) {
console.error(error)
}
}) })
let options = {
hostname: this.options.graylog.server,
port: this.options.graylog.port,
path: '/gelf',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
}
var post = this.https.request(options)
post.write(data)
post.end()
} }
return msg return msg
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment