Comparing version 0.1.2 to 0.2.0
# Changelog | ||
### 0.2.0 | ||
- Breaking: `Logger` constructor and `.create()` now take a single `options` object | ||
argument instead of a `service` and `name` argument. The `options` should have `serviceName` | ||
and `moduleName` props and can optionally have a `presets` prop. | ||
### 0.1.2 | ||
@@ -4,0 +10,0 @@ |
@@ -12,5 +12,9 @@ const _ = require('lodash'); | ||
class Logger { | ||
constructor(serviceName, logName) { | ||
this.debug = debug(`${serviceName}:${logName}`); | ||
this.name = logName; | ||
constructor(options) { | ||
const { serviceName, moduleName, presets } = options; | ||
this.presets = Object.assign( | ||
{ module: moduleName }, | ||
_.isObject(presets) ? presets : {}, | ||
); | ||
this.debug = debug(`${serviceName}:${moduleName}`); | ||
this.tag = `${serviceName}-${process.env.NODE_ENV}`; | ||
@@ -33,4 +37,4 @@ | ||
static create(serviceName, logName) { | ||
return new Logger(serviceName, logName); | ||
static create(options) { | ||
return new Logger(options); | ||
} | ||
@@ -102,5 +106,4 @@ | ||
const logObj = Object.assign({ | ||
module: this.name, | ||
}, logData); | ||
const logObj = Object.assign({}, this.presets, logData); | ||
if (response) { | ||
@@ -107,0 +110,0 @@ // If the response object has been included with the call then it means we need to |
@@ -52,3 +52,3 @@ { | ||
}, | ||
"version": "0.1.2" | ||
"version": "0.2.0" | ||
} |
@@ -35,3 +35,6 @@ # lalog | ||
``` | ||
const logger = Logger.create('service-name', 'module-name'); | ||
const logger = Logger.create({ | ||
serviceName: 'service-name', | ||
moduleName: 'module-name', | ||
}); | ||
``` | ||
@@ -42,7 +45,10 @@ | ||
``` | ||
const logger = new Logger('service-name', 'module-name'); | ||
const logger = new Logger({ | ||
serviceName: 'service-name', | ||
moduleName: 'module-name', | ||
}); | ||
``` | ||
`lalog` uses `debug` as one of its destinations. The `service-name` and `module-name` allow you | ||
to filter `debug` messages. | ||
`lalog` uses `debug` as one of its destinations. The `serviceName` and `moduleName` props allow | ||
you to filter `debug` messages. | ||
@@ -49,0 +55,0 @@ ### Write Log Messages |
@@ -8,3 +8,6 @@ const Logger = require('../../lib'); | ||
const logger = Logger.create('test-service', 'test-logger'); | ||
const logger = Logger.create({ | ||
serviceName: 'test-service', | ||
moduleName: 'test-logger', | ||
}); | ||
@@ -70,7 +73,7 @@ describe('/lib/logger', () => { | ||
test('should call create() multiple times without problem', async () => { | ||
const logger1 = Logger.create('fake-service-1', 'fake-module-1'); | ||
const logger1 = Logger.create({ serviceName: 'fake-service-1', moduleName: 'fake-module-1' }); | ||
const logger2 = Logger.create('fake-service-1', 'fake-module-2'); | ||
const logger2 = Logger.create({ serviceName: 'fake-service-1', moduleName: 'fake-module-2' }); | ||
const logger3 = Logger.create('fake-service-3', 'fake-module-2'); | ||
const logger3 = Logger.create({ serviceName: 'fake-service-3', moduleName: 'fake-module-2' }); | ||
@@ -83,7 +86,7 @@ expect(logger1).not.toBe(logger2); | ||
test('should new Logger() multiple times without problem', async () => { | ||
const logger1 = new Logger('fake-service-1', 'fake-module-1'); | ||
const logger1 = new Logger({ serviceName: 'fake-service-1', moduleName: 'fake-module-1' }); | ||
const logger2 = new Logger('fake-service-1', 'fake-module-2'); | ||
const logger2 = new Logger({ serviceName: 'fake-service-1', moduleName: 'fake-module-2' }); | ||
const logger3 = new Logger('fake-service-3', 'fake-module-2'); | ||
const logger3 = new Logger({ serviceName: 'fake-service-3', moduleName: 'fake-module-2' }); | ||
@@ -94,2 +97,11 @@ expect(logger1).not.toBe(logger2); | ||
}); | ||
test('should create a logger with presets', () => { | ||
const logger1 = new Logger({ | ||
serviceName: 'fake-service-1', | ||
moduleName: 'fake-module-1', | ||
presets: { trackId: 'fake-track-id' }, | ||
}); | ||
expect(typeof logger1).toBe('object'); | ||
}); | ||
}); |
@@ -12,3 +12,6 @@ /* eslint-disable no-console */ | ||
const logger = Logger.create('test-service', 'test-logger'); | ||
const logger = Logger.create({ | ||
serviceName: 'test-service', | ||
moduleName: 'test-logger', | ||
}); | ||
@@ -15,0 +18,0 @@ // Assign console to an object to check calls to console and supress |
24357
597
62