summaryrefslogtreecommitdiffstats
path: root/app/admin.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-03-16 14:59:44 -0400
committerCorey Hulen <corey@hulen.com>2017-03-16 11:59:44 -0700
commit0bc3e46082d9018188262f9cb8fdbc206d0656a0 (patch)
tree4ea3c374fff76fe12ad5f325987866baa69cea09 /app/admin.go
parent24848f9d6a92eb1e09189c358636fd1ba32fa6d6 (diff)
downloadchat-0bc3e46082d9018188262f9cb8fdbc206d0656a0.tar.gz
chat-0bc3e46082d9018188262f9cb8fdbc206d0656a0.tar.bz2
chat-0bc3e46082d9018188262f9cb8fdbc206d0656a0.zip
Implement GET /logs endpoint for APIv4 (#5778)
Diffstat (limited to 'app/admin.go')
-rw-r--r--app/admin.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/app/admin.go b/app/admin.go
index c551da50c..509d81840 100644
--- a/app/admin.go
+++ b/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, "")