2022-09-14 03:25:56 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"github.com/gravitl/netmaker/logger"
|
2022-09-15 01:26:31 +08:00
|
|
|
"github.com/gravitl/netmaker/logic"
|
2022-09-14 03:25:56 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func loggerHandlers(r *mux.Router) {
|
2022-12-23 22:49:08 +08:00
|
|
|
r.HandleFunc("/api/logs", logic.SecurityCheck(true, http.HandlerFunc(getLogs))).Methods(http.MethodGet)
|
2022-09-14 03:25:56 +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)
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
w.Write([]byte(logger.Retrieve(currentFilePath)))
|
|
|
|
}
|