From 699751e057c0d2d70860bd044be0c476f30acf9c Mon Sep 17 00:00:00 2001 From: Ed Eustace Date: Wed, 15 Mar 2017 09:42:01 +0000 Subject: [PATCH 1/6] set prerelease version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 684a3d1..c6ecf6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "log-factory", - "version": "0.0.1-prerelease", + "version": "0.1.0-prerelease", "author": "", "main": "lib/index.js", "types": "lib/index.d.ts", From 9a7de3af52ac6f354ab4e82b2fb4a09897391696 Mon Sep 17 00:00:00 2001 From: Ed Eustace Date: Mon, 27 Mar 2017 12:24:24 +0100 Subject: [PATCH 2/6] feat(config): Allow logging to be redirected to a file BREAKING CHANGE: The `init` method now takes an options object `{console, file, log}` - see README.md --- README.md | 40 +++++++++++++++++++++++++++++ lib/index.d.ts | 6 ++++- lib/index.js | 54 +++++++++++++++++++++++++++------------ package.json | 2 +- src/index.ts | 69 ++++++++++++++++++++++++++++++++++++++------------ 5 files changed, 137 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 23a1bcd..c8efd78 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,46 @@ let logger = buildLogger(); ``` +### Configuration + +```javascript + + import {init} from 'log-factory'; + + /** + * Calling init will only affect loggers after this call. + * So it is advisable to call this at the start of your app + */ + + init({ + console: false, + file: 'my-log.log', + log: 'INFO' + }); +``` + +The options for `init` are: + +* console - true/false, default: `true` +* file - direct logs to a file, default: `undefined` +* log - string|json-string|path-to-json-file, default: `'info'` + * string - error|warn|info|debug|verbose|silly + * json-string - a string that can be parsed as json + * path-to-json - a path to a json file + +If using json you can define levels for different categories. For example: + +```json +{ + "app": "info", + "item" : "debug" +} +``` + +`default` is a special category that will be applied if the category can't be found. + +To see the available categories, first run the log with level `silly`, the name in the square brackets is the category. + # test `npm test` diff --git a/lib/index.d.ts b/lib/index.d.ts index c90db75..23818c6 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,7 +1,11 @@ /// import * as winston from 'winston'; export declare const setDefaultLevel: (l: any) => void; -export declare const init: (log: any) => void; +export declare const init: (opts: { + console: boolean; + file?: string; + log?: any; +}) => void; export declare const getLogger: (id: string) => winston.LoggerInstance; export declare const fileLogger: (filename: any) => winston.LoggerInstance; export declare function buildLogger(): winston.LoggerInstance; diff --git a/lib/index.js b/lib/index.js index 0c10e2a..637db30 100644 --- a/lib/index.js +++ b/lib/index.js @@ -5,23 +5,41 @@ const fs = require("fs"); const path = require("path"); const stackTrace = require("stack-trace"); const winston = require("winston"); +const moduleOpts = { + console: true, + file: null, + log: 'INFO' +}; let config = { 'default': 'info' }; +const timestamp = () => { + var now = new Date(); + return dateFormat(now, 'HH:MM:ss.l'); +}; +const consoleTransport = (label) => { + return new (winston.transports.Console)({ + colorize: true, + label: label, + timestamp + }); +}; +const fileTransport = (label) => { + return new winston.transports.File({ + colorize: false, + json: false, + filename: moduleOpts.file, + label, + timestamp + }); +}; const mkLogConfig = (label, level) => { - return { - level: level, - transports: [ - new (winston.transports.Console)({ - colorize: true, - label: label, - timestamp: () => { - var now = new Date(); - return dateFormat(now, 'HH:MM:ss.l'); - } - }) - ] - }; + const addConsole = !moduleOpts.file && moduleOpts.console; + const transports = [ + addConsole ? consoleTransport(label) : null, + moduleOpts.file ? fileTransport(label) : null + ].filter(t => t !== null); + return { level, transports }; }; const logger = addLogger('LOG_FACTORY'); const setConfig = (cfg) => { @@ -40,8 +58,12 @@ exports.setDefaultLevel = (l) => { logger.configure(cfg); }); }; -exports.init = (log) => { - logger.debug('init: ', log); +exports.init = (opts) => { + logger.debug('init: ', opts); + moduleOpts.console = opts.console; + moduleOpts.file = opts.file; + moduleOpts.log = opts.log; + const { log } = moduleOpts; if (!log) { return; } @@ -108,4 +130,4 @@ function buildLogger() { } exports.buildLogger = buildLogger; -//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3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UuICovXG5leHBvcnQgY29uc3QgZmlsZUxvZ2dlciA9IChmaWxlbmFtZSk6IHdpbnN0b24uTG9nZ2VySW5zdGFuY2UgPT4ge1xuICB2YXIgbGFiZWw7XG4gIHZhciBwYXJzZWQgPSBwYXRoLnBhcnNlKGZpbGVuYW1lKTtcblxuICBpZiAocGFyc2VkLm5hbWUgPT09ICdpbmRleCcpIHtcbiAgICBsYWJlbCA9IHBhdGguYmFzZW5hbWUocGFyc2VkLmRpcik7XG4gIH0gZWxzZSB7XG4gICAgbGFiZWwgPSBwYXJzZWQubmFtZTtcbiAgfVxuICByZXR1cm4gZ2V0TG9nZ2VyKGxhYmVsKTtcbn07XG5cbi8qKlxuICogQ3JlYXRlIGEgbG9nZ2VyIGFuZCBhdXRvbWF0aWNhbGx5IG5hbWUgaXQgYnkgdXNpbmcgdGhlIGZpbGVuYW1lIG9mIHRoZSBjYWxsIHNpdGUuXG4gKiBFZzpcbiAqIGBgYFxuICogLy9teS1maWxlLmpzXG4gKiBpbXBvcnQge2J1aWxkTG9nZ2VyfSBmcm9tICdsb2ctZmFjdG9yeSc7XG4gKiBsZXQgbG9nZ2VyID0gYnVpbGRMb2dnZXIoKTtcbiAqIGxvZ2dlci5pbmZvKCdoaScpIC8vPT4gZW1pdHMgW0lORk9dIFtteS1maWxlXSBoaVxuICogYGBgXG4gKi9cbmV4cG9ydCBmdW5jdGlvbiBidWlsZExvZ2dlcigpOiB3aW5zdG9uLkxvZ2dlckluc3RhbmNlIHtcbiAgbGV0IHRyYWNlID0gc3RhY2tUcmFjZS5nZXQoKTtcbiAgbGV0IG5hbWUgPSB0cmFjZVsxXS5nZXRGaWxlTmFtZSgpO1xuICByZXR1cm4gZmlsZUxvZ2dlcihuYW1lKTtcbn1cbiJdfQ== diff --git a/package.json b/package.json index c6ecf6d..8d8f21d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "log-factory", - "version": "0.1.0-prerelease", + "version": "1.0.0-prerelease", "author": "", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/index.ts b/src/index.ts index ddabfbb..d01824e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,24 +7,55 @@ import * as winston from 'winston'; //levels: error > warn > info > verbose > debug > silly +type LogFactoryOpts = { + console: boolean, + file?: string, + log?: any +}; + +const moduleOpts = { + console: true, + file: null, + log: 'INFO' +}; + let config = { 'default': 'info' }; +const timestamp = () => { + var now = new Date(); + return dateFormat(now, 'HH:MM:ss.l'); +}; + +const consoleTransport = (label: string): winston.TransportInstance => { + return new (winston.transports.Console)({ + colorize: true, + label: label, + timestamp + }); +}; + +const fileTransport = (label: string): winston.TransportInstance => { + return new winston.transports.File({ + colorize: false, + json: false, + filename: moduleOpts.file, + label, + timestamp + }); +}; + const mkLogConfig = (label: string, level: string) => { - return { - level: level, - transports: [ - new (winston.transports.Console)({ - colorize: true, - label: label, - timestamp: () => { - var now = new Date(); - return dateFormat(now, 'HH:MM:ss.l'); - } - }) - ] - }; + + const addConsole = !moduleOpts.file && moduleOpts.console; + + const transports: winston.TransportInstance[] = [ + addConsole ? consoleTransport(label) : null, + moduleOpts.file ? fileTransport(label) : null + ].filter(t => t !== null); + + return { level, transports }; }; const logger = addLogger('LOG_FACTORY'); @@ -48,9 +79,15 @@ export const setDefaultLevel = (l) => { }); }; -export const init = (log): void => { +export const init = (opts: LogFactoryOpts): void => { - logger.debug('init: ', log); + logger.debug('init: ', opts); + + moduleOpts.console = opts.console; + moduleOpts.file = opts.file; + moduleOpts.log = opts.log; + + const { log } = moduleOpts; if (!log) { return; @@ -76,8 +113,8 @@ export const init = (log): void => { } }; - function addLogger(label, level?: string): winston.LoggerInstance { + level = level ? level : config['default'] || 'info'; let cfg = mkLogConfig(label, level); let logger; From a7e0ae82e91e8e1a6289247a77df667b22da3a3d Mon Sep 17 00:00:00 2001 From: Ed Eustace Date: Mon, 27 Mar 2017 12:46:17 +0100 Subject: [PATCH 3/6] update tests --- README.md | 2 + lib/index.js | 10 +-- src/index.ts | 10 +-- test/index-test.js | 165 +++++++++++++++++++++++++++++++-------------- 4 files changed, 122 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index c8efd78..c1aea84 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ The options for `init` are: * json-string - a string that can be parsed as json * path-to-json - a path to a json file + +> If you want to disable logging you can pass in: `{ console: false, file: undefined}` If using json you can define levels for different categories. For example: ```json diff --git a/lib/index.js b/lib/index.js index 637db30..b6213ab 100644 --- a/lib/index.js +++ b/lib/index.js @@ -8,7 +8,7 @@ const winston = require("winston"); const moduleOpts = { console: true, file: null, - log: 'INFO' + log: 'info' }; let config = { 'default': 'info' @@ -41,7 +41,6 @@ const mkLogConfig = (label, level) => { ].filter(t => t !== null); return { level, transports }; }; -const logger = addLogger('LOG_FACTORY'); const setConfig = (cfg) => { config = _.merge({}, config, cfg); _.forIn(cfg, (value, key) => { @@ -51,7 +50,6 @@ const setConfig = (cfg) => { const isLogLevel = (l) => _.includes(['error', 'warn', 'info', 'verbose', 'debug', 'silly'], l); exports.setDefaultLevel = (l) => { config = _.merge(config, { 'default': l }); - logger.debug('default level now: ', config['default']); _.forEach(winston.loggers.loggers, (value, key) => { let logger = winston.loggers.get(key); let cfg = mkLogConfig(key, config['default']); @@ -59,10 +57,9 @@ exports.setDefaultLevel = (l) => { }); }; exports.init = (opts) => { - logger.debug('init: ', opts); moduleOpts.console = opts.console; moduleOpts.file = opts.file; - moduleOpts.log = opts.log; + moduleOpts.log = opts.log || moduleOpts.log; const { log } = moduleOpts; if (!log) { return; @@ -76,7 +73,6 @@ exports.init = (opts) => { else { try { let config = JSON.parse(log); - logger.debug('parsed log: ', log); setConfig(config); } catch (e) { @@ -130,4 +126,4 @@ function buildLogger() { } exports.buildLogger = buildLogger; -//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIj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xuICogLy9teS1maWxlLmpzXG4gKiBpbXBvcnQge2J1aWxkTG9nZ2VyfSBmcm9tICdsb2ctZmFjdG9yeSc7XG4gKiBsZXQgbG9nZ2VyID0gYnVpbGRMb2dnZXIoKTtcbiAqIGxvZ2dlci5pbmZvKCdoaScpIC8vPT4gZW1pdHMgW0lORk9dIFtteS1maWxlXSBoaVxuICogYGBgXG4gKi9cbmV4cG9ydCBmdW5jdGlvbiBidWlsZExvZ2dlcigpOiB3aW5zdG9uLkxvZ2dlckluc3RhbmNlIHtcbiAgbGV0IHRyYWNlID0gc3RhY2tUcmFjZS5nZXQoKTtcbiAgbGV0IG5hbWUgPSB0cmFjZVsxXS5nZXRGaWxlTmFtZSgpO1xuICByZXR1cm4gZmlsZUxvZ2dlcihuYW1lKTtcbn1cbiJdfQ== diff --git a/src/index.ts b/src/index.ts index d01824e..bb859fe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,7 @@ type LogFactoryOpts = { const moduleOpts = { console: true, file: null, - log: 'INFO' + log: 'info' }; let config = { @@ -55,10 +55,10 @@ const mkLogConfig = (label: string, level: string) => { moduleOpts.file ? fileTransport(label) : null ].filter(t => t !== null); + return { level, transports }; }; -const logger = addLogger('LOG_FACTORY'); const setConfig = (cfg) => { config = _.merge({}, config, cfg); @@ -71,7 +71,6 @@ const isLogLevel = (l): Boolean => _.includes(['error', 'warn', 'info', 'verbose export const setDefaultLevel = (l) => { config = _.merge(config, { 'default': l }); - logger.debug('default level now: ', config['default']); _.forEach(winston.loggers.loggers, (value, key) => { let logger = winston.loggers.get(key); let cfg = mkLogConfig(key, config['default']); @@ -81,11 +80,9 @@ export const setDefaultLevel = (l) => { export const init = (opts: LogFactoryOpts): void => { - logger.debug('init: ', opts); - moduleOpts.console = opts.console; moduleOpts.file = opts.file; - moduleOpts.log = opts.log; + moduleOpts.log = opts.log || moduleOpts.log; const { log } = moduleOpts; @@ -100,7 +97,6 @@ export const init = (opts: LogFactoryOpts): void => { } else { try { let config = JSON.parse(log); - logger.debug('parsed log: ', log); setConfig(config); } catch (e) { if (fs.existsSync(log)) { diff --git a/test/index-test.js b/test/index-test.js index 622704d..f7c22c1 100644 --- a/test/index-test.js +++ b/test/index-test.js @@ -17,7 +17,8 @@ describe('log-factory', () => { deps = { 'winston': { transports: { - Console: stub().returns(instance) + Console: stub().returns(instance), + File: stub().returns(instance) }, loggers: { get: stub().returns(instance), @@ -32,84 +33,146 @@ describe('log-factory', () => { }, 'stack-trace': {} } - logFactory = proxyquire('../lib', deps); }); describe('init', () => { - beforeEach(() => { - logFactory.setDefaultLevel = stub(); - }); - - it('inits via a level', () => { - logFactory.init('silly'); - assert.calledWith(logFactory.setDefaultLevel, 'silly'); - }); + describe('disabled', () => { + beforeEach(() => { + logFactory.init({ console: false, file: undefined }); + logFactory.fileLogger('test'); + }); - let prepLoggers = (has) => { - deps.winston.loggers.has.withArgs('app').returns(has); - deps.winston.loggers.get.withArgs('app').returns(instance); - deps.winston.loggers.add.withArgs('app').returns(instance); - logFactory.init({ app: 'silly' }); - } + it('does not create a Console transport', () => { + assert.notCalled(deps.winston.transports.Console); + }); + it('does not create a File transport', () => { + assert.notCalled(deps.winston.transports.File) + }); + }); - let assertSetConfig = (run) => { + describe('console', () => { - it('calls logger.has', () => { - run(); - assert.calledWith(deps.winston.loggers.has, 'app'); + beforeEach(() => { + logFactory.init({ console: true, file: undefined }); + logFactory.fileLogger('test'); }); - it('calls logger.configure', () => { - run(); - assert.calledWith(instance.configure, { - level: 'silly', - transports: match.array + it('creates a new Console transport', () => { + assert.calledWith(deps.winston.transports.Console, { + colorize: true, + label: 'test', + timestamp: match.func }); }); + it('does not create a File transport', () => { + assert.notCalled(deps.winston.transports.File) + }); + }); + + describe('file', () => { - it('calls logger.add if there is no logger', () => { - run(false); - assert.calledWith(deps.winston.loggers.add, 'app', {}); + beforeEach(() => { + logFactory.init({ console: false, file: 'my-file.log' }); + logFactory.fileLogger('test'); }); - it('calls logger.get if there is a logger', () => { - run(true); - assert.calledWith(deps.winston.loggers.get, 'app'); + it('does not create a new Console transport', () => { + assert.notCalled(deps.winston.transports.Console) }); - } + it('creates a new File transport', () => + + assert.calledWith(deps.winston.transports.File, { + filename: 'my-file.log', + colorize: false, + json: false, + label: 'test', + timestamp: match.func + })); + }); + - describe('with object', () => { + describe('log', () => { - let run = (has) => { - prepLoggers(has); + beforeEach(() => { + logFactory.setDefaultLevel = stub(); + }); + + it('inits via a level', () => { + logFactory.init({ + log: 'silly' + }); + assert.calledWith(logFactory.setDefaultLevel, 'silly'); + }); + + let prepLoggers = (has) => { + deps.winston.loggers.has.withArgs('app').returns(has); + deps.winston.loggers.get.withArgs('app').returns(instance); + deps.winston.loggers.add.withArgs('app').returns(instance); logFactory.init({ app: 'silly' }); } - assertSetConfig(run); - }); - describe('with json string', () => { - let run = (has) => { - prepLoggers(has); - logFactory.init(JSON.stringify({ app: 'silly' })); - } - assertSetConfig(run); - }); + let assertSetConfig = (run) => { + + it('calls logger.has', () => { + run(); + assert.calledWith(deps.winston.loggers.has, 'app'); + }); + + it('calls logger.configure', () => { + run(); + assert.calledWith(instance.configure, { + level: 'silly', + transports: match.array + }); + }); + + + it('calls logger.add if there is no logger', () => { + run(false); + assert.calledWith(deps.winston.loggers.add, 'app', {}); + }); + + it('calls logger.get if there is a logger', () => { + run(true); + assert.calledWith(deps.winston.loggers.get, 'app'); + }); - describe('with path to file', () => { - let run = (has) => { - prepLoggers(has); - deps.fs.existsSync.returns(true); - deps.fs.readFileSync.returns(JSON.stringify({ app: 'silly' })); - logFactory.init('path/to/file'); } - assertSetConfig(run); + describe('with object', () => { + + let run = (has) => { + prepLoggers(has); + logFactory.init({ log: { app: 'silly' } }); + } + assertSetConfig(run); + }); + + describe('with json string', () => { + + let run = (has) => { + prepLoggers(has); + logFactory.init({ log: JSON.stringify({ app: 'silly' }) }); + } + assertSetConfig(run); + }); + + describe('with path to file', () => { + let run = (has) => { + prepLoggers(has); + deps.fs.existsSync.returns(true); + deps.fs.readFileSync.returns(JSON.stringify({ app: 'silly' })); + logFactory.init({ log: 'path/to/file' }); + } + + assertSetConfig(run); + }); }); }); }); \ No newline at end of file From 548d178fda4f0b45de6c278cd24b1c367f81cc5f Mon Sep 17 00:00:00 2001 From: Ed Eustace Date: Mon, 27 Mar 2017 12:49:06 +0100 Subject: [PATCH 4/6] bump version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8d8f21d..e86ae40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "log-factory", - "version": "1.0.0-prerelease", + "version": "1.1.0-prerelease", "author": "", "main": "lib/index.js", "types": "lib/index.d.ts", @@ -38,4 +38,4 @@ "test": "./node_modules/.bin/gulp build && ./node_modules/.bin/mocha", "live-test": "./node_modules/.bin/gulp watch" } -} \ No newline at end of file +} From e8ef396527e131a2dec8b21f68c963a04ca1e779 Mon Sep 17 00:00:00 2001 From: Ed Eustace Date: Mon, 27 Mar 2017 12:52:53 +0100 Subject: [PATCH 5/6] reset version - 1.0.0 not released yet --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e86ae40..729afdf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "log-factory", - "version": "1.1.0-prerelease", + "version": "1.0.0-prerelease", "author": "", "main": "lib/index.js", "types": "lib/index.d.ts", From 2d5b6134de82d049a3144b1532c5e342bc3d4ede Mon Sep 17 00:00:00 2001 From: Ed Eustace Date: Mon, 27 Mar 2017 18:54:49 +0100 Subject: [PATCH 6/6] more info in readme --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c1aea84..91d2997 100644 --- a/README.md +++ b/README.md @@ -9,17 +9,21 @@ let logger = buildLogger(); ``` +The logger will be named after the module that called `buildLogger`. So if your file was called `utils/index.js` the logger category will be `[utils]`. + ### Configuration +By default logging targets the console with a `level` of `info`. You can change this by calling `init`. + ```javascript import {init} from 'log-factory'; /** - * Calling init will only affect loggers after this call. - * So it is advisable to call this at the start of your app + * Will only affect loggers created after the call to init. + * It is advisable to call this at the start of your app + * before any log instances have been created. */ - init({ console: false, file: 'my-log.log', @@ -37,7 +41,8 @@ The options for `init` are: * path-to-json - a path to a json file -> If you want to disable logging you can pass in: `{ console: false, file: undefined}` +> If you want to disable logging you can pass in: `{console: false, file: undefined}` + If using json you can define levels for different categories. For example: ```json