Added chalk to console.error
MODIFY
src/client/websocket/WSClient.ts
src/client/websocket/WSClient.ts
@@ -5,6 +5,7 @@ import Logging from '../../utils/Logging';
import { ServerAction } from '../../types/Server';
import Utils from '../../utils/Utils';
import WebSocket from 'ws';
+import chalk from 'chalk';
const MODULE_NAME = 'WSClient';
@@ -147,7 +148,7 @@ export default class WSClient {
});
} else {
// eslint-disable-next-line no-console
- (Utils.isDevelopmentEnv() || Utils.isTestEnv()) && console.error(`WSClient connection refused to '${this.url}':`, error);
+ (Utils.isDevelopmentEnv() || Utils.isTestEnv()) && console.error(chalk.red(`WSClient connection refused to '${this.url}':`), chalk.red(error));
}
break;
default:
@@ -162,7 +163,7 @@ export default class WSClient {
});
} else {
// eslint-disable-next-line no-console
- (Utils.isDevelopmentEnv() || Utils.isTestEnv()) && console.error(`WSClient connection error to '${this.url}':`, error);
+ (Utils.isDevelopmentEnv() || Utils.isTestEnv()) && console.error(chalk.red(`WSClient connection error to '${this.url}':`), chalk.red(error));
}
break;
}
@@ -197,7 +198,7 @@ export default class WSClient {
});
} else {
// eslint-disable-next-line no-console
- (Utils.isDevelopmentEnv() || Utils.isTestEnv()) && console.error(`WSClient Connection closing error to '${this.url}', Reason: '${reason ? reason : 'No reason given'}', Message: '${Utils.getWebSocketCloseEventStatusString(code)}', Code: '${code}'`);
+ (Utils.isDevelopmentEnv() || Utils.isTestEnv()) && console.error(chalk.red(`WSClient Connection closing error to '${this.url}', Reason: '${reason ? reason : 'No reason given'}', Message: '${Utils.getWebSocketCloseEventStatusString(code)}', Code: '${code}'`));
}
break;
}

MODIFY
src/migration/MigrationHandler.ts
src/migration/MigrationHandler.ts
@@ -10,6 +10,7 @@ import MigrationTask from './MigrationTask';
import RemoveDuplicateTagVisualIDsTask from './tasks/RemoveDuplicateTagVisualIDsTask';
import RestoreDataIntegrityInSiteUsersTask from './tasks/RestoreDataIntegrityInSiteUsersTask';
import { ServerAction } from '../types/Server';
+import chalk from 'chalk';
import cluster from 'cluster';
import moment from 'moment';
@@ -142,7 +143,7 @@ export default class MigrationHandler {
message: logMsg,
detailedMessages: { error: error.stack }
});
- console.error(logMsg);
+ console.error(chalk.red(logMsg));
}
}
}

