feat: 容器日志行数增加所有选项 (#2191)

Refs #2143
pull/2195/head
ssongliu 2023-09-05 22:04:11 +08:00 committed by GitHub
parent e509fb0571
commit 31cd6691c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 22 deletions

View File

@ -567,7 +567,7 @@ func (u *ContainerService) ContainerLogs(wsConn *websocket.Conn, container, sinc
}
command := fmt.Sprintf("docker logs %s", container)
if tail != "0" {
command += " -n " + tail
command += " --tail " + tail
}
if since != "all" {
command += " --since " + since

View File

@ -1,15 +1,18 @@
<template>
<div>
<div style="display: flex; flex-wrap: wrap">
<el-select @change="searchLogs" v-model="logSearch.mode" style="width: 150px">
<el-select @change="searchLogs" v-model="logSearch.mode" class="selectWidth">
<template #prefix>{{ $t('container.fetch') }}</template>
<el-option v-for="item in timeOptions" :key="item.label" :value="item.value" :label="item.label" />
</el-select>
<el-input @change="searchLogs" class="margin-button" style="width: 100px" v-model.number="logSearch.tail">
<template #prefix>
<div style="margin-left: 2px">{{ $t('container.lines') }}</div>
</template>
</el-input>
<el-select @change="searchLogs" class="margin-button selectWidth" v-model.number="logSearch.tail">
<template #prefix>{{ $t('container.lines') }}</template>
<el-option :value="0" :label="$t('commons.table.all')" />
<el-option :value="100" :label="100" />
<el-option :value="200" :label="200" />
<el-option :value="500" :label="500" />
<el-option :value="1000" :label="1000" />
</el-select>
<div class="margin-button">
<el-checkbox border @change="searchLogs" v-model="logSearch.isWatch">
{{ $t('commons.button.watch') }}
@ -89,7 +92,7 @@ const timeOptions = ref([
]);
const searchLogs = async () => {
if (!Number(logSearch.tail) || Number(logSearch.tail) < 0) {
if (Number(logSearch.tail) < 0) {
MsgError(i18n.global.t('container.linesHelper'));
return;
}
@ -112,7 +115,17 @@ const searchLogs = async () => {
};
const onDownload = async () => {
downloadWithContent(logInfo.value, logSearch.container + '-' + dateFormatForName(new Date()) + '.log');
let msg =
logSearch.tail === 0
? i18n.global.t('container.downLogHelper1', [logSearch.container])
: i18n.global.t('container.downLogHelper2', [logSearch.container, logSearch.tail]);
ElMessageBox.confirm(msg, i18n.global.t('file.download'), {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
type: 'info',
}).then(async () => {
downloadWithContent(logInfo.value, logSearch.container + '-' + dateFormatForName(new Date()) + '.log');
});
};
interface DialogProps {
@ -154,4 +167,7 @@ defineExpose({
.margin-button {
margin-left: 20px;
}
.selectWidth {
width: 150px;
}
</style>

View File

@ -510,6 +510,8 @@ const message = {
lastHour: 'Last Hour',
last10Min: 'Last 10 Minutes',
cleanLog: 'Clean log',
downLogHelper1: 'Are you sure you want to download all logs for container {0}?',
downLogHelper2: 'Are you sure you want to download the recent {1} logs for container {0}?',
cleanLogHelper:
'Clearing logs requires restarting the container, and this operation cannot be rolled back. Do you want to continue?',
newName: 'New name',

View File

@ -497,6 +497,8 @@ const message = {
lastHour: ' 1 ',
last10Min: ' 10 ',
cleanLog: '',
downLogHelper1: ' {0} ',
downLogHelper2: ' {0} {1} ',
cleanLogHelper: '',
newName: '',
source: '使',

View File

@ -497,6 +497,8 @@ const message = {
lastHour: ' 1 ',
last10Min: ' 10 ',
cleanLog: '',
downLogHelper1: ' {0} ',
downLogHelper2: ' {0} {1} ',
cleanLogHelper: '',
newName: '',
source: '使',

View File

@ -14,20 +14,18 @@
</DrawerHeader>
</template>
<div>
<el-select @change="searchLogs" style="width: 30%; float: left" v-model="logSearch.mode">
<el-select @change="searchLogs" class="fetchClass" v-model="logSearch.mode">
<template #prefix>{{ $t('container.fetch') }}</template>
<el-option v-for="item in timeOptions" :key="item.label" :value="item.value" :label="item.label" />
</el-select>
<el-input
@change="searchLogs"
class="margin-button"
style="width: 20%; float: left"
v-model.number="logSearch.tail"
>
<template #prefix>
<div style="margin-left: 2px">{{ $t('container.lines') }}</div>
</template>
</el-input>
<el-select @change="searchLogs" class="tailClass" v-model.number="logSearch.tail">
<template #prefix>{{ $t('container.lines') }}</template>
<el-option :value="0" :label="$t('commons.table.all')" />
<el-option :value="100" :label="100" />
<el-option :value="200" :label="200" />
<el-option :value="500" :label="500" />
<el-option :value="1000" :label="1000" />
</el-select>
<div class="margin-button" style="float: left">
<el-checkbox border @change="searchLogs" v-model="logSearch.isWatch">
{{ $t('commons.button.watch') }}
@ -134,7 +132,7 @@ watch(logVisiable, (val) => {
if (screenfull.isEnabled && !val && !mobile.value) screenfull.exit();
});
const searchLogs = async () => {
if (!Number(logSearch.tail) || Number(logSearch.tail) < 0) {
if (Number(logSearch.tail) < 0) {
MsgError(i18n.global.t('container.linesHelper'));
return;
}
@ -157,7 +155,17 @@ const searchLogs = async () => {
};
const onDownload = async () => {
downloadWithContent(logInfo.value, logSearch.container + '-' + dateFormatForName(new Date()) + '.log');
let msg =
logSearch.tail === 0
? i18n.global.t('container.downLogHelper1', [logSearch.container])
: i18n.global.t('container.downLogHelper2', [logSearch.container, logSearch.tail]);
ElMessageBox.confirm(msg, i18n.global.t('file.download'), {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
type: 'info',
}).then(async () => {
downloadWithContent(logInfo.value, logSearch.container + '-' + dateFormatForName(new Date()) + '.log');
});
};
const onClean = async () => {
@ -209,4 +217,13 @@ defineExpose({
.fullScreen {
border: none;
}
.tailClass {
width: 20%;
float: left;
margin-left: 20px;
}
.fetchClass {
width: 30%;
float: left;
}
</style>