From d17997562666fcf4479ec3a26fad9173d3fb5d28 Mon Sep 17 00:00:00 2001 From: Honza Javorek Date: Thu, 17 Jan 2019 17:30:51 +0100 Subject: [PATCH] refactor: replace --level with --loglevel, remove --silent A part of the effort to separate application logging from the reporters output. Addresses https://github.com/apiaryio/dredd/issues/1089, supersedes https://github.com/apiaryio/dredd/pull/1099, enables https://github.com/apiaryio/dredd/issues/765 BREAKING CHANGE: Instead of --level use --loglevel. The option is no longer able to affect reporter output, it only affects application logging output. Use --loglevel=silent instead of --silent, which is now removed. The --loglevel option now only accepts 'silent', 'error', 'warning', 'debug' as values. --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- docs/usage-cli.rst | 3 +-- docs/usage-js.rst | 3 +-- lib/configuration.js | 20 +++++++++++++++----- lib/configureReporters.js | 2 +- lib/logger.js | 6 +++--- lib/options.json | 11 +++-------- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index c5fa3f6ec..73b127d40 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -25,7 +25,7 @@ A clear and concise description of what you expected to happen. ( paste your output here ) ``` -**Does `dredd --level=debug` uncover something?** +**Does `dredd --loglevel=debug` uncover something?** If you run Dredd with debugging output, do you see any interesting information relevant to the bug? **Can you send us failing test in a Pull Request?** diff --git a/docs/usage-cli.rst b/docs/usage-cli.rst index c7041f3e7..849a41348 100644 --- a/docs/usage-cli.rst +++ b/docs/usage-cli.rst @@ -70,9 +70,8 @@ See below how sample configuration file could look like. The structure is the sa inline-errors: false details: false method: [] - level: info + loglevel: warning timestamp: false - silent: false path: [] blueprint: api-description.apib endpoint: "http://127.0.0.1:3000" diff --git a/docs/usage-js.rst b/docs/usage-js.rst index ead5826b2..06f6c1607 100644 --- a/docs/usage-js.rst +++ b/docs/usage-js.rst @@ -39,8 +39,7 @@ Let’s have a look at an example configuration first. (Please also see the :ref 'dry-run': false, // Boolean, do not run any real HTTP transaction 'names': false, // Boolean, Print Transaction names and finish, similar to dry-run - 'level': 'info', // String, log-level (info, silly, debug, verbose, ...) - 'silent': false, // Boolean, Silences all logging output + 'loglevel': 'warning', // String, logging level (debug, warning, error, silent) 'only': [], // Array of Strings, run only transaction that match these names diff --git a/lib/configuration.js b/lib/configuration.js index a839265b9..122fae420 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -32,10 +32,21 @@ function applyLoggingOptions(options) { logger.transports.console.timestamp = options.timestamp; reporterOutputLogger.transports.console.timestamp = options.timestamp; - logger.transports.console.silent = options.silent; - reporterOutputLogger.transports.console.silent = options.silent; + if (options.loglevel) { + const loglevel = options.loglevel.toLowerCase(); + if (loglevel === 'silent') { + logger.transports.console.silent = true; + } else if (loglevel === 'warning') { + logger.transports.console.level = 'warn'; + } else if (['debug', 'warn', 'error'].includes(loglevel)) { + logger.transports.console.level = loglevel; + } else { + throw new Error(`Unsupported logging level: '${loglevel}'`); + } + } else { + logger.transports.console.level = 'warn'; + } - logger.transports.console.level = options.level; reporterOutputLogger.transports.console.level = 'test'; return options; @@ -52,7 +63,6 @@ function applyConfiguration(config) { }, options: { 'dry-run': false, - silent: false, reporter: null, output: null, debug: false, @@ -63,7 +73,7 @@ function applyConfiguration(config) { method: [], only: [], color: true, - level: 'info', + loglevel: 'warning', timestamp: false, sorted: false, names: false, diff --git a/lib/configureReporters.js b/lib/configureReporters.js index 68ca16788..60e548056 100644 --- a/lib/configureReporters.js +++ b/lib/configureReporters.js @@ -67,7 +67,7 @@ function configureReporters(config, stats, tests, runner) { } } - if (!config.options.silent) { addCli(reporters); } + addCli(reporters); const usedFileReporters = intersection(reporters, fileReporters); diff --git a/lib/logger.js b/lib/logger.js index 9417f1f17..3792d6f65 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -5,16 +5,16 @@ module.exports = new (winston.Logger)({ new (winston.transports.Console)({ colorize: true }), ], levels: { - silly: 5, - debug: 4, + debug: 5, + silly: 4, verbose: 3, info: 2, warn: 1, error: 0, }, colors: { - silly: 'gray', debug: 'cyan', + silly: 'gray', verbose: 'magenta', info: 'blue', warn: 'yellow', diff --git a/lib/options.json b/lib/options.json index a310084f5..6ac1667d0 100644 --- a/lib/options.json +++ b/lib/options.json @@ -92,21 +92,16 @@ "description": "Determines whether console output should include colors.", "default": true }, - "level": { + "loglevel": { "alias": "l", - "description": "The level of logging to output. Options: silly, debug, verbose, info, warn, error.", - "default": "info" + "description": "The level of logging to output. Options: 'debug', 'warning', 'error', 'silent'.", + "default": "warning" }, "timestamp": { "alias": "t", "description": "Determines whether console output should include timestamps.", "default": false }, - "silent": { - "alias": "q", - "description": "Silences commandline output.", - "default": false - }, "path": { "alias": "p", "description": "Additional API description paths or URLs. Can be used multiple times with glob pattern for paths.",