mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 16:13:58 +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,
|
||||
async fillAppLogs({ dateFrom = 0, dateTo = new Date().getTime() }) {
|
||||
async fillAppLogs({ dateFrom = 0, dateTo = new Date().getTime(), prepareForExport = false }) {
|
||||
const jslid = crypto.randomUUID();
|
||||
const outputFile = path.join(jsldir(), `${jslid}.jsonl`);
|
||||
await copyAppLogsIntoFile(dateFrom, dateTo, outputFile);
|
||||
await copyAppLogsIntoFile(dateFrom, dateTo, outputFile, prepareForExport);
|
||||
return {
|
||||
jslid,
|
||||
};
|
||||
|
||||
@@ -2,9 +2,9 @@ const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const { logsdir } = require('./directories');
|
||||
const { format, addDays, startOfDay } = require('date-fns');
|
||||
const JsonLinesDatastore = require('./JsonLinesDatastore');
|
||||
const LineReader = require('./LineReader');
|
||||
const socket = require('./socket');
|
||||
const _ = require('lodash');
|
||||
|
||||
async function getLogFiles(timeFrom, timeTo) {
|
||||
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);
|
||||
|
||||
for (const file of await getLogFiles(timeFrom, timeTo)) {
|
||||
@@ -40,7 +53,7 @@ async function copyAppLogsIntoFile(timeFrom, timeTo, fileName) {
|
||||
try {
|
||||
const logEntry = JSON.parse(line);
|
||||
if (logEntry.time >= timeFrom && logEntry.time <= timeTo) {
|
||||
writeStream.write(JSON.stringify(logEntry) + '\n');
|
||||
writeStream.write(JSON.stringify(prepareForExport ? prepareEntryForExport(logEntry) : logEntry) + '\n');
|
||||
}
|
||||
} catch (e) {
|
||||
continue;
|
||||
|
||||
@@ -157,20 +157,25 @@
|
||||
});
|
||||
|
||||
const quickExportHandler = fmt => async () => {
|
||||
let usedJslId = jslid;
|
||||
if (mode === 'recent') {
|
||||
const resp = await apiCall('files/fill-app-logs', {
|
||||
dateFrom: startOfDay(new Date()).getTime(),
|
||||
dateTo: endOfDay(new Date()).getTime(),
|
||||
});
|
||||
usedJslId = resp.jslid;
|
||||
}
|
||||
const resp =
|
||||
mode == 'recent'
|
||||
? await apiCall('files/fill-app-logs', {
|
||||
dateFrom: startOfDay(new Date()).getTime(),
|
||||
dateTo: endOfDay(new Date()).getTime(),
|
||||
prepareForExport: true,
|
||||
})
|
||||
: await apiCall('files/fill-app-logs', {
|
||||
dateFrom: startOfDay(dateFilter[0]).getTime(),
|
||||
dateTo: endOfDay(dateFilter[1]).getTime(),
|
||||
prepareForExport: true,
|
||||
});
|
||||
|
||||
exportQuickExportFile(
|
||||
'Log',
|
||||
{
|
||||
functionName: 'jslDataReader',
|
||||
props: {
|
||||
jslid: usedJslId,
|
||||
jslid: resp.jslid,
|
||||
},
|
||||
},
|
||||
fmt
|
||||
|
||||
Reference in New Issue
Block a user