Skip to content

Commit

Permalink
refactor: replace --level with --loglevel, remove --silent
Browse files Browse the repository at this point in the history
A part of the effort to separate application logging from the reporters output.

Addresses #1089, supersedes #1099, enables #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.
  • Loading branch information
honzajavorek committed Jan 24, 2019
1 parent 79baef6 commit d179975
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?**
Expand Down
3 changes: 1 addition & 2 deletions docs/usage-cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions docs/usage-js.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions lib/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,7 +63,6 @@ function applyConfiguration(config) {
},
options: {
'dry-run': false,
silent: false,
reporter: null,
output: null,
debug: false,
Expand All @@ -63,7 +73,7 @@ function applyConfiguration(config) {
method: [],
only: [],
color: true,
level: 'info',
loglevel: 'warning',
timestamp: false,
sorted: false,
names: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/configureReporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function configureReporters(config, stats, tests, runner) {
}
}

if (!config.options.silent) { addCli(reporters); }
addCli(reporters);

const usedFileReporters = intersection(reporters, fileReporters);

Expand Down
6 changes: 3 additions & 3 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 3 additions & 8 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit d179975

Please sign in to comment.