MODIFY
src/server/rest/CentralRestServer.ts
src/server/rest/CentralRestServer.ts
@@ -17,6 +17,7 @@ import { ServerAction } from '../../types/Server';
import { ServerUtils } from '../ServerUtils';
import UserToken from '../../types/UserToken';
import Utils from '../../utils/Utils';
+import chalk from 'chalk';
import cluster from 'cluster';
import http from 'http';
import jwtAuth from 'socketio-jwt-auth';
@@ -99,7 +100,7 @@ export default class CentralRestServer {
});
const userToken: UserToken = socket.request['user'];
if (!userToken || !userToken['logged_in']) {
- CentralRestServer.centralSystemRestConfig.debug && console.error('SocketIO client is trying to connect without token from ' + socket.handshake.headers['origin']);
+ CentralRestServer.centralSystemRestConfig.debug && console.error(chalk.red('SocketIO client is trying to connect without token from ' + socket.handshake.headers['origin']));
await Logging.logWarning({
tenantID: Constants.DEFAULT_TENANT,
module: MODULE_NAME, method: 'startSocketIO',
@@ -126,7 +127,7 @@ export default class CentralRestServer {
detailedMessages: { socketIOid: socket.id, socketIOHandshake: socket.handshake }
});
} catch (error) {
- CentralRestServer.centralSystemRestConfig.debug && console.error(`${userToken.tenantName ? userToken.tenantName : userToken.tenantID} - ${Utils.buildUserFullName(userToken, false)} - SocketIO error when trying to join a room: ${error}`);
+ CentralRestServer.centralSystemRestConfig.debug && console.error(chalk.red(`${userToken.tenantName ? userToken.tenantName : userToken.tenantID} - ${Utils.buildUserFullName(userToken, false)} - SocketIO error when trying to join a room: ${error}`));
await Logging.logError({
tenantID: userToken.tenantID,
module: MODULE_NAME, method: 'startSocketIO',

MODIFY
src/start.ts
src/start.ts
@@ -26,6 +26,7 @@ import { ServerAction } from './types/Server';
import SoapCentralSystemServer from './server/ocpp/soap/SoapCentralSystemServer';
import StorageConfiguration from './types/configuration/StorageConfiguration';
import Utils from './utils/Utils';
+import chalk from 'chalk';
import cluster from 'cluster';
import global from './types/GlobalType';
@@ -151,7 +152,7 @@ export default class Bootstrap {
} catch (error) {
// Log
// eslint-disable-next-line no-console
- console.error(error);
+ console.error(chalk.red(error));
await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.STARTUP,
@@ -228,7 +229,7 @@ export default class Bootstrap {
} catch (error) {
// Log
// eslint-disable-next-line no-console
- console.error(error);
+ console.error(chalk.red(error));
await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.STARTUP,
@@ -323,7 +324,7 @@ export default class Bootstrap {
} catch (error) {
// Log
// eslint-disable-next-line no-console
- console.error(error);
+ console.error(chalk.red(error));
await Logging.logError({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.STARTUP,
@@ -338,6 +339,6 @@ export default class Bootstrap {
// Start
Bootstrap.start().catch(
(error) => {
- console.error(error);
+ console.error(chalk.red(error));
}
);

MODIFY
src/storage/mongodb/MongoDBStorage.ts
src/storage/mongodb/MongoDBStorage.ts
@@ -12,6 +12,7 @@ import MigrationConfiguration from '../../types/configuration/MigrationConfigura
import { ServerAction } from '../../types/Server';
import StorageConfiguration from '../../types/configuration/StorageConfiguration';
import Utils from '../../utils/Utils';
+import chalk from 'chalk';
import cluster from 'cluster';
import urlencode from 'urlencode';
@@ -342,7 +343,7 @@ export default class MongoDBStorage {
try {
await this.db.createCollection(tenantCollectionName);
} catch (error) {
- console.error(`>>>>> Error in creating collection '${tenantCollectionName}': ${error.message as string}`);
+ console.error(chalk.red(`Error in creating collection '${tenantCollectionName}': ${error.message as string}`));
}
}
// Indexes?
@@ -372,7 +373,7 @@ export default class MongoDBStorage {
await this.db.collection(tenantCollectionName).dropIndex(databaseIndex.key);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- console.error(`>>>>> Error in dropping index '${databaseIndex.name}' in '${tenantCollectionName}': ${error.message}`);
+ console.error(chalk.red(`Error in dropping index '${databaseIndex.name}' in '${tenantCollectionName}': ${error.message}`));
}
}
}
@@ -390,7 +391,7 @@ export default class MongoDBStorage {
// eslint-disable-next-line @typescript-eslint/await-thenable
await this.db.collection(tenantCollectionName).createIndex(index.fields, index.options);
} catch (error) {
- console.error(`>>>>> Error in creating index '${JSON.stringify(index.fields)}' with options '${JSON.stringify(index.options)}' in '${tenantCollectionName}': ${error.message as string}`);
+ console.error(chalk.red(`Error in creating index '${JSON.stringify(index.fields)}' with options '${JSON.stringify(index.options)}' in '${tenantCollectionName}': ${error.message as string}`));
}
}
}

MODIFY
src/utils/Configuration.ts
src/utils/Configuration.ts
@@ -31,6 +31,7 @@ import SchedulerConfiguration from '../types/configuration/SchedulerConfiguratio
import StorageConfiguration from '../types/configuration/StorageConfiguration';
import WSClientConfiguration from '../types/configuration/WSClientConfiguration';
import WSDLEndpointConfiguration from '../types/configuration/WSDLEndpointConfiguration';
+import chalk from 'chalk';
import fs from 'fs';
import global from './../types/GlobalType';
import os from 'os';
@@ -316,7 +317,7 @@ export default class Configuration {
if (!Configuration.isUndefined(mongoDBServiceCredentials['uri'])) {
storageConfig.uri = mongoDBServiceCredentials['uri'];
} else {
- console.error('Connection URI not found in MongoDB Atlas User Provided Service');
+ console.error(chalk.red('Connection URI not found in MongoDB Atlas User Provided Service'));
}
}
}
@@ -439,10 +440,10 @@ export default class Configuration {
return credentials[key];
}
if (Configuration.isNullOrUndefined(credentials)) {
- console.error(`Credentials '${upsName}' User Provided Service not found or bound to the application in CF space`);
+ console.error(chalk.red(`Credentials '${upsName}' User Provided Service not found or bound to the application in CF space`));
}
if (!Configuration.isNullOrUndefined(credentials) && Configuration.isUndefined(credentials[key])) {
- console.error(`Credential key ${key} not found in '${upsName}' User Provided Service in CF space`);
+ console.error(chalk.red(`Credential key ${key} not found in '${upsName}' User Provided Service in CF space`));
}
}

Added chalk to console.error