mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 10:13:01 +00:00
Merge branch 'dev' of https://github.com/go-admin-team/go-admin into go-admin-team-dev
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/transfer"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"go-admin/common/global"
|
||||
"go-admin/common/log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func Monitor() {
|
||||
var r *gin.Engine
|
||||
h := global.Cfg.GetEngine()
|
||||
if h == nil {
|
||||
h = gin.New()
|
||||
global.Cfg.SetEngine(h)
|
||||
}
|
||||
switch h.(type) {
|
||||
case *gin.Engine:
|
||||
r = h.(*gin.Engine)
|
||||
default:
|
||||
log.Fatal("not support other engine")
|
||||
}
|
||||
//开发环境启动监控指标
|
||||
r.GET("/metrics", transfer.Handler(promhttp.Handler()))
|
||||
//健康检查
|
||||
r.GET("/health", func(c *gin.Context) {
|
||||
c.Status(http.StatusOK)
|
||||
})
|
||||
}
|
||||
+4
-12
@@ -10,8 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-admin-team/go-admin-core/transfer"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
@@ -76,18 +74,12 @@ func run() error {
|
||||
}
|
||||
engine := global.Cfg.GetEngine()
|
||||
if engine == nil {
|
||||
if mode == "dev" {
|
||||
r := gin.New()
|
||||
//开发环境启动监控指标
|
||||
r.GET("/metrics", transfer.Handler(promhttp.Handler()))
|
||||
//健康检查
|
||||
r.GET("/health", func(c *gin.Context) {
|
||||
c.Status(http.StatusOK)
|
||||
})
|
||||
engine = r
|
||||
} else {
|
||||
engine = gin.New()
|
||||
}
|
||||
|
||||
if mode == "dev" {
|
||||
//监控
|
||||
AppRouters = append(AppRouters, router.Monitor)
|
||||
}
|
||||
|
||||
for _, f := range AppRouters {
|
||||
|
||||
+11
-2
@@ -3,6 +3,7 @@ package logger
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
"sort"
|
||||
@@ -114,7 +115,11 @@ func (l *defaultLogger) Log(level Level, v ...interface{}) {
|
||||
}
|
||||
|
||||
t := rec.Timestamp.Format("2006-01-02 15:04:05")
|
||||
fmt.Printf("%s %s %v\n", t, metadata, rec.Message)
|
||||
_, err := l.opts.Out.Write([]byte(fmt.Sprintf("%s %s %v\n", t, metadata, rec.Message)))
|
||||
if err != nil {
|
||||
log.Printf("log [Log] write error: %s \n", err.Error())
|
||||
}
|
||||
//fmt.Printf("%s %s %v\n", t, metadata, rec.Message)
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) {
|
||||
@@ -153,7 +158,11 @@ func (l *defaultLogger) Logf(level Level, format string, v ...interface{}) {
|
||||
}
|
||||
|
||||
t := rec.Timestamp.Format("2006-01-02 15:04:05")
|
||||
fmt.Printf("%s %s %v\n", t, metadata, rec.Message)
|
||||
//fmt.Printf("%s %s %v\n", t, metadata, rec.Message)
|
||||
_, err := l.opts.Out.Write([]byte(fmt.Sprintf("%s %s %v\n", t, metadata, rec.Message)))
|
||||
if err != nil {
|
||||
log.Printf("log [Logf] write error: %s \n", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func (l *defaultLogger) Options() Options {
|
||||
|
||||
Reference in New Issue
Block a user