From 0bc3e46082d9018188262f9cb8fdbc206d0656a0 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Thu, 16 Mar 2017 14:59:44 -0400 Subject: Implement GET /logs endpoint for APIv4 (#5778) --- app/admin.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'app/admin.go') 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, "") -- cgit v1.2.3-1-g7c22