Use protocol-specific logger
MODIFY
lib/protocol/protocol.js
lib/protocol/protocol.js
@@ -276,6 +276,9 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
driverRes = parsedDriverRes.value;
}
+ // Use the logger that's specific to this response
+ const protocolLogger = isW3C ? w3cLog : mjsonwpLog;
+
// unpack createSession response
if (spec.command === 'createSession') {
newSessionId = driverRes[0];
@@ -306,8 +309,8 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
// delete should not return anything even if successful
if (spec.command === 'deleteSession') {
- log.debug(`Received response: ${_.truncate(JSON.stringify(driverRes), {length: LOG_OBJ_LENGTH})}`);
- log.debug('But deleting session, so not returning');
+ protocolLogger.debug(`Received response: ${_.truncate(JSON.stringify(driverRes), {length: LOG_OBJ_LENGTH})}`);
+ protocolLogger.debug('But deleting session, so not returning');
driverRes = null;
}
@@ -325,7 +328,7 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
httpResBody.status = (_.isNil(driverRes) || _.isUndefined(driverRes.status)) ? JSONWP_SUCCESS_STATUS_CODE : driverRes.status;
}
httpResBody.value = driverRes;
- log.debug(`Responding to client with driver.${spec.command}() ` +
+ protocolLogger.debug(`Responding to client with driver.${spec.command}() ` +
`result: ${_.truncate(JSON.stringify(driverRes), {length: LOG_OBJ_LENGTH})}`);
} catch (err) {
// if anything goes wrong, figure out what our response should be
@@ -340,11 +343,14 @@ function buildHandler (app, method, path, spec, driver, isSessCmd) {
isW3C = driver.isW3CProtocol();
}
+ // Use the logger that's specific to this response
+ const protocolLogger = isW3C ? w3cLog : mjsonwpLog;
+
if (isErrorType(err, errors.ProxyRequestError)) {
- log.error(`Encountered internal error running command: ${JSON.stringify(err)} ${err.stack}`);
+ protocolLogger.error(`Encountered internal error running command: ${JSON.stringify(err)} ${err.stack}`);
actualErr = err.getActualError(driver.protocol);
} else if (!isW3C && (!(isErrorType(err, ProtocolError) || isErrorType(err, errors.BadParametersError)))) {
- log.error(`Encountered internal error running command: ${err.stack}`);
+ protocolLogger.error(`Encountered internal error running command: ${err.stack}`);
actualErr = new errors.UnknownError(err);
}

Use protocol-specific logger (#209)