Skip to content

Commit

Permalink
BE-880 Fix incorrect multi-process logging (#260)
Browse files Browse the repository at this point in the history
* BE-880 Fix incorrect multi-process logging

Signed-off-by: Atsushi Neki <nekiaiken@gmail.com>

* BE-880 Add some comments for implementaion

Signed-off-by: Atsushi Neki <nekiaiken@gmail.com>
  • Loading branch information
nekia authored Aug 10, 2021
1 parent 79ec06f commit 1448548
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 61 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@
"sqlcharacter",
"peerlist",
"www",
"craetedat"
"craetedat",
"tcp",
"appender"
],
"skipWordIfMatch": [
"^\\d+px",
Expand Down
25 changes: 0 additions & 25 deletions app/common/commonUtils.ts

This file was deleted.

91 changes: 57 additions & 34 deletions app/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion app/sync/listener/ForkListenerHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1448548

Please sign in to comment.