Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: kkamkou/node-gelf-pro
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.3.4
Choose a base ref
...
head repository: kkamkou/node-gelf-pro
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Apr 6, 2021

  1. attempt to upgrade the deps

    kkamkou committed Apr 6, 2021
    Copy the full SHA
    37a1d73 View commit details
  2. mocha dep reverted

    kkamkou committed Apr 6, 2021
    Copy the full SHA
    4d138d4 View commit details
  3. readme updated

    kkamkou committed Apr 6, 2021
    Copy the full SHA
    65da9fa View commit details
  4. Copy the full SHA
    a3ce479 View commit details
  5. Copy the full SHA
    02aeab1 View commit details
  6. travis migration

    kkamkou committed Apr 6, 2021
    Copy the full SHA
    046b727 View commit details

Commits on Apr 7, 2021

  1. Copy the full SHA
    27d6939 View commit details

Commits on Oct 29, 2021

  1. Copy the full SHA
    20af372 View commit details
  2. Merge branch '1.3.6-rc.1'

    kkamkou committed Oct 29, 2021
    Copy the full SHA
    c3fa672 View commit details
  3. Create node.js.yml

    added github actions draft
    kkamkou authored Oct 29, 2021
    Copy the full SHA
    21db3da View commit details
  4. Copy the full SHA
    f998055 View commit details
  5. license change

    kkamkou committed Oct 29, 2021
    Copy the full SHA
    45d3eb6 View commit details
  6. npm test via github actions

    kkamkou committed Oct 29, 2021
    Copy the full SHA
    b36d2ee View commit details
  7. npm install missing

    kkamkou committed Oct 29, 2021
    Copy the full SHA
    073ce70 View commit details
  8. version 5 is glitching

    kkamkou committed Oct 29, 2021
    Copy the full SHA
    09c2546 View commit details
  9. 0.10 is replaced with 0.12

    kkamkou committed Oct 29, 2021
    Copy the full SHA
    b69d525 View commit details
  10. Copy the full SHA
    a19481e View commit details
  11. typo

    kkamkou committed Oct 29, 2021
    Copy the full SHA
    a5bdf63 View commit details
  12. npm publish corrections

    kkamkou committed Oct 29, 2021
    Copy the full SHA
    2e69bd5 View commit details
  13. added access

    kkamkou committed Oct 29, 2021
    Copy the full SHA
    415796e View commit details
  14. another attempt

    kkamkou committed Oct 29, 2021
    Copy the full SHA
    f1cd37f View commit details

Commits on May 8, 2022

  1. Copy the full SHA
    c15fa2c View commit details
  2. github actions change

    kkamkou committed May 8, 2022
    Copy the full SHA
    3c767fb View commit details
  3. github action up

    kkamkou committed May 8, 2022
    Copy the full SHA
    de08fe4 View commit details

Commits on Jun 8, 2022

  1. udp adapter issue, closes #78

    kkamkou committed Jun 8, 2022
    Copy the full SHA
    2bbe87a View commit details

Commits on Aug 16, 2022

  1. Copy the full SHA
    98cf7fa View commit details

Commits on Oct 13, 2022

  1. Update package.json

    kkamkou authored Oct 13, 2022
    Copy the full SHA
    029909d View commit details

Commits on Nov 27, 2022

  1. Unstable sending of chunked messages, closes #80; added node.js 19 to…

    … tests; readme minor changes
    kkamkou committed Nov 27, 2022
    Copy the full SHA
    8105001 View commit details

Commits on Jan 12, 2024

  1. Copy the full SHA
    34d6c91 View commit details
  2. Copy the full SHA
    ce8f71c View commit details
  3. removed v6 from CI build

    kkamkou committed Jan 12, 2024
    Copy the full SHA
    0f4894d View commit details
  4. Node.js 18+ test corrections

    kkamkou committed Jan 12, 2024
    Copy the full SHA
    6a397af View commit details
  5. Copy the full SHA
    2af3750 View commit details
  6. coveralls corrections

    kkamkou committed Jan 12, 2024
    Copy the full SHA
    3903828 View commit details
  7. coveralls corrections

    kkamkou committed Jan 12, 2024
    Copy the full SHA
    e89fd55 View commit details
  8. badge corrections, closes #90

    kkamkou committed Jan 12, 2024
    Copy the full SHA
    89fbc62 View commit details
  9. added windows to tests

    kkamkou committed Jan 12, 2024
    Copy the full SHA
    4ad90be View commit details
  10. removed windows

    kkamkou committed Jan 12, 2024
    Copy the full SHA
    f321254 View commit details

