diff --git a/.eslintrc.json b/.eslintrc.json index ac4441146..8a84cb14b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -398,7 +398,9 @@ "sqlcharacter", "peerlist", "www", - "craetedat" + "craetedat", + "tcp", + "appender" ], "skipWordIfMatch": [ "^\\d+px", diff --git a/app/common/commonUtils.ts b/app/common/commonUtils.ts deleted file mode 100644 index 140ba26ab..000000000 --- a/app/common/commonUtils.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - */ - -import { helper } from './helper'; - -const logger = helper.getLogger('ForkSenderHandler'); - -/** - * Returns the number of milliseconds between midnight, - * January 1, 1970 Universal Coordinated Time (UTC) (or GMT) and the specified date. - * - * @param {*} dateStr - * @returns - */ - -export function toUTCmilliseconds(dateStr: any) { - let startSyncMills = null; - try { - startSyncMills = Date.parse(dateStr); - } catch (err) { - logger.error('Unparsable date format, dateStr= ', dateStr, ' ', err); - } - return startSyncMills; -} diff --git a/app/common/helper.ts b/app/common/helper.ts index 2ef502758..e6aa469cf 100644 --- a/app/common/helper.ts +++ b/app/common/helper.ts @@ -68,45 +68,68 @@ export class helper { consoleLevel = process.env.LOG_LEVEL_CONSOLE; } - const logConfig = { - appenders: { - app: { - type: 'dateFile', - filename: appLog, - maxLogSize: 8 * 1024 * 1024, - daysToKeep: 7 + let logConfig: any = {}; + if (!yn(process.env.FORK)) { + logConfig = { + appenders: { + app: { + type: 'dateFile', + filename: appLog, + maxLogSize: 8 * 1024 * 1024, + daysToKeep: 7 + }, + db: { + type: 'dateFile', + filename: dbLog, + maxLogSize: 8 * 1024 * 1024, + daysToKeep: 7 + }, + console: { + type: 'dateFile', + filename: consoleLog, + maxLogSize: 8 * 1024 * 1024, + daysToKeep: 7 + }, + consoleFilter: { + type: 'logLevelFilter', + appender: 'console', + level: consoleLevel + } }, - db: { - type: 'dateFile', - filename: dbLog, - maxLogSize: 8 * 1024 * 1024, - daysToKeep: 7 - }, - console: { - type: 'dateFile', - filename: consoleLog, - maxLogSize: 8 * 1024 * 1024, - daysToKeep: 7 - }, - consoleFilter: { - type: 'logLevelFilter', - appender: 'console', - level: consoleLevel + categories: { + default: { appenders: ['consoleFilter', 'app'], level: appLevel }, + PgService: { appenders: ['consoleFilter', 'db'], level: dbLevel } } - }, - categories: { - default: { appenders: ['consoleFilter', 'app'], level: appLevel }, - PgService: { appenders: ['consoleFilter', 'db'], level: dbLevel } - } - }; + }; - if (process.env.LOG_CONSOLE_STDOUT) { - if (yn(process.env.LOG_CONSOLE_STDOUT)) { - logConfig.appenders.console = { - ...logConfig.appenders.console, - type: 'console' + if (moduleName === 'main') { + // Should initiate logger once with tcp-server appender + logConfig.appenders = { + ...logConfig.appenders, + server: { type: 'tcp-server' } }; } + + if (process.env.LOG_CONSOLE_STDOUT) { + if (yn(process.env.LOG_CONSOLE_STDOUT)) { + logConfig.appenders.console = { + ...logConfig.appenders.console, + type: 'console' + }; + } + } + } else { + logConfig = { + appenders: { + network: { + type: 'tcp' + } + }, + categories: { + default: { appenders: ['network'], level: appLevel }, + PgService: { appenders: ['network'], level: dbLevel } + } + }; } log4js.configure(logConfig); diff --git a/app/sync/listener/ForkListenerHandler.ts b/app/sync/listener/ForkListenerHandler.ts index 111115882..3632f734e 100644 --- a/app/sync/listener/ForkListenerHandler.ts +++ b/app/sync/listener/ForkListenerHandler.ts @@ -31,7 +31,13 @@ export class ForkListenerHandler { * @memberof ForkListenerHandler */ async initialize(args) { - this.syncProcessor = fork(path.resolve(__dirname, '../../sync.js'), args); + this.syncProcessor = fork(path.resolve(__dirname, '../../sync.js'), args, { + env: { + ...process.env, + // Mark forked process explicitly for logging using TCP server + FORK: '1' + } + }); this.syncProcessor.on('message', msg => { this.platform.getProxy().processSyncMessage(msg);