mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 23:06:00 +00:00
try to fix electron errors after start
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
const { setLogger, getLogger, setLoggerName } = require('dbgate-tools');
|
||||
const processArgs = require('./utility/processArgs');
|
||||
const pino = require('pino');
|
||||
const pinoms = require('pino-multi-stream');
|
||||
const fs = require('fs');
|
||||
const moment = require('moment');
|
||||
const path = require('path');
|
||||
@@ -14,35 +13,53 @@ if (processArgs.processDisplayName) {
|
||||
setLoggerName(processArgs.processDisplayName);
|
||||
}
|
||||
|
||||
function loadLogsContent(maxLines) {
|
||||
const text = fs.readFileSync(getLogsFilePath(), { encoding: 'utf8' });
|
||||
if (maxLines) {
|
||||
const lines = text
|
||||
.split('\n')
|
||||
.map(x => x.trim())
|
||||
.filter(x => x);
|
||||
return lines.slice(-maxLines).join('\n');
|
||||
}
|
||||
return text;
|
||||
}
|
||||
// function loadLogsContent(maxLines) {
|
||||
// const text = fs.readFileSync(getLogsFilePath(), { encoding: 'utf8' });
|
||||
// if (maxLines) {
|
||||
// const lines = text
|
||||
// .split('\n')
|
||||
// .map(x => x.trim())
|
||||
// .filter(x => x);
|
||||
// return lines.slice(-maxLines).join('\n');
|
||||
// }
|
||||
// return text;
|
||||
// }
|
||||
|
||||
function configureLogger() {
|
||||
const logsFilePath = path.join(logsdir(), `${moment().format('YYYY-MM-DD-HH-mm')}-${process.pid}.ndjson`);
|
||||
setLogsFilePath(logsFilePath);
|
||||
setLoggerName('main');
|
||||
|
||||
let logger = pinoms({
|
||||
// let logger = pinoms({
|
||||
// redact: { paths: ['hostname'], remove: true },
|
||||
// streams: [
|
||||
// {
|
||||
// stream: process.stdout,
|
||||
// level: process.env.CONSOLE_LOG_LEVEL || process.env.LOG_LEVEL || 'info',
|
||||
// },
|
||||
// {
|
||||
// stream: fs.createWriteStream(logsFilePath),
|
||||
// level: process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'info',
|
||||
// },
|
||||
// ],
|
||||
// });
|
||||
|
||||
// @ts-ignore
|
||||
let logger = pino({
|
||||
redact: { paths: ['hostname'], remove: true },
|
||||
streams: [
|
||||
{
|
||||
stream: process.stdout,
|
||||
level: process.env.CONSOLE_LOG_LEVEL || process.env.LOG_LEVEL || 'info',
|
||||
},
|
||||
{
|
||||
stream: fs.createWriteStream(logsFilePath),
|
||||
level: process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'info',
|
||||
},
|
||||
],
|
||||
transport: {
|
||||
targets: [
|
||||
{
|
||||
level: process.env.CONSOLE_LOG_LEVEL || process.env.LOG_LEVEL || 'info',
|
||||
target: 'pino/file',
|
||||
},
|
||||
{
|
||||
level: process.env.FILE_LOG_LEVEL || process.env.LOG_LEVEL || 'info',
|
||||
target: 'pino/file',
|
||||
options: { destination: logsFilePath },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
setLogger(logger);
|
||||
@@ -72,6 +89,6 @@ module.exports = {
|
||||
...shell,
|
||||
getLogger,
|
||||
configureLogger,
|
||||
loadLogsContent,
|
||||
// loadLogsContent,
|
||||
getMainModule: () => require('./main'),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user