mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 23:06:00 +00:00
20 lines
525 B
JavaScript
20 lines
525 B
JavaScript
const byline = require('byline');
|
|
const { safeJsonParse, getLogger } = require('dbgate-tools');
|
|
const logger = getLogger();
|
|
|
|
const logDispatcher = method => data => {
|
|
const json = safeJsonParse(data.toString());
|
|
if (json && json.level) {
|
|
logger.log(json);
|
|
} else {
|
|
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;
|