From 24d24a8656c298c47ffcdf3ad812d383baecf834 Mon Sep 17 00:00:00 2001
From: Dominik Sigmund <dominik.sigmund@br.de>
Date: Fri, 8 May 2020 09:51:25 +0200
Subject: [PATCH] udpclient fix

---
 index.js | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/index.js b/index.js
index 8105206..2fb5b07 100644
--- a/index.js
+++ b/index.js
@@ -1,6 +1,4 @@
 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()
             })
           } 
         })
-- 
GitLab