mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-17 19:07:08 +08:00
fix: Split the system log files (#8085)
This commit is contained in:
parent
b13302775e
commit
07f2a34373
13 changed files with 71 additions and 37 deletions
|
@ -446,10 +446,17 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi
|
|||
logFilePath = ssl.GetLogPath()
|
||||
case constant.TypeSystem:
|
||||
fileName := ""
|
||||
if len(req.Name) == 0 || req.Name == time.Now().Format("2006-01-02") {
|
||||
if len(req.Name) == 0 {
|
||||
fileName = "1Panel.log"
|
||||
} else {
|
||||
fileName = "1Panel-" + req.Name + ".log"
|
||||
if strings.HasSuffix(req.Name, time.Now().Format("2006-01-02")) {
|
||||
fileName = "1Panel.log"
|
||||
if strings.HasPrefix(req.Name, "Core-") {
|
||||
fileName = "1Panel-Core.log"
|
||||
}
|
||||
} else {
|
||||
fileName = "1Panel-" + req.Name + ".log"
|
||||
}
|
||||
}
|
||||
logFilePath = path.Join(global.Dir.DataDir, "log", fileName)
|
||||
if _, err := os.Stat(logFilePath); err != nil {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -25,35 +24,45 @@ func NewILogService() ILogService {
|
|||
}
|
||||
|
||||
func (u *LogService) ListSystemLogFile() ([]string, error) {
|
||||
var files []string
|
||||
if err := filepath.Walk(global.Dir.LogDir, func(pathItem string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() && strings.HasPrefix(info.Name(), "1Panel") {
|
||||
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
|
||||
}); err != nil {
|
||||
var listFile []string
|
||||
files, err := os.ReadDir(global.Dir.LogDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(files) < 2 {
|
||||
return files, nil
|
||||
listMap := make(map[string]struct{})
|
||||
for _, item := range files {
|
||||
if !item.IsDir() && strings.HasPrefix(item.Name(), "1Panel") {
|
||||
if item.Name() == "1Panel.log" || item.Name() == "1Panel-Core.log" {
|
||||
itemName := time.Now().Format("2006-01-02")
|
||||
if _, ok := listMap[itemName]; ok {
|
||||
continue
|
||||
}
|
||||
listMap[itemName] = struct{}{}
|
||||
listFile = append(listFile, itemName)
|
||||
continue
|
||||
}
|
||||
itemFileName := strings.TrimPrefix(item.Name(), "1Panel-Core-")
|
||||
itemFileName = strings.TrimPrefix(itemFileName, "1Panel-")
|
||||
itemFileName = strings.TrimSuffix(itemFileName, ".gz")
|
||||
itemFileName = strings.TrimSuffix(itemFileName, ".log")
|
||||
if len(itemFileName) == 0 {
|
||||
continue
|
||||
}
|
||||
if _, ok := listMap[itemFileName]; ok {
|
||||
continue
|
||||
}
|
||||
listMap[itemFileName] = struct{}{}
|
||||
listFile = append(listFile, itemFileName)
|
||||
}
|
||||
}
|
||||
sort.Slice(files, func(i, j int) bool {
|
||||
return files[i] > files[j]
|
||||
if len(listFile) < 2 {
|
||||
return listFile, nil
|
||||
}
|
||||
sort.Slice(listFile, func(i, j int) bool {
|
||||
return listFile[i] > listFile[j]
|
||||
})
|
||||
|
||||
return files, nil
|
||||
return listFile, nil
|
||||
}
|
||||
|
||||
func (u *LogService) LoadSystemLog(name string) (string, error) {
|
||||
|
|
|
@ -16,6 +16,6 @@ remote_url:
|
|||
log:
|
||||
level: debug
|
||||
time_zone: Asia/Shanghai
|
||||
log_name: 1Panel
|
||||
log_name: 1Panel-Core
|
||||
log_suffix: .log
|
||||
max_backup: 10
|
|
@ -108,15 +108,10 @@ const onLoadUpgradeInfo = async () => {
|
|||
upgradeInfo.value = res.data;
|
||||
if (upgradeInfo.value.newVersion) {
|
||||
upgradeVersion.value = upgradeInfo.value.newVersion;
|
||||
return;
|
||||
}
|
||||
if (upgradeInfo.value.latestVersion) {
|
||||
} else if (upgradeInfo.value.latestVersion) {
|
||||
upgradeVersion.value = upgradeInfo.value.latestVersion;
|
||||
return;
|
||||
}
|
||||
if (upgradeInfo.value.testVersion) {
|
||||
} else if (upgradeInfo.value.testVersion) {
|
||||
upgradeVersion.value = upgradeInfo.value.testVersion;
|
||||
return;
|
||||
}
|
||||
upgradeRef.value.acceptParams({ upgradeInfo: upgradeInfo.value, upgradeVersion: upgradeVersion.value });
|
||||
} else {
|
||||
|
|
|
@ -1253,6 +1253,8 @@ const message = {
|
|||
},
|
||||
},
|
||||
logs: {
|
||||
core: 'Panel Service',
|
||||
agent: 'Node Monitoring',
|
||||
panelLog: 'Panel Logs',
|
||||
operation: 'Operation Logs',
|
||||
login: 'Login Logs',
|
||||
|
|
|
@ -1190,6 +1190,8 @@ const message = {
|
|||
},
|
||||
},
|
||||
logs: {
|
||||
core: 'パネルサービス',
|
||||
agent: 'ノード監視',
|
||||
panelLog: 'パネルログ',
|
||||
operation: '操作ログ',
|
||||
login: 'ログインログ',
|
||||
|
|
|
@ -1178,6 +1178,8 @@ const message = {
|
|||
},
|
||||
},
|
||||
logs: {
|
||||
core: '패널 서비스',
|
||||
agent: '노드 모니터링',
|
||||
panelLog: '패널 로그',
|
||||
operation: '작업 로그',
|
||||
login: '로그인 로그',
|
||||
|
|
|
@ -1233,6 +1233,8 @@ const message = {
|
|||
},
|
||||
},
|
||||
logs: {
|
||||
core: 'Perkhidmatan Panel',
|
||||
agent: 'Pemantauan Nod',
|
||||
panelLog: 'Log Panel',
|
||||
operation: 'Log Operasi',
|
||||
login: 'Log Masuk',
|
||||
|
|
|
@ -1216,6 +1216,8 @@ const message = {
|
|||
alertTitle: 'Tarefa de scan de vírus 「{0}」 detectou alerta de arquivo infectado',
|
||||
},
|
||||
logs: {
|
||||
core: 'Serviço de Painel',
|
||||
agent: 'Monitoramento de Nós',
|
||||
panelLog: 'Logs do painel',
|
||||
operation: 'Logs de operação',
|
||||
login: 'Logs de login',
|
||||
|
|
|
@ -1224,6 +1224,8 @@ const message = {
|
|||
},
|
||||
},
|
||||
logs: {
|
||||
core: 'Сервис панели',
|
||||
agent: 'Мониторинг узлов',
|
||||
panelLog: 'Логи панели',
|
||||
operation: 'Логи операций',
|
||||
login: 'Логи входа',
|
||||
|
|
|
@ -1183,6 +1183,8 @@ const message = {
|
|||
},
|
||||
},
|
||||
logs: {
|
||||
core: '面板服務',
|
||||
agent: '節點監控',
|
||||
panelLog: '面板日誌',
|
||||
operation: '操作日誌',
|
||||
login: '訪問日誌',
|
||||
|
|
|
@ -1181,6 +1181,8 @@ const message = {
|
|||
},
|
||||
},
|
||||
logs: {
|
||||
core: '面板服务',
|
||||
agent: '节点监控',
|
||||
panelLog: '面板日志',
|
||||
operation: '操作日志',
|
||||
login: '访问日志',
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<LogRouter current="SystemLog" />
|
||||
</template>
|
||||
<template #leftToolBar>
|
||||
<el-select class="p-w-200 mr-2.5" v-model="logConfig.name" @change="search()">
|
||||
<el-select class="p-w-200 mr-2.5" v-model="itemName" @change="search()">
|
||||
<template #prefix>{{ $t('commons.table.date') }}</template>
|
||||
<el-option v-for="(item, index) in fileList" :key="index" :label="item" :value="item" />
|
||||
</el-select>
|
||||
|
@ -14,6 +14,10 @@
|
|||
{{ $t('commons.button.watch') }}
|
||||
</el-checkbox>
|
||||
</el-button>
|
||||
<el-radio-group class="ml-2" @change="search()" v-model="itemType">
|
||||
<el-radio-button :label="$t('logs.agent')" value="Agent" />
|
||||
<el-radio-button :label="$t('logs.core')" value="Core" />
|
||||
</el-radio-group>
|
||||
</template>
|
||||
<template #main>
|
||||
<LogFile
|
||||
|
@ -48,6 +52,8 @@ const logConfig = reactive({
|
|||
colorMode: 'system',
|
||||
});
|
||||
const showLog = ref(false);
|
||||
const itemName = ref();
|
||||
const itemType = ref('Agent');
|
||||
|
||||
const changeTail = () => {
|
||||
logRef.value.changeTail(true);
|
||||
|
@ -57,12 +63,13 @@ const loadFiles = async () => {
|
|||
const res = await getSystemFiles();
|
||||
fileList.value = res.data || [];
|
||||
if (fileList.value) {
|
||||
logConfig.name = fileList.value[0];
|
||||
itemName.value = fileList.value[0];
|
||||
search();
|
||||
}
|
||||
};
|
||||
|
||||
const search = () => {
|
||||
logConfig.name = itemType.value === 'Agent' ? itemName.value : 'Core-' + itemName.value;
|
||||
showLog.value = false;
|
||||
nextTick(() => {
|
||||
showLog.value = true;
|
||||
|
|
Loading…
Add table
Reference in a new issue