mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 09:44:00 +00:00
SYNC: export logs
This commit is contained in:
committed by
Diflow
parent
994dae2a7d
commit
d8eeeaaef6
@@ -314,10 +314,10 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
fillAppLogs_meta: true,
|
fillAppLogs_meta: true,
|
||||||
async fillAppLogs({ dateFrom = 0, dateTo = new Date().getTime() }) {
|
async fillAppLogs({ dateFrom = 0, dateTo = new Date().getTime(), prepareForExport = false }) {
|
||||||
const jslid = crypto.randomUUID();
|
const jslid = crypto.randomUUID();
|
||||||
const outputFile = path.join(jsldir(), `${jslid}.jsonl`);
|
const outputFile = path.join(jsldir(), `${jslid}.jsonl`);
|
||||||
await copyAppLogsIntoFile(dateFrom, dateTo, outputFile);
|
await copyAppLogsIntoFile(dateFrom, dateTo, outputFile, prepareForExport);
|
||||||
return {
|
return {
|
||||||
jslid,
|
jslid,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ const fs = require('fs-extra');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { logsdir } = require('./directories');
|
const { logsdir } = require('./directories');
|
||||||
const { format, addDays, startOfDay } = require('date-fns');
|
const { format, addDays, startOfDay } = require('date-fns');
|
||||||
const JsonLinesDatastore = require('./JsonLinesDatastore');
|
|
||||||
const LineReader = require('./LineReader');
|
const LineReader = require('./LineReader');
|
||||||
const socket = require('./socket');
|
const socket = require('./socket');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
async function getLogFiles(timeFrom, timeTo) {
|
async function getLogFiles(timeFrom, timeTo) {
|
||||||
const dir = logsdir();
|
const dir = logsdir();
|
||||||
@@ -28,7 +28,20 @@ function adjustRecentLogs() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copyAppLogsIntoFile(timeFrom, timeTo, fileName) {
|
function prepareEntryForExport(entry) {
|
||||||
|
return {
|
||||||
|
date: format(new Date(entry.time), 'yyyy-MM-dd'),
|
||||||
|
time: format(new Date(entry.time), 'HH:mm:ss'),
|
||||||
|
msgcode: entry.msgcode || '',
|
||||||
|
message: entry.msg || '',
|
||||||
|
..._.omit(entry, ['time', 'msg', 'msgcode']),
|
||||||
|
conid: entry.conid || '',
|
||||||
|
database: entry.database || '',
|
||||||
|
engine: entry.engine || '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyAppLogsIntoFile(timeFrom, timeTo, fileName, prepareForExport) {
|
||||||
const writeStream = fs.createWriteStream(fileName);
|
const writeStream = fs.createWriteStream(fileName);
|
||||||
|
|
||||||
for (const file of await getLogFiles(timeFrom, timeTo)) {
|
for (const file of await getLogFiles(timeFrom, timeTo)) {
|
||||||
@@ -40,7 +53,7 @@ async function copyAppLogsIntoFile(timeFrom, timeTo, fileName) {
|
|||||||
try {
|
try {
|
||||||
const logEntry = JSON.parse(line);
|
const logEntry = JSON.parse(line);
|
||||||
if (logEntry.time >= timeFrom && logEntry.time <= timeTo) {
|
if (logEntry.time >= timeFrom && logEntry.time <= timeTo) {
|
||||||
writeStream.write(JSON.stringify(logEntry) + '\n');
|
writeStream.write(JSON.stringify(prepareForExport ? prepareEntryForExport(logEntry) : logEntry) + '\n');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -157,20 +157,25 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
const quickExportHandler = fmt => async () => {
|
const quickExportHandler = fmt => async () => {
|
||||||
let usedJslId = jslid;
|
const resp =
|
||||||
if (mode === 'recent') {
|
mode == 'recent'
|
||||||
const resp = await apiCall('files/fill-app-logs', {
|
? await apiCall('files/fill-app-logs', {
|
||||||
dateFrom: startOfDay(new Date()).getTime(),
|
dateFrom: startOfDay(new Date()).getTime(),
|
||||||
dateTo: endOfDay(new Date()).getTime(),
|
dateTo: endOfDay(new Date()).getTime(),
|
||||||
});
|
prepareForExport: true,
|
||||||
usedJslId = resp.jslid;
|
})
|
||||||
}
|
: await apiCall('files/fill-app-logs', {
|
||||||
|
dateFrom: startOfDay(dateFilter[0]).getTime(),
|
||||||
|
dateTo: endOfDay(dateFilter[1]).getTime(),
|
||||||
|
prepareForExport: true,
|
||||||
|
});
|
||||||
|
|
||||||
exportQuickExportFile(
|
exportQuickExportFile(
|
||||||
'Log',
|
'Log',
|
||||||
{
|
{
|
||||||
functionName: 'jslDataReader',
|
functionName: 'jslDataReader',
|
||||||
props: {
|
props: {
|
||||||
jslid: usedJslId,
|
jslid: resp.jslid,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
fmt
|
fmt
|
||||||
|
|||||||
Reference in New Issue
Block a user