mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 17:55:59 +00:00
messages view improvements
This commit is contained in:
@@ -12,6 +12,7 @@ const {
|
||||
jsonScriptToJavascript,
|
||||
getLogger,
|
||||
safeJsonParse,
|
||||
pinoLogRecordToMessageRecord,
|
||||
} = require('dbgate-tools');
|
||||
const { handleProcessCommunication } = require('../utility/processComm');
|
||||
const processArgs = require('../utility/processArgs');
|
||||
@@ -68,18 +69,20 @@ module.exports = {
|
||||
|
||||
dispatchMessage(runid, message) {
|
||||
if (message) {
|
||||
const json = safeJsonParse(message.message);
|
||||
if (_.isPlainObject(message)) logger.log(message);
|
||||
else logger.info(message);
|
||||
|
||||
if (json) logger.log(json);
|
||||
else logger.info(message.message);
|
||||
const toEmit = _.isPlainObject(message)
|
||||
? {
|
||||
time: new Date(),
|
||||
...message,
|
||||
}
|
||||
: {
|
||||
message,
|
||||
time: new Date(),
|
||||
};
|
||||
|
||||
const toEmit = {
|
||||
time: new Date(),
|
||||
...message,
|
||||
message: json ? json.msg : message.message,
|
||||
};
|
||||
|
||||
if (json && json.level >= 50) {
|
||||
if (toEmit.level >= 50) {
|
||||
toEmit.severity = 'error';
|
||||
}
|
||||
|
||||
@@ -131,7 +134,16 @@ module.exports = {
|
||||
}
|
||||
);
|
||||
const pipeDispatcher = severity => data => {
|
||||
return this.dispatchMessage(runid, { severity, message: data.toString().trim() });
|
||||
const json = safeJsonParse(data, null);
|
||||
|
||||
if (json) {
|
||||
return this.dispatchMessage(runid, pinoLogRecordToMessageRecord(json));
|
||||
} else {
|
||||
return this.dispatchMessage(runid, {
|
||||
message: json == null ? data.toString().trim() : null,
|
||||
severity,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
byline(subprocess.stdout).on('data', pipeDispatcher('info'));
|
||||
@@ -165,7 +177,7 @@ module.exports = {
|
||||
|
||||
start_meta: true,
|
||||
async start({ script }) {
|
||||
const runid = crypto.randomUUID()
|
||||
const runid = crypto.randomUUID();
|
||||
|
||||
if (script.type == 'json') {
|
||||
const js = jsonScriptToJavascript(script);
|
||||
|
||||
@@ -43,9 +43,17 @@ const platformInfo = {
|
||||
platform,
|
||||
runningInWebpack: !!process.env.WEBPACK_DEV_SERVER_URL,
|
||||
allowShellConnection:
|
||||
(!processArgs.listenApiChild && !isNpmDist) || !!process.env.SHELL_CONNECTION || !!isElectron() || !!isDbModel,
|
||||
(!processArgs.listenApiChild && !isNpmDist) ||
|
||||
!!process.env.SHELL_CONNECTION ||
|
||||
!!isElectron() ||
|
||||
!!isDbModel ||
|
||||
isDevMode,
|
||||
allowShellScripting:
|
||||
(!processArgs.listenApiChild && !isNpmDist) || !!process.env.SHELL_SCRIPTING || !!isElectron() || !!isDbModel,
|
||||
(!processArgs.listenApiChild && !isNpmDist) ||
|
||||
!!process.env.SHELL_SCRIPTING ||
|
||||
!!isElectron() ||
|
||||
!!isDbModel ||
|
||||
isDevMode,
|
||||
allowConnectionFromEnvVariables: !!isDbModel,
|
||||
defaultKeyfile: path.join(os.homedir(), '.ssh/id_rsa'),
|
||||
isAwsUbuntuLayout,
|
||||
|
||||
@@ -70,7 +70,7 @@ export class DatabaseAnalyser {
|
||||
}
|
||||
|
||||
async fullAnalysis() {
|
||||
logger.info(`Performing full analysis, DB=${dbNameLogCategory(this.dbhan.database)}, engine=${this.driver.engine}`);
|
||||
logger.debug(`Performing full analysis, DB=${dbNameLogCategory(this.dbhan.database)}, engine=${this.driver.engine}`);
|
||||
const res = this.addEngineField(await this._runAnalysis());
|
||||
// console.log('FULL ANALYSIS', res);
|
||||
return res;
|
||||
|
||||
@@ -76,7 +76,7 @@ export const driverBase = {
|
||||
for (const sqlItem of splitQuery(sql, this.getQuerySplitterOptions('script'))) {
|
||||
try {
|
||||
if (options?.logScriptItems) {
|
||||
logger.info({ sql: getLimitedQuery(sqlItem as string) }, `Execute script item`);
|
||||
logger.info({ sql: getLimitedQuery(sqlItem as string) }, 'Execute script item');
|
||||
}
|
||||
await this.query(pool, sqlItem, { discardResult: true, ...options?.queryOptions });
|
||||
} catch (err) {
|
||||
|
||||
@@ -521,3 +521,23 @@ export function getLimitedQuery(sql: string): string {
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
export function pinoLogRecordToMessageRecord(logRecord, defaultSeverity = 'info') {
|
||||
const { level, time, msg, ...rest } = logRecord;
|
||||
|
||||
const levelToSeverity = {
|
||||
10: 'debug',
|
||||
20: 'debug',
|
||||
30: 'info',
|
||||
40: 'info',
|
||||
50: 'error',
|
||||
60: 'error',
|
||||
};
|
||||
|
||||
return {
|
||||
...rest,
|
||||
time,
|
||||
message: msg,
|
||||
severity: levelToSeverity[level] ?? defaultSeverity,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
$: time0 = items[0] && new Date(items[0].time).getTime();
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
// $: console.log('MESSAGE ROWS', items);
|
||||
</script>
|
||||
|
||||
<div class="main">
|
||||
@@ -43,6 +45,7 @@
|
||||
{#each items as row, index}
|
||||
<tr
|
||||
class:isError={row.severity == 'error'}
|
||||
class:isDebug={row.severity == 'debug'}
|
||||
class:isActive={row.line}
|
||||
on:click={() => dispatch('messageclick', row)}
|
||||
>
|
||||
@@ -99,4 +102,7 @@
|
||||
tr.isError {
|
||||
color: var(--theme-icon-red);
|
||||
}
|
||||
tr.isDebug {
|
||||
color: var(--theme-font-3);
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user