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

udpclient fix

parent 70b1cabc
No related branches found
No related tags found
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 = {
......@@ -36,7 +34,9 @@ function Log (options) {
} catch (error) {
throw new Error('Could not create path ' + this.options.path + '\n' + error.toString())
}
if (this.options.graylog && this.options.graylog.active) {
this.udpclient = udp.createSocket('udp4')
}
try {
this.fs.accessSync(this.path.join(this.options.path, this.options.file), this.fs.constants.R_OK | this.fs.constants.W_OK)
} catch (err) {
......@@ -128,15 +128,15 @@ function Log (options) {
facility: this.name,
level:tag
}))
graylog.connect(this.options.graylog.port, this.options.graylog.server, (err) => {
this.udpclient.connect(this.options.graylog.port, this.options.graylog.server, (err) => {
if (err) {
console.error(err)
} else {
graylog.send(buffed, (error) => {
this.udpclient.send(buffed, (error) => {
if (error) {
console.error(error)
}
graylog.close();
this.udpclient.close()
})
}
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment