mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 14:16:01 +00:00
pipe logs from forks into pino logger
This commit is contained in:
15
packages/api/src/utility/pipeForkLogs.js
Normal file
15
packages/api/src/utility/pipeForkLogs.js
Normal 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;
|
||||
Reference in New Issue
Block a user