summaryrefslogtreecommitdiffstats
path: root/api/admin.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-09-10 18:32:22 -0700
committer=Corey Hulen <corey@hulen.com>2015-09-10 18:32:22 -0700
commite06e292be71ca699d90bafbd635118aa47c2d7a5 (patch)
tree3f8f7ce86a1618f625e71084041746745139ba0c /api/admin.go
parent41439eb801c6c8c0a55bcada3eeba3b4a561c663 (diff)
downloadchat-e06e292be71ca699d90bafbd635118aa47c2d7a5.tar.gz
chat-e06e292be71ca699d90bafbd635118aa47c2d7a5.tar.bz2
chat-e06e292be71ca699d90bafbd635118aa47c2d7a5.zip
PLT-12 adding log viewer
Diffstat (limited to 'api/admin.go')
-rw-r--r--api/admin.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/api/admin.go b/api/admin.go
new file mode 100644
index 000000000..d4af1d247
--- /dev/null
+++ b/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)))
+}