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 udp = require('dgram')
const Buffer = require('buffer')
const graylog = udp.createSocket('udp4')
function Log (options) { function Log (options) {
this.levels = { this.levels = {
...@@ -36,7 +34,9 @@ function Log (options) { ...@@ -36,7 +34,9 @@ function Log (options) {
} catch (error) { } catch (error) {
throw new Error('Could not create path ' + this.options.path + '\n' + error.toString()) 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 { try {
this.fs.accessSync(this.path.join(this.options.path, this.options.file), this.fs.constants.R_OK | this.fs.constants.W_OK) this.fs.accessSync(this.path.join(this.options.path, this.options.file), this.fs.constants.R_OK | this.fs.constants.W_OK)
} catch (err) { } catch (err) {
...@@ -128,15 +128,15 @@ function Log (options) { ...@@ -128,15 +128,15 @@ function Log (options) {
facility: this.name, facility: this.name,
level:tag 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) { if (err) {
console.error(err) console.error(err)
} else { } else {
graylog.send(buffed, (error) => { this.udpclient.send(buffed, (error) => {
if (error) { if (error) {
console.error(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.
Please register or to comment