diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 243ca65..1437350 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -17,9 +17,9 @@ jobs: os: [ubuntu-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} cache: 'npm' diff --git a/.github/workflows/publish-to-registry.yml b/.github/workflows/publish-to-registry.yml index 2b1cdf1..849affb 100644 --- a/.github/workflows/publish-to-registry.yml +++ b/.github/workflows/publish-to-registry.yml @@ -8,14 +8,14 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: artifacts run: | mkdir /tmp/output mv -t /tmp/output lib typings README.md LICENSE package.json - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: artifacts path: /tmp/output @@ -24,12 +24,12 @@ jobs: runs-on: ubuntu-latest needs: build steps: - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: node-version: 'lts/*' registry-url: 'https://registry.npmjs.org' - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: artifacts path: artifacts diff --git a/LICENSE b/LICENSE index d20ce09..ffe8ac2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2013-2024 Kanstantsin Kamkou and contributors +Copyright (c) 2013-2025 Kanstantsin Kamkou and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index 86c53c2..47debcb 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,13 @@ Sends logs to Graylog2 server in GELF (Graylog Extended Log Format) format. ## Installation ``` "dependencies": { - "gelf-pro": "~1.3" // see the "releases" section + "gelf-pro": "~1.4" // see the "releases" section } ``` `npm install gelf-pro` (**ALL** node.js versions are supported [0.x to 2x.x] :) -Library depends on: `lodash#~4.17` +Library only depends on: `lodash#~4.17` ## Initialization ```javascript diff --git a/lib/adapter/udp.js b/lib/adapter/udp.js index 6240a1f..36dcc70 100644 --- a/lib/adapter/udp.js +++ b/lib/adapter/udp.js @@ -70,18 +70,16 @@ adapter.send = function (message, callback) { isInterrupted = false, self = this; - var callbackOnce = _.once(callback), - cbResults = function (err, result) { - client.close(); - return callbackOnce(err, result); - }; + var cbResults = _.once(function (err, result) { + client.close(); + return callback(err, result); + }); client.on('error', function (err) { isInterrupted = true; cbResults(err, bytesSentTotal); }); - self.deflate(message, function (err, buf) { if (err) { return cbResults(err, 0); } diff --git a/package.json b/package.json index dda574e..b6d7c6f 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,13 @@ { "name": "gelf-pro", - "version": "1.3.12", + "version": "1.4.0", "main": "./lib/gelf-pro.js", "typings": "./typings/index.d.ts", "author": "Kanstantsin Kamkou ", "description": "The Graylog Extended Log Format for the Node.js", "keywords": [ "graylog", + "graylog2", "gelf", "logging", "udp", diff --git a/test/tests.js b/test/tests.js index 02ad1d3..65994b3 100644 --- a/test/tests.js +++ b/test/tests.js @@ -329,6 +329,7 @@ module.exports = { gelf.send(message, function (err, bytesSent) { err.should.be.an.instanceof(Error); + err.message.should.equal('A message MUST NOT consist of more than 128 chunks'); bytesSent.should.equal(0); sandbox.restore(); done(); @@ -347,17 +348,42 @@ module.exports = { }); var client = adapter._createSocket(); - sinon.stub(client, 'send').yields(new Error('Random fail')); + sandbox.stub(client, 'send').yields(new Error('Random fail')); sandbox.stub(adapter, '_createSocket').returns(client); adapter.send(msg, function (err, bytesSent) { err.should.be.an.instanceof(Error); + err.message.should.equal('Random fail'); bytesSent.should.equal(0); sandbox.restore(); done(); }); }, + 'Socket exception in the middle': function (done) { + var adapter = getAdapter('udp'), + msg = getLongMessage(10000), + sandbox = sinon.sandbox.create(); + + var client = adapter._createSocket(); + + sandbox.stub(adapter, '_createSocket').returns(client); + sandbox.stub(client, 'send') + .onFirstCall().yields(null, 100) + .onThirdCall().yields(null, 300) + .onSecondCall().callsFake(function () { + client.emit('error', new Error('Unable to send the chunk')); + }); + + adapter.send(msg, function (err, bytesSent) { + err.should.be.an.instanceof(Error); + err.message.should.equal('Unable to send the chunk'); + bytesSent.should.equal(100); + sandbox.restore(); + done(); + }); + }, + 'DNS exception': function (done) { var adapter = getAdapter('udp'), msg = getLongMessage(10000), @@ -386,7 +412,7 @@ module.exports = { dgramSocket = require('dgram').createSocket('udp4'), mock = sinon.mock(dgramSocket).expects('close').once(); - sinon.stub(dgramSocket, 'send').callsFake(function (msg, offset, length, port, address, cb) { + var stub = sinon.stub(dgramSocket, 'send').callsFake(function (msg, offset, length, port, address, cb) { msg.should.be.an.instanceof(Buffer); offset.should.equal(0); length.should.equal(24); @@ -401,6 +427,7 @@ module.exports = { mock.verify(); err.message.should.equal(msgError); bytesSent.should.equal(0); + stub.restore(); done(); }); }