Implement GET /logs endpoint for APIv4 (#5778)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
24848f9d6a
Коммит
0bc3e46082
21
app/admin.go
21
app/admin.go
@@ -18,14 +18,14 @@ import (
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
func GetLogs() ([]string, *model.AppError) {
|
||||
lines, err := GetLogsSkipSend()
|
||||
func GetLogs(page, perPage int) ([]string, *model.AppError) {
|
||||
lines, err := GetLogsSkipSend(page, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
clines, err := einterfaces.GetClusterInterface().GetLogs()
|
||||
clines, err := einterfaces.GetClusterInterface().GetLogs(page, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func GetLogs() ([]string, *model.AppError) {
|
||||
return lines, nil
|
||||
}
|
||||
|
||||
func GetLogsSkipSend() ([]string, *model.AppError) {
|
||||
func GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) {
|
||||
var lines []string
|
||||
|
||||
if utils.Cfg.LogSettings.EnableFile {
|
||||
@@ -47,9 +47,20 @@ func GetLogsSkipSend() ([]string, *model.AppError) {
|
||||
|
||||
defer file.Close()
|
||||
|
||||
offsetCount := 0
|
||||
limitCount := 0
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
if limitCount >= perPage {
|
||||
break
|
||||
}
|
||||
|
||||
if offsetCount >= page*perPage {
|
||||
lines = append(lines, scanner.Text())
|
||||
limitCount++
|
||||
} else {
|
||||
offsetCount++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lines = append(lines, "")
|
||||
|
||||
Ссылка в новой задаче
Block a user