Commits on Mar 27, 2024

  1. Readme update (#94)

    * Update README.md
    * Update LICENSE
    kkamkou authored Mar 27, 2024
    Copy the full SHA
    07030ef View commit details
  2. Update README.md

    kkamkou authored Mar 27, 2024
    Copy the full SHA
    87b42d8 View commit details

Commits on Jun 27, 2024

  1. Copy the full SHA
    a6e835b View commit details

Commits on Jan 2, 2025

  1. Copy the full SHA
    45872e7 View commit details
Showing with 925 additions and 846 deletions.
  1. +46 −0 .github/workflows/node.js.yml
  2. +49 −0 .github/workflows/publish-to-registry.yml
  3. +0 −28 .travis.yml
  4. +1 −1 LICENSE
  5. +38 −10 README.md
  6. +42 −52 lib/adapter/udp.js
  7. +690 −740 package-lock.json
  8. +6 −6 package.json
  9. +49 −9 test/tests.js
  10. +4 −0 typings/index.d.ts
46 changes: 46 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Node.js CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
name: node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
node: ['lts/*', '8', '10', '12', '14', '16', '18', '20', '22']
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- run: npm install

- run: npm test

- name: coveralls parallel
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
flag-name: ${{matrix.os}}-node-${{ matrix.node }}
parallel: true

finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: coveralls publish
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
parallel-finished: true
49 changes: 49 additions & 0 deletions .github/workflows/publish-to-registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Publish to NPM registry

on:
release:
types: [ published ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- 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@v4
with:
name: artifacts
path: /tmp/output

publish:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/setup-node@v4
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'

- uses: actions/download-artifact@v4
with:
name: artifacts
path: artifacts

- name: list
run: ls -R
working-directory: artifacts

- name: publish
run: npm publish ./artifacts/ --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- uses: geekyeggo/delete-artifact@v1
with:
name: artifacts

28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

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-2019 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
48 changes: 38 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
node-gelf pro
gelf pro
=============
node-gelf - Graylog2 client library for Node.js. Pro - because of code-quality. GELF - The Graylog Extended Log Format.
`gelf-pro` - Graylog2 client library for Node.js.
Sends logs to Graylog2 server in GELF (Graylog Extended Log Format) format.

![Build Status](https://travis-ci.org/kkamkou/node-gelf-pro.svg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/kkamkou/node-gelf-pro/badge.svg?branch=master)](https://coveralls.io/github/kkamkou/node-gelf-pro?branch=master)
[![Code Climate](https://codeclimate.com/github/kkamkou/node-gelf-pro/badges/gpa.svg)](https://codeclimate.com/github/kkamkou/node-gelf-pro)
**Features:**
- JS object marshalling
- UDP/TCP/TLS support
- Filtering, Transforming, Broadcasting.

![Build Status](https://github.com/kkamkou/node-gelf-pro/actions/workflows/node.js.yml/badge.svg?branch=master)
![Coverage Status](https://coveralls.io/repos/github/kkamkou/node-gelf-pro/badge.svg?branch=master)

## 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 :)

`npm install gelf-pro` (**ALL** node.js versions are supported [0.x to 2x.x] :)

Library only depends on: `lodash#~4.17`

## Initialization
```javascript
@@ -21,13 +29,25 @@ var log = require('gelf-pro');

### Adapters

> [!WARNING]
> To ensure consistent behavior, **none of the existing adapters re-use the socket connection**. Re-using socket connections can lead to resource leakage, complexity in state management, concurrency issues, security risks, and may not always provide significant performance benefits.
> It's often simpler and safer to establish new connections as needed rather than re-using existing ones, ensuring better resource utilization and reducing potential complications in network communication.
>
> There are multiple ([1](https://github.com/kkamkou/node-gelf-pro/pull/68), [2](https://github.com/fdelayen/node-gelf-pro/commit/b52b4b6b1ff26772314b8673dd6fd724c0937caa)) variants available for you to borrow from and create a new adapter. [See related section](#third-party-adapters).
- UDP (with deflation and chunking)
- Input: `GELF UDP`
- TCP
- Input: `GELF TCP` (with `Null frame delimiter`)
- TCP via TLS(SSL)
- Input: `GELF TCP` (with `Null frame delimiter` and `Enable TLS`)


> [!NOTE]
> Within a more or less stable network (which is most likely), I would recommend using the `udp` adapter.
> I would also recommend it for an average to high-loaded project.
> For sensitive information, the `tcp-tls` adapter is recommended.
### Configuration
```javascript
// simple
@@ -62,8 +82,7 @@ log.setConfig({
}
});
```
> `log.setConfig` merges the data. Therefore you can call it multiple times.

> `log.setConfig` merges the data. Therefore, you can call it multiple times.
### Basic functionality
```javascript
@@ -86,7 +105,7 @@ log.message(new Error('An error message'), 3); // same as previous
##### Extra
In case `extra` [is a plain object](https://lodash.com/docs#isPlainObject),
the library converts it to a readable format. Other values [are converted to string](https://lodash.com/docs#toString).
Acceptable format of a key is: `^[\w-]$`
The acceptable format of a key is: `^[\w-]$`
```javascript
log.info(
'a new msg goes here',
@@ -143,6 +162,15 @@ Default:
Example: `log.emergency(...)`, `log.critical(...)`, etc.
Custom example: `{alert: 0, notice: 1, ...}`

### Third party adapters
You can force using custom adapter by setting the `adapter` right after initialisation. The [signature](lib/adapter/abstract.js) might be found here.
```javascript
var log = require('gelf-pro');
var myFancyAdapter = require('...');
log.adapter = myFancyAdapter;
// (!) adapterName and adapterOptions will be ignored
```

### Aliases

Default: `{log: 'debug', warn: 'warning'}`
94 changes: 42 additions & 52 deletions lib/adapter/udp.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
'use strict';

var _ = require('lodash'),
async = require('async'),
crypto = require('crypto'),
dgram = require('dgram'),
abstract = require('./abstract');
@@ -61,7 +60,7 @@ adapter.getArrayFromBuffer = function (buffer, maxSize) {

/**
* Sends a chunk to the server
* @param {Object} message
* @param {String} message
* @param {Function} callback
* @returns {adapter}
*/
@@ -71,66 +70,57 @@ 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);
});

async.waterfall(
[
function (cb) {
self.deflate(message, cb);
},
function (buf, cb) {
var chunks = self.getArrayFromBuffer(
buf, self.specification.chunkMaxLength[self.options.protocol]
),
chunksCount = chunks.length;

if (chunksCount > self.specification.chunkMaxCount) {
return cb(
new Error(
'A message MUST NOT consist of more than %d chunks'.replace(
'%d', self.specification.chunkMaxCount
)
)
);
}
self.deflate(message, function (err, buf) {
if (err) { return cbResults(err, 0); }

var packetId = Array.prototype.slice.call(crypto.randomBytes(8)),
cbOnce = _.once(cb);
var chunkMaxLength = self.specification.chunkMaxLength[self.options.protocol],
chunks = self.getArrayFromBuffer(buf, chunkMaxLength),
chunksCount = chunks.length;

for (var idx in chunks) {
if (isInterrupted) {
break;
}
if (chunksCount > self.specification.chunkMaxCount) {
return cbResults(
new Error(
'A message MUST NOT consist of more than %d chunks'.replace(
'%d', self.specification.chunkMaxCount
)
), 0
);
}

var chunk = chunks[idx],
packet = buffer.from(
self.specification.magicBytes.concat(packetId, idx, chunksCount, chunk)
);
client.send(
packet, 0, packet.length, self.options.port, self.options.host,
function (err, bytesSent) {
if (err) { return cbOnce(err); }
bytesSentTotal += bytesSent;
/* istanbul ignore else */
if (idx >= chunksCount - 1) {
cbOnce(err, bytesSentTotal);
}
}
);
}
var packetId = Array.prototype.slice.call(crypto.randomBytes(8)),
chunksSent = 0;
for (var idx in chunks) {
if (isInterrupted) {
break;
}
],
cbResults
);

var chunk = chunks[idx],
packet = buffer
.from(self.specification.magicBytes.concat(packetId, idx, chunksCount, chunk));
client.send(
packet, 0, packet.length, self.options.port, self.options.host,
function (err, bytesSent) {
if (err) { return cbResults(err, 0); }
bytesSentTotal += bytesSent;
/* istanbul ignore else */
if (++chunksSent >= chunksCount) {
cbResults(err, bytesSentTotal);
}
}
);
}
});

return this;
};

Loading