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