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)
|
'--checkParent', // ...process.argv.slice(3)
|
||||||
'--is-forked-api',
|
'--is-forked-api',
|
||||||
|
'--process-display-name',
|
||||||
|
'script',
|
||||||
...processArgs.getPassArgs(),
|
...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 processArgs = require('./utility/processArgs');
|
||||||
const pino = require('pino');
|
const pino = require('pino');
|
||||||
const pinoms = require('pino-multi-stream');
|
const pinoms = require('pino-multi-stream');
|
||||||
@ -7,13 +7,24 @@ const moment = require('moment');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { logsdir } = require('./utility/directories');
|
const { logsdir } = require('./utility/directories');
|
||||||
|
|
||||||
|
if (processArgs.startProcess) {
|
||||||
|
setLoggerName(processArgs.startProcess.replace(/Process$/, ''));
|
||||||
|
}
|
||||||
|
if (processArgs.processDisplayName) {
|
||||||
|
setLoggerName(processArgs.processDisplayName);
|
||||||
|
}
|
||||||
|
|
||||||
if (processArgs.listenApi) {
|
if (processArgs.listenApi) {
|
||||||
// configure logger
|
// configure logger
|
||||||
|
|
||||||
var logger = pinoms({
|
let logger = pinoms({
|
||||||
streams: [
|
streams: [
|
||||||
{ stream: process.stdout }, // an "info" level destination stream
|
{ 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 isForkedApi = process.argv.includes('--is-forked-api');
|
||||||
const pluginsDir = getNamedArg('--plugins-dir');
|
const pluginsDir = getNamedArg('--plugins-dir');
|
||||||
const workspaceDir = getNamedArg('--workspace-dir');
|
const workspaceDir = getNamedArg('--workspace-dir');
|
||||||
|
const processDisplayName = getNamedArg('--process-display-name');
|
||||||
const listenApi = process.argv.includes('--listen-api');
|
const listenApi = process.argv.includes('--listen-api');
|
||||||
const listenApiChild = process.argv.includes('--listen-api-child') || listenApi;
|
const listenApiChild = process.argv.includes('--listen-api-child') || listenApi;
|
||||||
|
|
||||||
@ -37,4 +38,5 @@ module.exports = {
|
|||||||
workspaceDir,
|
workspaceDir,
|
||||||
listenApi,
|
listenApi,
|
||||||
listenApiChild,
|
listenApiChild,
|
||||||
|
processDisplayName,
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import pino, { Logger } from 'pino';
|
import pino, { Logger } from 'pino';
|
||||||
|
|
||||||
let _logger: Logger;
|
let _logger: Logger;
|
||||||
|
let _name: string = null;
|
||||||
const defaultLogger: Logger = pino();
|
const defaultLogger: Logger = pino();
|
||||||
|
|
||||||
export function setLogger(value: Logger) {
|
export function setLogger(value: Logger) {
|
||||||
@ -10,7 +11,15 @@ export function setLogger(value: Logger) {
|
|||||||
export function getLogger(caller?: string): Logger {
|
export function getLogger(caller?: string): Logger {
|
||||||
let res = _logger || defaultLogger;
|
let res = _logger || defaultLogger;
|
||||||
if (caller) {
|
if (caller) {
|
||||||
res = res.child({ caller });
|
const props = { caller };
|
||||||
|
if (_name) {
|
||||||
|
props['name'] = _name;
|
||||||
|
}
|
||||||
|
res = res.child(props);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setLoggerName(value) {
|
||||||
|
_name = value;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user