PLT-12 adding log viewer
Этот коммит содержится в:
51
api/admin.go
Обычный файл
51
api/admin.go
Обычный файл
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
l4g "code.google.com/p/log4go"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
func InitAdmin(r *mux.Router) {
|
||||
l4g.Debug("Initializing admin api routes")
|
||||
|
||||
sr := r.PathPrefix("/admin").Subrouter()
|
||||
sr.Handle("/logs", ApiUserRequired(getLogs)).Methods("GET")
|
||||
}
|
||||
|
||||
func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if !c.HasSystemAdminPermissions("getLogs") {
|
||||
return
|
||||
}
|
||||
|
||||
var lines []string
|
||||
|
||||
if utils.Cfg.LogSettings.FileEnable {
|
||||
|
||||
file, err := os.Open(utils.Cfg.LogSettings.FileLocation)
|
||||
if err != nil {
|
||||
c.Err = model.NewAppError("getLogs", "Error reading log file", err.Error())
|
||||
}
|
||||
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
} else {
|
||||
lines = append(lines, "")
|
||||
}
|
||||
|
||||
w.Write([]byte(model.ArrayToJson(lines)))
|
||||
}
|
||||
Ссылка в новой задаче
Block a user