Do not console.log in prod
MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
@@ -58,6 +58,7 @@ export default class Logging {
}
const sizeOfDataKB = Utils.truncTo(sizeof(data) / 1024, 2);
const numberOfRecords = Array.isArray(data) ? data.length : 0;
+ if (Utils.isDevelopmentEnv()) {
const message = `${module}.${method} ${found ? '- ' + executionDurationMillis.toString() + 'ms' : ''}${!Utils.isEmptyJSon(data) ? '- ' + sizeOfDataKB.toString() + 'kB' : ''} ${Array.isArray(data) ? '- ' + numberOfRecords.toString() + 'rec' : ''}`;
console.debug(chalk.green(message));
if (sizeOfDataKB > Constants.PERF_MAX_DATA_VOLUME_KB) {
@@ -72,6 +73,7 @@ export default class Logging {
console.error(chalk.red(message));
console.error(chalk.red('===================================='));
}
+ }
await PerformanceStorage.savePerformanceRecord(
Utils.buildPerformanceRecord({
tenantID,
@@ -273,8 +275,8 @@ export default class Logging {
if (res.getHeader('content-length')) {
sizeOfDataKB = Utils.truncTo(res.getHeader('content-length') as number / 1024, 2);
}
- if (Utils.isDevelopmentEnv()) {
const message = `Express HTTP Response - ${(executionDurationMillis > 0) ? executionDurationMillis : '?'}ms - ${(sizeOfDataKB > 0) ? sizeOfDataKB : '?'}kB >> ${req.method}/${res.statusCode} '${req.url}'`;
+ if (Utils.isDevelopmentEnv()) {
console.debug(chalk.green(message));
if (sizeOfDataKB > Constants.PERF_MAX_DATA_VOLUME_KB) {
console.error(chalk.red('===================================='));
@@ -293,7 +295,7 @@ export default class Logging {
tenantID: tenantID,
user: req.user,
action: ServerAction.HTTP_RESPONSE,
- message: `Express HTTP Response - ${(executionDurationMillis > 0) ? executionDurationMillis : '?'}ms - ${(sizeOfDataKB > 0) ? sizeOfDataKB : '?'}kB >> ${req.method}/${res.statusCode} '${req.url}'`,
+ message,
module: MODULE_NAME, method: 'logExpressResponse',
detailedMessages: {
request: req.url,
@@ -350,8 +352,8 @@ export default class Logging {
if (response.config.headers['Content-Length']) {
sizeOfDataKB = Utils.truncTo(response.config.headers['Content-Length'] / 1024, 2);
}
- if (Utils.isDevelopmentEnv()) {
const message = `Axios HTTP Response - ${(executionDurationMillis > 0) ? executionDurationMillis : '?'}ms - ${(sizeOfDataKB > 0) ? sizeOfDataKB : '?'}kB << ${response.config.method.toLocaleUpperCase()}/${response.status} '${response.config.url}'`;
+ if (Utils.isDevelopmentEnv()) {
console.log(chalk.green(message));
if (sizeOfDataKB > Constants.PERF_MAX_DATA_VOLUME_KB) {
console.error(chalk.red('===================================='));
@@ -369,7 +371,7 @@ export default class Logging {
await Logging.logSecurityDebug({
tenantID: tenantID,
action: ServerAction.HTTP_RESPONSE,
- message: `Axios HTTP Response - ${(executionDurationMillis > 0) ? executionDurationMillis : '?'}ms - ${(sizeOfDataKB > 0) ? sizeOfDataKB : '?'}kB << ${response.config.method.toLocaleUpperCase()}/${response.status} '${response.config.url}'`,
+ message,
module: MODULE_NAME, method: 'logAxiosResponse',
detailedMessages: {
status: response.status,
@@ -894,8 +896,8 @@ export default class Logging {
delete Logging.traceCalls[`${chargeBoxID}~action`];
found = true;
}
- if (Utils.isDevelopmentEnv()) {
const message = `${direction} OCPP Request '${action}' on '${chargeBoxID}' has been processed ${found ? 'in ' + executionDurationMillis.toString() + 'ms' : ''}`;
+ if (Utils.isDevelopmentEnv()) {
console.debug(chalk.green(message));
if (executionDurationMillis > Constants.PERF_MAX_RESPONSE_TIME_MILLIS) {
console.error(chalk.red('===================================='));
@@ -909,7 +911,7 @@ export default class Logging {
tenantID: tenantID,
source: chargeBoxID,
module: module, method: action,
- message: `${direction} OCPP Request has been processed ${found ? 'in ' + executionDurationMillis.toString() + 'ms' : ''}`,
+ message,
action: action,
detailedMessages
});
@@ -918,7 +920,7 @@ export default class Logging {
tenantID: tenantID,
source: chargeBoxID,
module: module, method: action,
- message: `${direction} OCPP Request has been processed ${found ? 'in ' + executionDurationMillis.toString() + 'ms' : ''}`,
+ message,
action: action,
detailedMessages
});

Do not console.log in prod