New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

enrise-logger

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

enrise-logger - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

13

index.js

@@ -24,13 +24,14 @@ 'use strict';

Logger.prototype.get = function (label, level) {
const conf = _.cloneDeep(this._settings.winston);
const conf = _.cloneDeep(this._settings.transports);
const transports = _.map(this._settings.transports, (transport) => {
const transportSettings = conf[_.lowerFirst(transport)];
// Filter out falsey values
const transportKeys = _.keys(_.pickBy(this._settings.transports, _.identity));
const transports = _.map(transportKeys, (transport) => {
const transportSettings = conf[transport];
transportSettings.label = label;
transportSettings.level = level || transportSettings.level;
const transportConfig = this._settings[`get${transport}Config`](conf);
return new winston.transports[transport](transportConfig);
return new winston.transports[transport](transportSettings);
});

@@ -37,0 +38,0 @@

{
"name": "enrise-logger",
"description": "Logger used within Enrise projects and module's",
"version": "0.1.1",
"version": "0.2.0",
"author": "Team MatchMinds @ Enrise",

@@ -6,0 +6,0 @@ "main": "index.js",

@@ -32,15 +32,7 @@ # Node.js logger module

{
transports: ['Console'],
getConsoleConfig: (config) => {
return config.console;
},
getLogstashUDPConfig: (config) => {
return config.logstashUDP;
},
winston: {
console: {
transports: {
Console: {
level: 'info',
colorize: true
},
logstashUDP: {}
}
},

@@ -61,15 +53,10 @@ levels: {

#### `transports`
Define all transports that the logger should use. Defaults to only the Console. The other possible transport is `LogstashUDP`. These can be used together.
#### `transports: Object`
The keys define the transports that the logger should use, the value is the configuration passed to the transport constructor. Multiple transports can be combined. Defaults to only the Console with the settings above. To exclude the Console transport, set it to `null`. Possible transports are:
- `Console`: [winston.Console documentation](https://github.com/winstonjs/winston/blob/master/docs/transports.md#console-transport)
- `File`: [winston.File documentation](https://github.com/winstonjs/winston/blob/master/docs/transports.md#file-transport)
- `Http`: [winston.Http documentation](https://github.com/winstonjs/winston/blob/master/docs/transports.md#http-transport)
- `LogstashUDP`: [winston.LogstashUDP documentation](https://www.npmjs.com/package/winston-logstash-udp)
#### `getConsoleConfig` & `getLogstashUDPConfig`
Overwrite and modify the configuration used for their corresponding transport. The `config` object is _always_ a clone of the `config.winston` object.
#### `winston`
An object with specific configuration for the transporters.
- `console`: [winston.Console documentation](https://github.com/winstonjs/winston)
- `logstashUDP`: [winston.LogstashUDP documentation](https://www.npmjs.com/package/winston-logstash-udp)
#### `levels`
The node-logger uses more detailed log-levels than winston does. The higher the priority the more important the message is considered to be, and the lower the corresponding integer priority. These levels can be modified to your liking.
module.exports = {
getConsoleConfig: (config) => {
return config.console;
},
getLogstashUDPConfig: (config) => {
return config.logstashUDP;
},
transports: ['Console'],
longtrace: false,
winston: {
console: {
transports: {
Console: {
level: 'info',
colorize: true
},
logstashUDP: {}
}
},
longtrace: false,
levels: {

@@ -18,0 +10,0 @@ error: 0,

'use strict';
const _ = require('lodash');
const chai = require('chai');

@@ -38,6 +37,2 @@ const sinon = require('sinon');

},
transports: {
Console: sinon.stub(),
LogstashUDP: sinon.stub()
},
Container: sinon.stub().returns(winstonContainer)

@@ -51,2 +46,9 @@ };

beforeEach(() => {
winston.transports = {
Console: sinon.stub(),
LogstashUDP: sinon.stub()
};
});
describe('Logger', () => {

@@ -76,4 +78,4 @@ it('throws an error when trying to use without instantiating', () => {

const logger = new Logger({
winston: {
console: {
transports: {
Console: {
level: 'verbose'

@@ -84,17 +86,11 @@ }

expect(logger._settings).to.deep.equal({
transports: ['Console'],
getConsoleConfig: logger._settings.getConsoleConfig,
getLogstashUDPConfig: logger._settings.getLogstashUDPConfig,
longtrace: false,
winston: {
console: {
transports: {
Console: {
level: 'verbose',
colorize: true
},
logstashUDP: {}
}
},
levels: levels
});
expect(logger._settings.getConsoleConfig).to.be.a('function');
expect(logger._settings.getLogstashUDPConfig).to.be.a('function');
});

@@ -111,31 +107,2 @@

it('calls a custom get config function with a clone of the winston data', () => {
let winstonConfig;
const loggerConfig = {
winston: {
console: {}
},
getConsoleConfig: (_config) => {
winstonConfig = _config;
return winstonConfig;
}
};
new Logger(loggerConfig).get('LABEL');
expect(loggerConfig.winston).to.not.equal(winstonConfig);
expect(_.set(loggerConfig.winston, 'console.label', 'LABEL')).to.deep.equal(winstonConfig);
});
it('calls a custom get config function for the console transport', () => {
new Logger({
getConsoleConfig: () => {
return {
foo: 'bar'
};
}
}).get('TEST');
expect(winston.transports.Console).to.have.been.calledWith({
foo: 'bar'
});
});
it('correctly sets the log-levels', () => {

@@ -148,5 +115,4 @@ new Logger().get('TEST');

new Logger({
transports: ['Console', 'LogstashUDP'],
winston: {
logstashUDP: {
transports: {
LogstashUDP: {
bar: 'foo',

@@ -168,2 +134,20 @@ level: 'verbose'

});
it('allows removal of default Console transport', () => {
new Logger({
transports: {
Console: null,
LogstashUDP: {
bar: 'foo',
level: 'verbose'
}
}
}).get('TEST');
expect(winston.transports.Console).to.not.have.been.called;
expect(winston.transports.LogstashUDP).to.have.been.calledWith({
bar: 'foo',
level: 'verbose',
label: 'TEST'
});
});
});
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