netmaker/controllers/logger.go

24 lines
577 B
Go
Raw Normal View History

2021-12-07 04:31:08 +08:00
package controller
import (
"fmt"
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/gravitl/netmaker/logger"
)
func loggerHandlers(r *mux.Router) {
2021-12-08 00:15:01 +08:00
r.HandleFunc("/api/logs", securityCheck(true, http.HandlerFunc(getLogs))).Methods("GET")
2021-12-07 04:31:08 +08:00
}
func getLogs(w http.ResponseWriter, r *http.Request) {
var currentTime = time.Now().Format(logger.TimeFormatDay)
var currentFilePath = fmt.Sprintf("data/netmaker.log.%s", currentTime)
logger.DumpFile(currentFilePath)
logger.ResetLogs()
w.WriteHeader(http.StatusOK)
w.Write([]byte(logger.Retrieve(currentFilePath)))
}