mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 17:24:00 +00:00
#360 allow to set log level
This commit is contained in:
@@ -20,9 +20,13 @@ function configureLogger() {
|
|||||||
|
|
||||||
let logger = pinoms({
|
let logger = pinoms({
|
||||||
streams: [
|
streams: [
|
||||||
{ stream: process.stdout }, // an "info" level destination stream
|
{
|
||||||
|
stream: process.stdout,
|
||||||
|
level: process.env.CONSOLE_LOG_LEVEL || process.env.LOG_LEVEL || 'info',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
stream: fs.createWriteStream(logsFilePath),
|
stream: fs.createWriteStream(logsFilePath),
|
||||||
|
level: process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'info',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,9 +2,22 @@ const byline = require('byline');
|
|||||||
const { safeJsonParse, getLogger } = require('dbgate-tools');
|
const { safeJsonParse, getLogger } = require('dbgate-tools');
|
||||||
const logger = getLogger();
|
const logger = getLogger();
|
||||||
|
|
||||||
|
const levelNames = {
|
||||||
|
10: 'trace',
|
||||||
|
20: 'debug',
|
||||||
|
30: 'info',
|
||||||
|
40: 'warn',
|
||||||
|
50: 'error',
|
||||||
|
60: 'fatal',
|
||||||
|
};
|
||||||
|
|
||||||
const logDispatcher = method => data => {
|
const logDispatcher = method => data => {
|
||||||
const json = safeJsonParse(data.toString());
|
const json = safeJsonParse(data.toString());
|
||||||
logger[method](json || data.toString());
|
if (json && json.level && levelNames[json.level]) {
|
||||||
|
logger[levelNames[json.level]](json || data.toString());
|
||||||
|
} else {
|
||||||
|
logger[method](json || data.toString());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function pipeForkLogs(subprocess) {
|
function pipeForkLogs(subprocess) {
|
||||||
|
|||||||
Reference in New Issue
Block a user