Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gelf-pro

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gelf-pro - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

38

lib/gelf-pro.js

@@ -21,2 +21,4 @@ /**

fields: {},
filter: [],
broadcast: [],
adapterName: 'udp',

@@ -113,4 +115,4 @@ adapterOptions: {

// defining default functions like info(), error(), etc.
['emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug']
.forEach(function (lvl, idx) {
['emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'].forEach(
function (lvl, idx) {
var self = this;

@@ -124,2 +126,4 @@ this[lvl] = function (message, extra, cb) {

cb = cb || _.noop;
// trying to convert an error to readable message

@@ -133,18 +137,26 @@ if (_.isError(message)) {

// creating string from object
extra = this.getStringFromObject(
_.merge(
{}, {short_message: message, level: idx}, // eslint-disable-line
this.config.fields, extra || {}
)
);
// eslint-disable-next-line
extra = _.merge({}, {short_message: message, level: idx}, this.config.fields, extra || {});
// runs before any other I/O events fire
// filtering
if (this.config.filter.length
&& !_.overEvery(this.config.filter)(_.cloneDeep(extra))) {
return cb(null, 0);
}
// broadcasting
if (this.config.broadcast.length) {
_.invokeMap(this.config.broadcast, _.call, null, _.cloneDeep(extra));
}
extra = this.getStringFromObject(extra);
process.nextTick(function () {
return self.send(extra, cb || _.noop);
self.send(extra, cb);
});
};
}.bind(gelf));
}.bind(gelf)
);
// aliases for to be compatible with the console
// aliases to be console alike
_.forEach({log: 'debug', warn: 'warning'}, function (from, to) {

@@ -151,0 +163,0 @@ this[to] = this[from];

{
"name": "gelf-pro",
"version": "0.4.0",
"version": "0.5.0",
"main": "./lib/gelf-pro.js",

@@ -5,0 +5,0 @@ "author": "Kanstantsin Kamkou <kkamkou@gmail.com>",

@@ -10,3 +10,3 @@ node-gelf pro

"dependencies": {
"gelf-pro": "~0.4"
"gelf-pro": "~0.5"
}

@@ -48,2 +48,28 @@ ```

##### Filtering
Sometimes we have to discard a message which is not suitable for the current environment.
It is not possible to modify the data.
```javascript
log.setConfig({
filter: [
function (message, extra) { // rejects a "debug" message
return (extra.level < 5);
}
]
});
```
##### Broadcasting
It is not possible to modify the data. `broadcasting` happens after `filtering`.
```javascript
log.setConfig({
broadcast: [
function (message) { // broadcasting to console
console[message.level > 3 ? 'log' : 'error'](message.short_message, message);
}
]
});
```
### Levels

@@ -50,0 +76,0 @@ `emergency`, `alert`, `critical`, `error`, `warning` (`warn`), `notice`, `info`, `debug` (`log`)

@@ -26,3 +26,3 @@ 'use strict';

'Core functionality': {
'Default adapter functionality': function () {
'Set default adapter': function () {
var gelf = _.cloneDeep(gelfOriginal),

@@ -35,3 +35,3 @@ adapter = gelf.getAdapter(); // udp is a default one

'Predefined levels': function () {
'Expose pre-defined levels': function () {
var levels = {

@@ -51,3 +51,3 @@ emergency: 0, alert: 1, critical: 2, error: 3, warning: 4, warn: 4, notice: 5, info: 6,

'Predefined fields': function () {
'Set pre-defined fields': function () {
var gelf = _.cloneDeep(gelfOriginal),

@@ -64,3 +64,3 @@ mock = sinon.mock(gelf);

'Field validation': function () {
'Validate fields': function () {
var gelf = _.cloneDeep(gelfOriginal),

@@ -127,2 +127,32 @@ args = {

.should.have.properties(['_error_message', '_error_stack']);
},
'Broadcast messages': function () {
var expected = [{short_message: 'test', level: 6, world: true}],
stub1 = sinon.stub(),
stub2 = sinon.stub(),
gelf = _.cloneDeep(gelfOriginal);
gelf.setConfig({broadcast: [stub1, stub2]});
gelf.info('test', {world: true});
stub1.lastCall.args.should.eql(expected);
stub2.lastCall.args.should.eql(expected);
},
'Filter messages': function (done) {
var gelf = _.cloneDeep(gelfOriginal),
stub = sinon.stub().returns(true),
spyFn = sinon.spy(function (msg) { return msg.level < 4; }),
spySend = sinon.spy(gelf, 'send');
gelf.setConfig({filter: [stub, spyFn]});
gelf.warn('test', function (err, bytes) {
should.not.exist(err);
bytes.should.be.equal(0);
stub.lastCall.args.should.eql([{short_message: 'test', level: 4}]);
spyFn.lastCall.returned(false).should.be.true();
spySend.neverCalledWith().should.be.true();;
done();
});
}

@@ -129,0 +159,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc