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

pull/2444/head
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" "path/filepath"
"sort" "sort"
"strings" "strings"
"time"
"github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/app/model"
@ -50,8 +51,15 @@ func (u *LogService) ListSystemLogFile() ([]string, error) {
if err != nil { if err != nil {
return err return err
} }
if !info.IsDir() && (strings.HasSuffix(info.Name(), ".log") || strings.HasSuffix(info.Name(), ".log.gz")) { if !info.IsDir() {
files = append(files, strings.TrimSuffix(info.Name(), ".gz")) 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
} }
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) { 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) filePath := path.Join(global.CONF.System.DataDir, "log", name)
if _, err := os.Stat(filePath); err != nil { if _, err := os.Stat(filePath); err != nil {
fileGzPath := path.Join(global.CONF.System.DataDir, "log", name+".gz") 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") return "", buserr.New("ErrHttpReqNotFound")
} }
if err := handleGunzip(fileGzPath); err != nil { 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) content, err := os.ReadFile(filePath)

View File

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

View File

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

View File

@ -823,6 +823,8 @@ const message = {
websites: '', websites: '',
containers: '', containers: '',
files: '', files: '',
runtimes: '',
process: '',
logs: '', logs: '',
settings: '', settings: '',
cronjobs: '', cronjobs: '',

View File

@ -823,6 +823,8 @@ const message = {
websites: '', websites: '',
containers: '', containers: '',
files: '', files: '',
runtimes: '',
process: '',
logs: '', logs: '',
settings: '', settings: '',
cronjobs: '', cronjobs: '',

View File

@ -17,14 +17,14 @@
</span> </span>
<div v-if="!withTagAll"> <div v-if="!withTagAll">
<ul v-for="(item, index) in imageList" :key="index"> <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] }} {{ item.tags[0] }}
</li> </li>
</ul> </ul>
</div> </div>
<div v-else> <div v-else>
<ul v-for="(item, index) in imageList" :key="index"> <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> </ul>
</div> </div>
</el-form> </el-form>

View File

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

View File

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