mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-14 13:44:37 +08:00
23 lines
577 B
Go
23 lines
577 B
Go
package controller
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/gravitl/netmaker/logger"
|
|
)
|
|
|
|
func loggerHandlers(r *mux.Router) {
|
|
r.HandleFunc("/api/logs", securityCheck(true, http.HandlerFunc(getLogs))).Methods("GET")
|
|
}
|
|
|
|
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)))
|
|
}
|