pipe logs from forks into pino logger

This commit is contained in:
Jan Prochazka
2023-01-22 10:00:01 +01:00
parent af01d95348
commit e1f92fef13
7 changed files with 99 additions and 41 deletions

View File

@@ -0,0 +1,15 @@
const byline = require('byline');
const { safeJsonParse, getLogger } = require('dbgate-tools');
const logger = getLogger();
const logDispatcher = method => data => {
const json = safeJsonParse(data.toString());
logger[method](json || data.toString());
};
function pipeForkLogs(subprocess) {
byline(subprocess.stdout).on('data', logDispatcher('info'));
byline(subprocess.stderr).on('data', logDispatcher('error'));
}
module.exports = pipeForkLogs;