Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
refactor: log only as error, warning, and debug
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Jan 23, 2019
1 parent 3144251 commit 548df20
Show file tree
Hide file tree
Showing 30 changed files with 171 additions and 184 deletions.
2 changes: 0 additions & 2 deletions docs/hooks/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ You can get a list of all transaction names available in your API description do
:emphasize-lines: 3, 5
$ dredd ./blog.apib http://127.0.0.1 --names
info: Beginning Dredd testing...
info: Articles > List articles
skip: GET (200) /articles
info: Articles > Publish an article
Expand All @@ -156,7 +155,6 @@ You can get a list of all transaction names available in your API description do
:emphasize-lines: 3, 5
$ dredd ./blog.yaml http://127.0.0.1 --names
info: Beginning Dredd testing...
info: Articles > List articles > 200 > application/json
skip: GET (200) /articles
info: Articles > Publish an article > 201 > application/json
Expand Down
2 changes: 0 additions & 2 deletions docs/how-to-guides.rst
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ Dredd will detect two HTTP transaction examples and will compile following trans
::

$ dredd api-description.apib http://127.0.0.1 --names
info: Beginning Dredd testing...
info: Resource > Update Resource > Example 1
info: Resource > Update Resource > Example 2

Expand Down Expand Up @@ -687,7 +686,6 @@ Command-line output of complex HTTP responses and expectations can be hard to re

$ dredd apiary.apib http://127.0.0.1 --reporter=apiary
warn: Apiary API Key or API Project Subdomain were not provided. Configure Dredd to be able to save test reports alongside your Apiary API project: https://dredd.org/en/latest/how-to-guides/#using-apiary-reporter-and-apiary-tests
info: Beginning Dredd testing...
pass: DELETE /honey duration: 884ms
complete: 1 passing, 0 failing, 0 errors, 0 skipped, 1 total
complete: Tests took 1631ms
Expand Down
48 changes: 24 additions & 24 deletions lib/CLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ Example:
// Gracefully terminate server
stopServer(callback) {
if (!this.serverProcess || !this.serverProcess.spawned) {
logger.verbose('No backend server process to terminate.');
logger.debug('No backend server process to terminate.');
return callback();
}
if (this.serverProcess.terminated) {
logger.debug('The backend server process has already terminated');
return callback();
}
logger.verbose('Terminating backend server process, PID', this.serverProcess.pid);
logger.debug('Terminating backend server process, PID', this.serverProcess.pid);
this.serverProcess.terminate({ force: true });
this.serverProcess.on('exit', () => callback());
}
Expand All @@ -80,7 +80,7 @@ Example:

