mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
added process name to logger output
This commit is contained in:
parent
e1f92fef13
commit
1bf8f38793
@ -111,6 +111,8 @@ module.exports = {
|
||||
[
|
||||
'--checkParent', // ...process.argv.slice(3)
|
||||
'--is-forked-api',
|
||||
'--process-display-name',
|
||||
'script',
|
||||
...processArgs.getPassArgs(),
|
||||
],
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
const { setLogger, getLogger } = require('dbgate-tools');
|
||||
const { setLogger, getLogger, setLoggerName } = require('dbgate-tools');
|
||||
const processArgs = require('./utility/processArgs');
|
||||
const pino = require('pino');
|
||||
const pinoms = require('pino-multi-stream');
|
||||
@ -7,13 +7,24 @@ const moment = require('moment');
|
||||
const path = require('path');
|
||||
const { logsdir } = require('./utility/directories');
|
||||
|
||||
if (processArgs.startProcess) {
|
||||
setLoggerName(processArgs.startProcess.replace(/Process$/, ''));
|
||||
}
|
||||
if (processArgs.processDisplayName) {
|
||||
setLoggerName(processArgs.processDisplayName);
|
||||
}
|
||||
|
||||
if (processArgs.listenApi) {
|
||||
// configure logger
|
||||
|
||||
var logger = pinoms({
|
||||
let logger = pinoms({
|
||||
streams: [
|
||||
{ stream: process.stdout }, // an "info" level destination stream
|
||||
{ stream: fs.createWriteStream(path.join(logsdir(), `${moment().format('YYYY-MM-DD-HH-mm')}-${process.pid}.ndjson`)) },
|
||||
{
|
||||
stream: fs.createWriteStream(
|
||||
path.join(logsdir(), `${moment().format('YYYY-MM-DD-HH-mm')}-${process.pid}.ndjson`)
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
|
@ -11,6 +11,7 @@ const startProcess = getNamedArg('--start-process');
|
||||
const isForkedApi = process.argv.includes('--is-forked-api');
|
||||
const pluginsDir = getNamedArg('--plugins-dir');
|
||||
const workspaceDir = getNamedArg('--workspace-dir');
|
||||
const processDisplayName = getNamedArg('--process-display-name');
|
||||
const listenApi = process.argv.includes('--listen-api');
|
||||
const listenApiChild = process.argv.includes('--listen-api-child') || listenApi;
|
||||
|
||||
@ -37,4 +38,5 @@ module.exports = {
|
||||
workspaceDir,
|
||||
listenApi,
|
||||
listenApiChild,
|
||||
processDisplayName,
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
import pino, { Logger } from 'pino';
|
||||
|
||||
let _logger: Logger;
|
||||
let _name: string = null;
|
||||
const defaultLogger: Logger = pino();
|
||||
|
||||
export function setLogger(value: Logger) {
|
||||
@ -10,7 +11,15 @@ export function setLogger(value: Logger) {
|
||||
export function getLogger(caller?: string): Logger {
|
||||
let res = _logger || defaultLogger;
|
||||
if (caller) {
|
||||
res = res.child({ caller });
|
||||
const props = { caller };
|
||||
if (_name) {
|
||||
props['name'] = _name;
|
||||
}
|
||||
res = res.child(props);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export function setLoggerName(value) {
|
||||
_name = value;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user