summaryrefslogtreecommitdiffstats
path: root/app/admin.go
diff options
context:
space:
mode:
authorYusuke Nemoto <kaakaa@users.noreply.github.com>2017-12-14 04:04:55 +0900
committerChris <ccbrown112@gmail.com>2017-12-13 13:04:55 -0600
commitddd99f747663ff6f2a5446ab7fc92490ea90ddef (patch)
treea30dff3ef2ecde4fd516b743e2ac1312c9a3b277 /app/admin.go
parentc39788b64b2d2c1f61968da234cac47c21e1affb (diff)
downloadchat-ddd99f747663ff6f2a5446ab7fc92490ea90ddef.tar.gz
chat-ddd99f747663ff6f2a5446ab7fc92490ea90ddef.tar.bz2
chat-ddd99f747663ff6f2a5446ab7fc92490ea90ddef.zip
PLT-6896 per-paging for logs (#7903)
* PLT-6896 Read logs from last * Getting rid of file.Stats * remove deprecated value * Make non-reassigned value constant
Diffstat (limited to 'app/admin.go')
-rw-r--r--app/admin.go55
1 files changed, 40 insertions, 15 deletions
diff --git a/app/admin.go b/app/admin.go
index ef5a1c5d5..e46d9073c 100644
--- a/app/admin.go
+++ b/app/admin.go
@@ -4,7 +4,7 @@
package app
import (
- "bufio"
+ "io"
"os"
"strings"
"time"
@@ -20,9 +20,6 @@ import (
)
func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) {
-
- perPage = 10000
-
var lines []string
if a.Cluster != nil && *a.Config().ClusterSettings.Enable {
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
@@ -62,20 +59,48 @@ func (a *App) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) {
defer file.Close()
- offsetCount := 0
- limitCount := 0
- scanner := bufio.NewScanner(file)
- for scanner.Scan() {
- if limitCount >= perPage {
- break
+ var newLine = []byte{'\n'}
+ var lineCount int
+ const searchPos = -1
+ lineEndPos, err := file.Seek(0, io.SeekEnd)
+ if err != nil {
+ return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError)
+ }
+ for {
+ pos, err := file.Seek(searchPos, io.SeekCurrent)
+ if err != nil {
+ return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError)
}
- if offsetCount >= page*perPage {
- lines = append(lines, scanner.Text())
- limitCount++
- } else {
- offsetCount++
+ b := make([]byte, 1)
+ _, err = file.ReadAt(b, pos)
+ if err != nil {
+ return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError)
}
+
+ if b[0] == newLine[0] || pos == 0 {
+ lineCount++
+ if lineCount > page*perPage {
+ line := make([]byte, lineEndPos-pos)
+ _, err := file.ReadAt(line, pos)
+ if err != nil {
+ return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, err.Error(), http.StatusInternalServerError)
+ }
+ lines = append(lines, string(line))
+ }
+ if pos == 0 {
+ break
+ }
+ lineEndPos = pos
+ }
+
+ if len(lines) == perPage {
+ break
+ }
+ }
+
+ for i, j := 0, len(lines)-1; i < j; i, j = i+1, j-1 {
+ lines[i], lines[j] = lines[j], lines[i]
}
} else {
lines = append(lines, "")