mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-10 11:12:25 +08:00
initial commit
This commit is contained in:
22
controllers/logger.go
Normal file
22
controllers/logger.go
Normal file
@@ -0,0 +1,22 @@
|
||||
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)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(logger.Retrieve(currentFilePath)))
|
||||
}
|
Reference in New Issue
Block a user