Skip to content

Commit

Permalink
feat: 应用支持实时日志
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Oct 20, 2024
1 parent 5ae6135 commit 730aea0
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 234 deletions.
6 changes: 2 additions & 4 deletions internal/apps/mysql/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ func (s *Service) Load(w http.ResponseWriter, r *http.Request) {

// ErrorLog 获取错误日志
func (s *Service) ErrorLog(w http.ResponseWriter, r *http.Request) {
log, _ := shell.Execf("tail -n 100 %s/server/mysql/mysql-error.log", app.Root)
service.Success(w, log)
service.Success(w, fmt.Sprintf("%s/server/mysql/mysql-error.log", app.Root))
}

// ClearErrorLog 清空错误日志
Expand All @@ -160,8 +159,7 @@ func (s *Service) ClearErrorLog(w http.ResponseWriter, r *http.Request) {

// SlowLog 获取慢查询日志
func (s *Service) SlowLog(w http.ResponseWriter, r *http.Request) {
log, _ := shell.Execf("tail -n 100 %s/server/mysql/mysql-slow.log", app.Root)
service.Success(w, log)
service.Success(w, fmt.Sprintf("%s/server/mysql/mysql-slow.log", app.Root))
}

// ClearSlowLog 清空慢查询日志
Expand Down
3 changes: 1 addition & 2 deletions internal/apps/nginx/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func (s *Service) SaveConfig(w http.ResponseWriter, r *http.Request) {
}

func (s *Service) ErrorLog(w http.ResponseWriter, r *http.Request) {
out, _ := shell.Execf("tail -n 100 %s/%s", app.Root, "wwwlogs/nginx-error.log")
service.Success(w, out)
service.Success(w, fmt.Sprintf("%s/%s", app.Root, "wwwlogs/nginx-error.log"))
}

func (s *Service) ClearErrorLog(w http.ResponseWriter, r *http.Request) {
Expand Down
6 changes: 2 additions & 4 deletions internal/apps/php/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,11 @@ func (s *Service) Load(w http.ResponseWriter, r *http.Request) {
}

func (s *Service) ErrorLog(w http.ResponseWriter, r *http.Request) {
log, _ := shell.Execf("tail -n 500 %s/server/php/%d/var/log/php-fpm.log", app.Root, s.version)
service.Success(w, log)
service.Success(w, fmt.Sprintf("%s/server/php/%d/var/log/php-fpm.log", app.Root, s.version))
}

func (s *Service) SlowLog(w http.ResponseWriter, r *http.Request) {
log, _ := shell.Execf("tail -n 500 %s/server/php/%d/var/log/slow.log", app.Root, s.version)
service.Success(w, log)
service.Success(w, fmt.Sprintf("%s/server/php/%d/var/log/slow.log", app.Root, s.version))
}

func (s *Service) ClearErrorLog(w http.ResponseWriter, r *http.Request) {
Expand Down
3 changes: 1 addition & 2 deletions internal/apps/postgresql/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ func (s *Service) Load(w http.ResponseWriter, r *http.Request) {

// Log 获取日志
func (s *Service) Log(w http.ResponseWriter, r *http.Request) {
log, _ := shell.Execf("tail -n 100 %s/server/postgresql/logs/postgresql-%s.log", app.Root, time.Now().Format(time.DateOnly))
service.Success(w, log)
service.Success(w, fmt.Sprintf("%s/server/postgresql/logs/postgresql-%s.log", app.Root, time.Now().Format(time.DateOnly)))
}

// ClearLog 清空日志
Expand Down
1 change: 0 additions & 1 deletion internal/apps/supervisor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ func init() {
Route: func(r chi.Router) {
service := NewService()
r.Get("/service", service.Service)
r.Get("/log", service.Log)
r.Post("/clearLog", service.ClearLog)
r.Get("/config", service.GetConfig)
r.Post("/config", service.UpdateConfig)
Expand Down
9 changes: 1 addition & 8 deletions internal/apps/supervisor/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ func (s *Service) Service(w http.ResponseWriter, r *http.Request) {
service.Success(w, s.name)
}

// Log 日志
func (s *Service) Log(w http.ResponseWriter, r *http.Request) {
log, _ := shell.Execf(`tail -n 200 /var/log/supervisor/supervisord.log`)
service.Success(w, log)
}

// ClearLog 清空日志
func (s *Service) ClearLog(w http.ResponseWriter, r *http.Request) {
if _, err := shell.Execf(`echo "" > /var/log/supervisor/supervisord.log`); err != nil {
Expand Down Expand Up @@ -204,8 +198,7 @@ func (s *Service) ProcessLog(w http.ResponseWriter, r *http.Request) {
return
}

log, _ := shell.Execf(`tail -n 200 '%s'`, logPath)
service.Success(w, log)
service.Success(w, logPath)
}

// ClearProcessLog 清空进程日志
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/common/RealtimeLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const logRef = ref<LogInst | null>(null)
let logWs: WebSocket | null = null
const init = async () => {
const cmd = `tail -n 40 -f ${props.path}`
const cmd = `tail -n 40 -f '${props.path}'`
ws.exec(cmd)
.then((ws: WebSocket) => {
logWs = ws
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/common/RealtimeLogModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const logRef = ref<LogInst | null>(null)
let logWs: WebSocket | null = null
const init = async () => {
const cmd = `tail -n 40 -f ${props.path}`
const cmd = `tail -n 40 -f '${props.path}'`
ws.exec(cmd)
.then((ws: WebSocket) => {
logWs = ws
Expand Down
34 changes: 2 additions & 32 deletions web/src/views/apps/mysql/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,11 @@ const handleSaveConfig = async () => {
const handleClearErrorLog = async () => {
await mysql.clearErrorLog()
getErrorLog().then((res) => {
errorLog.value = res
})
window.$message.success('清空成功')
}
const handleClearSlowLog = async () => {
await mysql.clearSlowLog()
getSlowLog().then((res) => {
slowLog.value = res
})
window.$message.success('清空成功')
}
Expand Down Expand Up @@ -268,34 +262,10 @@ onMounted(() => {
/>
</n-tab-pane>
<n-tab-pane name="error-log" tab="错误日志">
<Editor
v-model:value="errorLog"
language="ini"
theme="vs-dark"
height="60vh"
mt-8
:options="{
automaticLayout: true,
formatOnType: true,
formatOnPaste: true,
readOnly: true
}"
/>
<realtime-log :path="errorLog" />
</n-tab-pane>
<n-tab-pane name="slow-log" tab="慢查询日志">
<Editor
v-model:value="slowLog"
language="ini"
theme="vs-dark"
height="60vh"
mt-8
:options="{
automaticLayout: true,
formatOnType: true,
formatOnPaste: true,
readOnly: true
}"
/>
<realtime-log :path="slowLog" />
</n-tab-pane>
</n-tabs>
</common-page>
Expand Down
17 changes: 1 addition & 16 deletions web/src/views/apps/nginx/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ const handleSaveConfig = async () => {
const handleClearErrorLog = async () => {
await nginx.clearErrorLog()
getErrorLog().then((res) => {
errorLog.value = res
})
window.$message.success('清空成功')
}
Expand Down Expand Up @@ -222,19 +219,7 @@ onMounted(() => {
/>
</n-tab-pane>
<n-tab-pane name="error-log" tab="错误日志">
<Editor
v-model:value="errorLog"
language="ini"
theme="vs-dark"
height="60vh"
mt-8
:options="{
automaticLayout: true,
formatOnType: true,
formatOnPaste: true,
readOnly: true
}"
/>
<realtime-log :path="errorLog" />
</n-tab-pane>
</n-tabs>
</common-page>
Expand Down
35 changes: 2 additions & 33 deletions web/src/views/apps/php81/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ const getFPMConfig = async () => {
const handleSaveConfig = async () => {
await php.saveConfig(version, config.value)
window.$message.success('保存成功')
await getErrorLog()
}
const handleSaveFPMConfig = async () => {
Expand All @@ -174,13 +173,11 @@ const handleSaveFPMConfig = async () => {
const handleClearErrorLog = async () => {
await php.clearErrorLog(version)
await getErrorLog()
window.$message.success('清空成功')
}
const handleClearSlowLog = async () => {
await php.clearSlowLog(version)
await getSlowLog()
window.$message.success('清空成功')
}
Expand All @@ -199,28 +196,24 @@ const handleStart = async () => {
await systemctl.start(`php-fpm-${version}`)
window.$message.success('启动成功')
await getStatus()
await getErrorLog()
}
const handleStop = async () => {
await systemctl.stop(`php-fpm-${version}`)
window.$message.success('停止成功')
await getStatus()
await getErrorLog()
}
const handleRestart = async () => {
await systemctl.restart(`php-fpm-${version}`)
window.$message.success('重启成功')
await getStatus()
await getErrorLog()
}
const handleReload = async () => {
await systemctl.reload(`php-fpm-${version}`)
window.$message.success('重载成功')
await getStatus()
await getErrorLog()
}
const handleInstallExtension = async (slug: string) => {
Expand Down Expand Up @@ -394,34 +387,10 @@ onMounted(() => {
/>
</n-tab-pane>
<n-tab-pane name="error-log" tab="错误日志">
<Editor
v-model:value="errorLog"
language="ini"
theme="vs-dark"
height="60vh"
mt-8
:options="{
automaticLayout: true,
formatOnType: true,
formatOnPaste: true,
readOnly: true
}"
/>
<realtime-log :path="errorLog" />
</n-tab-pane>
<n-tab-pane name="slow-log" tab="慢日志">
<Editor
v-model:value="slowLog"
language="ini"
theme="vs-dark"
height="60vh"
mt-8
:options="{
automaticLayout: true,
formatOnType: true,
formatOnPaste: true,
readOnly: true
}"
/>
<realtime-log :path="slowLog" />
</n-tab-pane>
</n-tabs>
</common-page>
Expand Down
35 changes: 2 additions & 33 deletions web/src/views/apps/php82/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ const getFPMConfig = async () => {
const handleSaveConfig = async () => {
await php.saveConfig(version, config.value)
window.$message.success('保存成功')
await getErrorLog()
}
const handleSaveFPMConfig = async () => {
Expand All @@ -174,13 +173,11 @@ const handleSaveFPMConfig = async () => {
const handleClearErrorLog = async () => {
await php.clearErrorLog(version)
await getErrorLog()
window.$message.success('清空成功')
}
const handleClearSlowLog = async () => {
await php.clearSlowLog(version)
await getSlowLog()
window.$message.success('清空成功')
}
Expand All @@ -199,28 +196,24 @@ const handleStart = async () => {
await systemctl.start(`php-fpm-${version}`)
window.$message.success('启动成功')
await getStatus()
await getErrorLog()
}
const handleStop = async () => {
await systemctl.stop(`php-fpm-${version}`)
window.$message.success('停止成功')
await getStatus()
await getErrorLog()
}
const handleRestart = async () => {
await systemctl.restart(`php-fpm-${version}`)
window.$message.success('重启成功')
await getStatus()
await getErrorLog()
}
const handleReload = async () => {
await systemctl.reload(`php-fpm-${version}`)
window.$message.success('重载成功')
await getStatus()
await getErrorLog()
}
const handleInstallExtension = async (slug: string) => {
Expand Down Expand Up @@ -394,34 +387,10 @@ onMounted(() => {
/>
</n-tab-pane>
<n-tab-pane name="error-log" tab="错误日志">
<Editor
v-model:value="errorLog"
language="ini"
theme="vs-dark"
height="60vh"
mt-8
:options="{
automaticLayout: true,
formatOnType: true,
formatOnPaste: true,
readOnly: true
}"
/>
<realtime-log :path="errorLog" />
</n-tab-pane>
<n-tab-pane name="slow-log" tab="慢日志">
<Editor
v-model:value="slowLog"
language="ini"
theme="vs-dark"
height="60vh"
mt-8
:options="{
automaticLayout: true,
formatOnType: true,
formatOnPaste: true,
readOnly: true
}"
/>
<realtime-log :path="slowLog" />
</n-tab-pane>
</n-tabs>
</common-page>
Expand Down
Loading

0 comments on commit 730aea0

Please sign in to comment.