Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish-to-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions lib/adapter/udp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <kkamkou@gmail.com>",
"description": "The Graylog Extended Log Format for the Node.js",
"keywords": [
"graylog",
"graylog2",
"gelf",
"logging",
"udp",
Expand Down
31 changes: 29 additions & 2 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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),
Expand Down Expand Up @@ -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);
Expand All @@ -401,6 +427,7 @@ module.exports = {
mock.verify();
err.message.should.equal(msgError);
bytesSent.should.equal(0);
stub.restore();
done();
});
}
Expand Down
Loading