From 12c0f56589292e176158241f057c1be0178017df Mon Sep 17 00:00:00 2001 From: Blackbaud-SteveBrush Date: Tue, 25 Jul 2017 13:15:24 -0400 Subject: [PATCH 1/2] Added colors to winston --- cli/e2e.js | 2 +- cli/serve.js | 2 +- cli/utils/run-compiler.js | 2 +- cli/version.js | 2 +- config/sky-pages/sky-pages.config.js | 2 +- config/webpack/serve.webpack.config.js | 2 +- index.js | 2 +- loader/sky-processor/index.js | 2 +- loader/sky-tslint/program.js | 2 +- test/cli-build-public-library.spec.js | 2 +- test/cli-build.spec.js | 2 +- test/cli-e2e.spec.js | 2 +- test/cli-serve.spec.js | 2 +- test/cli-utils-run-compiler.spec.js | 2 +- test/cli-version.spec.js | 2 +- test/config-sky-pages.spec.js | 2 +- test/config-webpack-serve.spec.js | 2 +- test/loader-processor.spec.js | 2 +- test/sky-pages-out-skyux2.spec.js | 2 +- test/utils-logger.spec.js | 29 ++++++++++++++++++++++++++ utils/logger.js | 17 +++++++++++++++ 21 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 test/utils-logger.spec.js create mode 100644 utils/logger.js diff --git a/cli/e2e.js b/cli/e2e.js index 13c98b3f..5bba934e 100644 --- a/cli/e2e.js +++ b/cli/e2e.js @@ -3,7 +3,7 @@ const path = require('path'); const spawn = require('cross-spawn'); -const logger = require('winston'); +const logger = require('../utils/logger'); const portfinder = require('portfinder'); const HttpServer = require('http-server'); const selenium = require('selenium-standalone'); diff --git a/cli/serve.js b/cli/serve.js index 8b4a98dc..b80859de 100644 --- a/cli/serve.js +++ b/cli/serve.js @@ -1,9 +1,9 @@ /*jshint node: true*/ 'use strict'; -const logger = require('winston'); const portfinder = require('portfinder'); +const logger = require('../utils/logger'); const assetsProcessor = require('../lib/assets-processor'); /** diff --git a/cli/utils/run-compiler.js b/cli/utils/run-compiler.js index 5e8447ac..491413a6 100644 --- a/cli/utils/run-compiler.js +++ b/cli/utils/run-compiler.js @@ -1,7 +1,7 @@ /*jshint node: true*/ 'use strict'; -const logger = require('winston'); +const logger = require('../../utils/logger'); const runCompiler = (webpack, config) => { const compiler = webpack(config); diff --git a/cli/version.js b/cli/version.js index d387bd20..1e1450ac 100644 --- a/cli/version.js +++ b/cli/version.js @@ -2,7 +2,7 @@ 'use strict'; const path = require('path'); -const logger = require('winston'); +const logger = require('../utils/logger'); /** * Returns the version from package.json. diff --git a/config/sky-pages/sky-pages.config.js b/config/sky-pages/sky-pages.config.js index 539b0b45..6b5a9b61 100644 --- a/config/sky-pages/sky-pages.config.js +++ b/config/sky-pages/sky-pages.config.js @@ -4,7 +4,7 @@ const fs = require('fs-extra'); const path = require('path'); const merge = require('merge'); -const logger = require('winston'); +const logger = require('../../utils/logger'); /** * Resolves a path given a root path and an array-like arguments object. diff --git a/config/webpack/serve.webpack.config.js b/config/webpack/serve.webpack.config.js index d87a5b7e..648a33e1 100644 --- a/config/webpack/serve.webpack.config.js +++ b/config/webpack/serve.webpack.config.js @@ -5,7 +5,7 @@ const fs = require('fs'); const path = require('path'); const util = require('util'); const open = require('open'); -const logger = require('winston'); +const logger = require('../../utils/logger'); const webpackMerge = require('webpack-merge'); const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin'); const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin'); diff --git a/index.js b/index.js index 574b266d..db0b6ea3 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,9 @@ /*jshint node: true*/ 'use strict'; -const logger = require('winston'); const webpack = require('webpack'); const WebpackDevServer = require('webpack-dev-server'); +const logger = require('./utils/logger'); const config = require('./config/sky-pages/sky-pages.config'); module.exports = { diff --git a/loader/sky-processor/index.js b/loader/sky-processor/index.js index 9f74da87..96b154c3 100644 --- a/loader/sky-processor/index.js +++ b/loader/sky-processor/index.js @@ -1,7 +1,7 @@ /*jshint node: true*/ 'use strict'; -const logger = require('winston'); +const logger = require('../../utils/logger'); let plugins; const getPluginContents = (skyPagesConfig) => { diff --git a/loader/sky-tslint/program.js b/loader/sky-tslint/program.js index d74461f5..36f7153e 100644 --- a/loader/sky-tslint/program.js +++ b/loader/sky-tslint/program.js @@ -2,7 +2,7 @@ 'use strict'; const tslint = require('tslint'); -const logger = require('winston'); +const logger = require('../../utils/logger'); let _program; const getProgram = (tsconfigPath) => { diff --git a/test/cli-build-public-library.spec.js b/test/cli-build-public-library.spec.js index d2d96f01..c675777c 100644 --- a/test/cli-build-public-library.spec.js +++ b/test/cli-build-public-library.spec.js @@ -4,7 +4,7 @@ const mock = require('mock-require'); const fs = require('fs-extra'); const rimraf = require('rimraf'); -const logger = require('winston'); +const logger = require('../utils/logger'); const skyPagesConfigUtil = require('../config/sky-pages/sky-pages.config'); describe('cli build-public-library', () => { diff --git a/test/cli-build.spec.js b/test/cli-build.spec.js index 8dbfbb39..ccc3ae4b 100644 --- a/test/cli-build.spec.js +++ b/test/cli-build.spec.js @@ -2,7 +2,7 @@ 'use strict'; const mock = require('mock-require'); -const logger = require('winston'); +const logger = require('../utils/logger'); const assetsProcessor = require('../lib/assets-processor'); const runtimeUtils = require('../utils/runtime-test-utils'); diff --git a/test/cli-e2e.spec.js b/test/cli-e2e.spec.js index 088ae924..ce8cf560 100644 --- a/test/cli-e2e.spec.js +++ b/test/cli-e2e.spec.js @@ -3,8 +3,8 @@ const path = require('path'); const mock = require('mock-require'); -const logger = require('winston'); const selenium = require('selenium-standalone'); +const logger = require('../utils/logger'); describe('cli e2e', () => { const PORT = 1234; diff --git a/test/cli-serve.spec.js b/test/cli-serve.spec.js index 049b5cb4..33b47876 100644 --- a/test/cli-serve.spec.js +++ b/test/cli-serve.spec.js @@ -2,8 +2,8 @@ 'use strict'; const mock = require('mock-require'); -const logger = require('winston'); const portfinder = require('portfinder'); +const logger = require('../utils/logger'); describe('cli serve', () => { diff --git a/test/cli-utils-run-compiler.spec.js b/test/cli-utils-run-compiler.spec.js index 89eb620a..59e8fa7f 100644 --- a/test/cli-utils-run-compiler.spec.js +++ b/test/cli-utils-run-compiler.spec.js @@ -2,7 +2,7 @@ 'use strict'; const mock = require('mock-require'); -const logger = require('winston'); +const logger = require('../utils/logger'); describe('cli utils run compiler', () => { const requirePath = '../cli/utils/run-compiler'; diff --git a/test/cli-version.spec.js b/test/cli-version.spec.js index dafacc5b..e55da15c 100644 --- a/test/cli-version.spec.js +++ b/test/cli-version.spec.js @@ -3,7 +3,7 @@ const path = require('path'); const proxyquire = require('proxyquire'); -const logger = require('winston'); +const logger = require('../utils/logger'); describe('cli version', () => { it('should return the version from package.json', () => { diff --git a/test/config-sky-pages.spec.js b/test/config-sky-pages.spec.js index ea75e834..cd7993ab 100644 --- a/test/config-sky-pages.spec.js +++ b/test/config-sky-pages.spec.js @@ -2,7 +2,7 @@ 'use strict'; const fs = require('fs-extra'); -const logger = require('winston'); +const logger = require('../utils/logger'); describe('config sky-pages', () => { diff --git a/test/config-webpack-serve.spec.js b/test/config-webpack-serve.spec.js index 00498e40..8947bf92 100644 --- a/test/config-webpack-serve.spec.js +++ b/test/config-webpack-serve.spec.js @@ -2,8 +2,8 @@ 'use strict'; const mock = require('mock-require'); -const logger = require('winston'); const urlLibrary = require('url'); +const logger = require('../utils/logger'); const runtimeUtils = require('../utils/runtime-test-utils'); describe('config webpack serve', () => { diff --git a/test/loader-processor.spec.js b/test/loader-processor.spec.js index 325ec28c..adc13e34 100644 --- a/test/loader-processor.spec.js +++ b/test/loader-processor.spec.js @@ -2,7 +2,7 @@ 'use strict'; const mock = require('mock-require'); -const logger = require('winston'); +const logger = require('../utils/logger'); describe('SKY UX processor Webpack loader', () => { const preloaderPath = '../loader/sky-processor/preload'; diff --git a/test/sky-pages-out-skyux2.spec.js b/test/sky-pages-out-skyux2.spec.js index 8990297e..9d1258b7 100644 --- a/test/sky-pages-out-skyux2.spec.js +++ b/test/sky-pages-out-skyux2.spec.js @@ -2,7 +2,7 @@ 'use strict'; const mock = require('mock-require'); -const logger = require('winston'); +const logger = require('../utils/logger'); describe('@blackbaud/skyux-builder', () => { diff --git a/test/utils-logger.spec.js b/test/utils-logger.spec.js new file mode 100644 index 00000000..19a4b822 --- /dev/null +++ b/test/utils-logger.spec.js @@ -0,0 +1,29 @@ +/*jshint jasmine: true, node: true */ +'use strict'; + +const mock = require('mock-require'); + +describe('logger', () => { + afterEach(() => { + mock.stopAll(); + }); + + it('should configure a custom transport', () => { + let _transports; + let _colorize = false; + mock('winston', { + Logger: function (opts) { + _transports = opts.transports; + }, + transports: { + Console: function (opts) { + _colorize = opts.colorize; + } + } + }); + + const logger = mock.reRequire('../utils/logger'); + expect(_colorize).toEqual(true); + expect(_transports).toBeDefined(); + }); +}); diff --git a/utils/logger.js b/utils/logger.js new file mode 100644 index 00000000..f2cb5377 --- /dev/null +++ b/utils/logger.js @@ -0,0 +1,17 @@ +/*jshint node: true */ +'use strict'; + +const Winston = require('winston'); + +const logger = new Winston.Logger({ + transports: [ + new Winston.transports.Console({ + level: 'debug', + handleExceptions: true, + json: false, + colorize: true + }) + ] +}); + +module.exports = logger; From b038c7959ec66b655438fe4557a6c6e2e59b92f6 Mon Sep 17 00:00:00 2001 From: Steve Brush Date: Tue, 25 Jul 2017 13:54:34 -0400 Subject: [PATCH 2/2] Update logger.js --- utils/logger.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/logger.js b/utils/logger.js index f2cb5377..d7d263ae 100644 --- a/utils/logger.js +++ b/utils/logger.js @@ -1,11 +1,11 @@ /*jshint node: true */ 'use strict'; -const Winston = require('winston'); +const winston = require('winston'); -const logger = new Winston.Logger({ +const logger = new winston.Logger({ transports: [ - new Winston.transports.Console({ + new winston.transports.Console({ level: 'debug', handleExceptions: true, json: false,