if (this.exit) {
this._processExit = (exitStatus) => {
logger.verbose(`Exiting Dredd process with status '${exitStatus}'.`);
logger.debug(`Exiting Dredd process with status '${exitStatus}'.`);
logger.debug('Using configured custom exit() method to terminate the Dredd process.');
this.finished = true;
this.stopServer(() => {
Expand All @@ -89,19 +89,19 @@ Example:
};
} else {
this._processExit = (exitStatus) => {
logger.verbose(`Exiting Dredd process with status '${exitStatus}'.`);
logger.debug(`Exiting Dredd process with status '${exitStatus}'.`);
logger.debug('Using native process.exit() method to terminate the Dredd process.');
this.stopServer(() => process.exit(exitStatus));
};
}
} else {
this._processExit = (exitStatus) => {
logger.verbose(`Exiting Dredd process with status '${exitStatus}'.`);
logger.debug(`Exiting Dredd process with status '${exitStatus}'.`);
logger.debug('Using configured custom callback to terminate the Dredd process.');
this.finished = true;
if (this.sigIntEventAdded) {
if (this.serverProcess && !this.serverProcess.terminated) {
logger.verbose('Killing backend server process before Dredd exits.');
logger.debug('Killing backend server process before Dredd exits.');
this.serverProcess.signalKill();
}
process.removeEventListener('SIGINT', this.commandSigInt);
Expand Down Expand Up @@ -145,7 +145,7 @@ Example:
runExitingActions() {
// Run interactive config
if (this.argv._[0] === 'init' || this.argv.init === true) {
logger.silly('Starting interactive configuration.');
logger.debug('Starting interactive configuration.');
this.finished = true;
interactiveConfig(this.argv, (config) => {
configUtils.save(config);
Expand All @@ -156,13 +156,13 @@ Example:

// Show help
} else if (this.argv.help === true) {
logger.silly('Printing help.');
logger.debug('Printing help.');
this.optimist.showHelp(console.error);
this._processExit(0);

// Show version
} else if (this.argv.version === true) {
logger.silly('Printing version.');
logger.debug('Printing version.');
console.log(`\
${packageData.name} v${packageData.version} \
(${os.type()} ${os.release()}; ${os.arch()})\
Expand All @@ -173,10 +173,10 @@ ${packageData.name} v${packageData.version} \

loadDreddFile() {
const configPath = this.argv.config;
logger.verbose('Loading configuration file:', configPath);
logger.debug('Loading configuration file:', configPath);

if (configPath && fs.existsSync(configPath)) {
logger.info(`Configuration '${configPath}' found, ignoring other arguments.`);
logger.debug(`Configuration '${configPath}' found, ignoring other arguments.`);
this.argv = configUtils.load(configPath);
}

Expand All @@ -197,33 +197,33 @@ ${packageData.name} v${packageData.version} \

runServerAndThenDredd() {
if (!this.argv.server) {
logger.verbose('No backend server process specified, starting testing at once');
logger.debug('No backend server process specified, starting testing at once');
this.runDredd(this.dreddInstance);
} else {
logger.verbose('Backend server process specified, starting backend server and then testing');
logger.debug('Backend server process specified, starting backend server and then testing');

const parsedArgs = spawnArgs(this.argv.server);
const command = parsedArgs.shift();

logger.verbose(`Using '${command}' as a server command, ${JSON.stringify(parsedArgs)} as arguments`);
logger.debug(`Using '${command}' as a server command, ${JSON.stringify(parsedArgs)} as arguments`);
this.serverProcess = spawn(command, parsedArgs);
logger.info(`Starting backend server process with command: ${this.argv.server}`);
logger.debug(`Starting backend server process with command: ${this.argv.server}`);

this.serverProcess.stdout.setEncoding('utf8');
this.serverProcess.stdout.on('data', data => process.stdout.write(data.toString()));

this.serverProcess.stderr.setEncoding('utf8');
this.serverProcess.stderr.on('data', data => process.stdout.write(data.toString()));

this.serverProcess.on('signalTerm', () => logger.verbose('Gracefully terminating the backend server process'));
this.serverProcess.on('signalKill', () => logger.verbose('Killing the backend server process'));
this.serverProcess.on('signalTerm', () => logger.debug('Gracefully terminating the backend server process'));
this.serverProcess.on('signalKill', () => logger.debug('Killing the backend server process'));

this.serverProcess.on('crash', (exitStatus, killed) => {
if (killed) { logger.info('Backend server process was killed'); }
if (killed) { logger.debug('Backend server process was killed'); }
});

this.serverProcess.on('exit', () => {
logger.info('Backend server process exited');
logger.debug('Backend server process exited');
});

this.serverProcess.on('error', (err) => {
Expand All @@ -234,22 +234,22 @@ ${packageData.name} v${packageData.version} \
// Ensure server is not running when dredd exits prematurely somewhere
process.on('beforeExit', () => {
if (this.serverProcess && !this.serverProcess.terminated) {
logger.verbose('Killing backend server process before Dredd exits');
logger.debug('Killing backend server process before Dredd exits');
this.serverProcess.signalKill();
}
});

// Ensure server is not running when dredd exits prematurely somewhere
process.on('exit', () => {
if (this.serverProcess && !this.serverProcess.terminated) {
logger.verbose('Killing backend server process on Dredd\'s exit');
logger.debug('Killing backend server process on Dredd\'s exit');
this.serverProcess.signalKill();
}
});

const waitSecs = parseInt(this.argv['server-wait'], 10);
const waitMilis = waitSecs * 1000;
logger.info(`Waiting ${waitSecs} seconds for backend server process to start`);
logger.debug(`Waiting ${waitSecs} seconds for backend server process to start`);

this.wait = setTimeout(() => {
this.runDredd(this.dreddInstance);
Expand Down Expand Up @@ -356,9 +356,9 @@ ${packageData.name} v${packageData.version} \
process.on('SIGINT', this.commandSigInt);
}

logger.verbose('Running Dredd instance.');
logger.debug('Running Dredd instance.');
dreddInstance.run((error, stats) => {
logger.verbose('Dredd instance run finished.');
logger.debug('Dredd instance run finished.');
this.exitWithStatus(error, stats);
});

Expand Down
18 changes: 9 additions & 9 deletions lib/Dredd.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ${proxySettings.join(', ')}. Please read documentation on how
Dredd works with proxies:
https://dredd.org/en/latest/how-it-works/#using-https-proxy
`;
logger.verbose(message);
logger.debug(message);
}
}

Expand Down Expand Up @@ -122,27 +122,27 @@ https://dredd.org/en/latest/how-it-works/#using-https-proxy
}

// Spin that merry-go-round
logger.verbose('Expanding glob patterns.');
logger.debug('Expanding glob patterns.');
this.expandGlobs((globsErr) => {
if (globsErr) { return callback(globsErr, this.stats); }

logger.verbose('Reading API description files.');
logger.debug('Reading API description files.');
this.loadFiles((loadErr) => {
if (loadErr) { return callback(loadErr, this.stats); }

logger.verbose('Parsing API description files and compiling a list of HTTP transactions to test.');
logger.debug('Parsing API description files and compiling a list of HTTP transactions to test.');
this.compileTransactions((compileErr) => {
if (compileErr) { return callback(compileErr, this.stats); }

logger.verbose('Starting reporters and waiting until all of them are ready.');
logger.debug('Starting reporters and waiting until all of them are ready.');
this.emitStart((emitStartErr) => {
if (emitStartErr) { return callback(emitStartErr, this.stats); }

logger.verbose('Starting transaction runner.');
logger.debug('Starting transaction runner.');
this.startRunner((runnerErr) => {
if (runnerErr) { return callback(runnerErr, this.stats); }

logger.verbose('Wrapping up testing.');
logger.debug('Wrapping up testing.');
this.transactionsComplete(callback);
});
});
Expand Down Expand Up @@ -196,7 +196,7 @@ API description document (or documents) not found on path:
async.eachLimit(this.configuration.files, 6, (fileUrlOrPath, loadCallback) => {
const { protocol, host } = url.parse(fileUrlOrPath);
if (host && ['http:', 'https:'].includes(protocol)) {
logger.verbose('Downloading remote file:', fileUrlOrPath);
logger.debug('Downloading remote file:', fileUrlOrPath);
this.downloadFile(fileUrlOrPath, loadCallback);
} else {
this.readLocalFile(fileUrlOrPath, loadCallback);
Expand Down Expand Up @@ -255,7 +255,7 @@ Is the provided path correct?
const fileData = this.configuration.data[filename];
if (!fileData.annotations) { fileData.annotations = []; }

logger.verbose('Compiling HTTP transactions from API description file:', filename);
logger.debug('Compiling HTTP transactions from API description file:', filename);
dreddTransactions.compile(fileData.raw, filename, (compilationError, compilationResult) => {
if (compilationError) { return next(compilationError); }

Expand Down
34 changes: 17 additions & 17 deletions lib/HooksWorkerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ class HooksWorkerClient {
}

start(callback) {
logger.verbose('Looking up hooks handler implementation:', this.language);
logger.debug('Looking up hooks handler implementation:', this.language);
this.setCommandAndCheckForExecutables((executablesError) => {
if (executablesError) { return callback(executablesError); }

logger.verbose('Starting hooks handler.');
logger.debug('Starting hooks handler.');
this.spawnHandler((spawnHandlerError) => {
if (spawnHandlerError) { return callback(spawnHandlerError); }

logger.verbose('Connecting to hooks handler.');
logger.debug('Connecting to hooks handler.');
this.connectToHandler((connectHandlerError) => {
if (connectHandlerError) { return callback(connectHandlerError); }

logger.verbose('Registering hooks.');
logger.debug('Registering hooks.');
this.registerHooks((registerHooksError) => {
if (registerHooksError) { return callback(registerHooksError); }
callback();
Expand All @@ -57,7 +57,7 @@ class HooksWorkerClient {
}

terminateHandler(callback) {
logger.verbose('Terminating hooks handler process, PID', this.handler.pid);
logger.debug('Terminating hooks handler process, PID', this.handler.pid);
if (this.handler.terminated) {
logger.debug('The hooks handler process has already terminated');
return callback();
Expand Down Expand Up @@ -169,7 +169,7 @@ $ go get github.com/snikch/goodman/cmd/goodman
this.handlerCommand = parsedArgs.shift();
this.handlerCommandArgs = parsedArgs;

logger.verbose(`Using '${this.handlerCommand}' as a hook handler command, '${this.handlerCommandArgs.join(' ')}' as arguments`);
logger.debug(`Using '${this.handlerCommand}' as a hook handler command, '${this.handlerCommandArgs.join(' ')}' as arguments`);
if (!which.which(this.handlerCommand)) {
msg = `Hooks handler command not found: ${this.handlerCommand}`;
callback(new Error(msg));
Expand All @@ -183,14 +183,14 @@ $ go get github.com/snikch/goodman/cmd/goodman
const pathGlobs = [].concat(this.runner.hooks.configuration.options.hookfiles);
const handlerCommandArgs = this.handlerCommandArgs.concat(pathGlobs);

logger.info(`Spawning '${this.language}' hooks handler process.`);
logger.debug(`Spawning '${this.language}' hooks handler process.`);
this.handler = spawn(this.handlerCommand, handlerCommandArgs);

this.handler.stdout.on('data', data => logger.info('Hooks handler stdout:', data.toString()));
this.handler.stderr.on('data', data => logger.info('Hooks handler stderr:', data.toString()));
this.handler.stdout.on('data', data => logger.debug('Hooks handler stdout:', data.toString()));
this.handler.stderr.on('data', data => logger.debug('Hooks handler stderr:', data.toString()));

this.handler.on('signalTerm', () => logger.verbose('Gracefully terminating the hooks handler process'));
this.handler.on('signalKill', () => logger.verbose('Killing the hooks handler process'));
this.handler.on('signalTerm', () => logger.debug('Gracefully terminating the hooks handler process'));
this.handler.on('signalKill', () => logger.debug('Killing the hooks handler process'));

this.handler.on('crash', (exitStatus, killed) => {
let msg;
Expand Down Expand Up @@ -236,7 +236,7 @@ $ go get github.com/snikch/goodman/cmd/goodman
};

const connectAndSetupClient = () => {
logger.verbose('Starting TCP connection with hooks handler process.');
logger.debug('Starting TCP connection with hooks handler process.');

if (this.runner.hookHandlerError) {
callback(this.runner.hookHandlerError);
Expand All @@ -245,7 +245,7 @@ $ go get github.com/snikch/goodman/cmd/goodman
this.handlerClient = net.connect({ port: this.handlerPort, host: this.handlerHost });

this.handlerClient.on('connect', () => {
logger.info(`Successfully connected to hooks handler. Waiting ${this.afterConnectWait / 1000}s to start testing.`);
logger.debug(`Successfully connected to hooks handler. Waiting ${this.afterConnectWait / 1000}s to start testing.`);
this.clientConnected = true;
clearTimeout(timeout);
setTimeout(callback, this.afterConnectWait);
Expand Down Expand Up @@ -278,10 +278,10 @@ $ go get github.com/snikch/goodman/cmd/goodman
const result = [];
for (const message of messages) {
if (message.uuid) {
logger.verbose('Dredd received a valid message from hooks handler:', message.uuid);
logger.debug('Dredd received a valid message from hooks handler:', message.uuid);
result.push(this.emitter.emit(message.uuid, message));
} else {
result.push(logger.verbose('UUID not present in hooks handler message, ignoring:', JSON.stringify(message, null, 2)));
result.push(logger.debug('UUID not present in hooks handler message, ignoring:', JSON.stringify(message, null, 2)));
}
}
return result;
Expand Down Expand Up @@ -312,14 +312,14 @@ $ go get github.com/snikch/goodman/cmd/goodman
data,
};

logger.verbose('Sending HTTP transaction data to hooks handler:', uuid);
logger.debug('Sending HTTP transaction data to hooks handler:', uuid);
this.handlerClient.write(JSON.stringify(message));
this.handlerClient.write(this.handlerMessageDelimiter);

// Register event for the sent transaction
function messageHandler(receivedMessage) {
let value;
logger.verbose('Handling hook:', uuid);
logger.debug('Handling hook:', uuid);
clearTimeout(timeout);

// We are directly modifying the `data` argument here. Neither direct
Expand Down
Loading

0 comments on commit 548df20

Please sign in to comment.