1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

fix: 日志筛选项格式修改 (#2440)

This commit is contained in:
ssongliu 2023-10-07 16:58:46 +08:00 committed by GitHub
parent d685bed167
commit e76d1e018e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import (
"path/filepath"
"sort"
"strings"
"time"
"github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/model"
@ -50,8 +51,15 @@ func (u *LogService) ListSystemLogFile() ([]string, error) {
if err != nil {
return err
}
if !info.IsDir() && (strings.HasSuffix(info.Name(), ".log") || strings.HasSuffix(info.Name(), ".log.gz")) {
files = append(files, strings.TrimSuffix(info.Name(), ".gz"))
if !info.IsDir() {
if info.Name() == "1Panel.log" {
files = append(files, time.Now().Format("2006-01-02"))
return nil
}
itemFileName := strings.TrimPrefix(info.Name(), "1Panel-")
itemFileName = strings.TrimSuffix(itemFileName, ".gz")
itemFileName = strings.TrimSuffix(itemFileName, ".log")
files = append(files, itemFileName)
return nil
}
return nil
@ -113,6 +121,11 @@ func (u *LogService) PageOperationLog(req dto.SearchOpLogWithPage) (int64, inter
}
func (u *LogService) LoadSystemLog(name string) (string, error) {
if name == time.Now().Format("2006-01-02") {
name = "1Panel.log"
} else {
name = "1Panel-" + name + ".log"
}
filePath := path.Join(global.CONF.System.DataDir, "log", name)
if _, err := os.Stat(filePath); err != nil {
fileGzPath := path.Join(global.CONF.System.DataDir, "log", name+".gz")
@ -120,7 +133,7 @@ func (u *LogService) LoadSystemLog(name string) (string, error) {
return "", buserr.New("ErrHttpReqNotFound")
}
if err := handleGunzip(fileGzPath); err != nil {
return "", fmt.Errorf("handle ungzip file %s falied, err: %v", fileGzPath, err)
return "", fmt.Errorf("handle ungzip file %s failed, err: %v", fileGzPath, err)
}
}
content, err := os.ReadFile(filePath)

View File

@ -389,7 +389,7 @@ func sortFileList(fileNames []sshFileItem) []sshFileItem {
return fileNames[i].Name > fileNames[j].Name
})
itemFile = append(itemFile, fileNames[len(fileNames)-1])
itemFile = append(itemFile, fileNames[:len(fileNames)-2]...)
itemFile = append(itemFile, fileNames[:len(fileNames)-1]...)
return itemFile
}
sort.Slice(fileNames, func(i, j int) bool {

View File

@ -857,6 +857,8 @@ const message = {
websites: 'Website',
containers: 'Container',
files: 'File Manage',
runtimes: 'Runtime',
process: 'Process',
logs: 'Panel Logs',
settings: 'Panel Setting',
cronjobs: 'Cronjob',

View File

@ -823,6 +823,8 @@ const message = {
websites: '網站',
containers: '容器',
files: '文件管理',
runtimes: '運行環境',
process: '進程管理',
logs: '日誌審計',
settings: '面板設置',
cronjobs: '計劃任務',

View File

@ -823,6 +823,8 @@ const message = {
websites: '网站',
containers: '容器',
files: '文件管理',
runtimes: '运行环境',
process: '进程管理',
logs: '日志审计',
settings: '面板设置',
cronjobs: '计划任务',

View File

@ -17,14 +17,14 @@
</span>
<div v-if="!withTagAll">
<ul v-for="(item, index) in imageList" :key="index">
<li v-if="item.tags.length === 1 && item.tags[0].indexOf('<none>') !== -1">
<li v-if="item.tags && item.tags.length === 1 && item.tags[0].indexOf('<none>') !== -1">
{{ item.tags[0] }}
</li>
</ul>
</div>
<div v-else>
<ul v-for="(item, index) in imageList" :key="index">
<li v-if="!item.isUsed">{{ item.tags.join(', ') }}</li>
<li v-if="item.tags && !item.isUsed">{{ item.tags.join(', ') }}</li>
</ul>
</div>
</el-form>

View File

@ -36,11 +36,13 @@
<el-option :label="$t('commons.table.all')" value=""></el-option>
<el-option :label="$t('logs.detail.apps')" value="apps"></el-option>
<el-option :label="$t('logs.detail.websites')" value="websites"></el-option>
<el-option :label="$t('logs.detail.runtimes')" value="runtimes"></el-option>
<el-option :label="$t('logs.detail.databases')" value="databases"></el-option>
<el-option :label="$t('logs.detail.containers')" value="containers"></el-option>
<el-option :label="$t('logs.detail.cronjobs')" value="cronjobs"></el-option>
<el-option :label="$t('logs.detail.files')" value="files"></el-option>
<el-option :label="$t('logs.detail.hosts')" value="hosts"></el-option>
<el-option :label="$t('logs.detail.process')" value="process"></el-option>
<el-option :label="$t('logs.detail.logs')" value="logs"></el-option>
<el-option :label="$t('logs.detail.settings')" value="settings"></el-option>
</el-select>

View File

@ -59,7 +59,7 @@ const router = useRouter();
const loading = ref();
const isWatch = ref();
const currentFile = ref('1Panel.log');
const currentFile = ref();
const fileList = ref();
const extensions = [javascript(), oneDark];
@ -87,6 +87,10 @@ const changeWatch = async () => {
const loadFiles = async () => {
const res = await getSystemFiles();
fileList.value = res.data || [];
if (fileList.value) {
currentFile.value = fileList.value[0];
search();
}
};
const search = async () => {
@ -118,7 +122,6 @@ onBeforeUnmount(() => {
onMounted(() => {
loadFiles();
search();
});
</script>