- 日志增加版本信息
continuous-integration/drone/push Build is passing Details

master
李光春 2 years ago
parent 8d2ee23a5c
commit 1981e946d1

@ -11,6 +11,7 @@ type api struct {
tableName string // 日志表名
insideIp string // 内网ip
hostname string // 主机名
goVersion float64 // go版本
}
// ApiPostgresqlLog 结构体
@ -30,6 +31,7 @@ type ApiPostgresqlLog struct {
ResponseTime TimeString `gorm:"index" json:"response_time"` //【返回】时间
SystemHostName string `gorm:"type:text" json:"system_host_name"` //【系统】主机名
SystemInsideIp string `gorm:"type:text" json:"system_inside_ip"` //【系统】内网ip
GoVersion float64 `gorm:"type:bigint" json:"go_version"` //【程序】Go版本
}
// AutoMigrate 自动迁移
@ -46,6 +48,7 @@ func (a *api) Record(content ApiPostgresqlLog) int64 {
if content.SystemInsideIp == "" {
content.SystemInsideIp = a.insideIp
}
content.GoVersion = a.goVersion
return a.db.Table(a.tableName).Create(&content).RowsAffected
}

@ -4,6 +4,9 @@ import (
"go.dtapp.net/goip"
"gorm.io/gorm"
"os"
"runtime"
"strconv"
"strings"
)
type App struct {
@ -25,6 +28,8 @@ func (a *App) InitClientApi() {
a.Api.tableName = a.TableName
a.Api.hostname, _ = os.Hostname()
a.Api.insideIp = goip.GetInsideIp()
goVersion, _ := strconv.ParseFloat(strings.TrimPrefix(runtime.Version(), "go"), 64)
a.Api.goVersion = goVersion
a.Api.AutoMigrate()
}
@ -40,5 +45,7 @@ func (a *App) InitClientGin() {
a.Gin.tableName = a.TableName
a.Gin.hostname, _ = os.Hostname()
a.Gin.insideIp = goip.GetInsideIp()
goVersion, _ := strconv.ParseFloat(strings.TrimPrefix(runtime.Version(), "go"), 64)
a.Gin.goVersion = goVersion
a.Gin.AutoMigrate()
}

@ -4,6 +4,9 @@ import (
"go.dtapp.net/goip"
"gorm.io/gorm"
"os"
"runtime"
"strconv"
"strings"
)
type Client struct {
@ -20,7 +23,8 @@ func NewClientGin(db *gorm.DB, tableName string) *Client {
panic("表名不能为空")
}
hostname, _ := os.Hostname()
client := &Client{Gin: gin{db: db, tableName: tableName, hostname: hostname, insideIp: goip.GetInsideIp()}}
goVersion, _ := strconv.ParseFloat(strings.TrimPrefix(runtime.Version(), "go"), 64)
client := &Client{Gin: gin{db: db, tableName: tableName, hostname: hostname, insideIp: goip.GetInsideIp(), goVersion: goVersion}}
client.Gin.AutoMigrate()
return client
}
@ -34,7 +38,8 @@ func NewClientApi(db *gorm.DB, tableName string) *Client {
panic("表名不能为空")
}
hostname, _ := os.Hostname()
client := &Client{Api: api{db: db, tableName: tableName, hostname: hostname, insideIp: goip.GetInsideIp()}}
goVersion, _ := strconv.ParseFloat(strings.TrimPrefix(runtime.Version(), "go"), 64)
client := &Client{Api: api{db: db, tableName: tableName, hostname: hostname, insideIp: goip.GetInsideIp(), goVersion: goVersion}}
client.Api.AutoMigrate()
return client
}

@ -11,6 +11,7 @@ type gin struct {
tableName string // 日志表名
insideIp string // 内网ip
hostname string // 主机名
goVersion float64 // go版本
}
// GinPostgresqlLog 结构体
@ -41,6 +42,7 @@ type GinPostgresqlLog struct {
CostTime int64 `gorm:"type:bigint" json:"cost_time"` //【系统】花费时间
SystemHostName string `gorm:"type:text" json:"system_host_name"` //【系统】主机名
SystemInsideIp string `gorm:"type:text" json:"system_inside_ip"` //【系统】内网ip
GoVersion float64 `gorm:"type:bigint" json:"go_version"` //【程序】Go版本
}
// AutoMigrate 自动迁移
@ -57,6 +59,7 @@ func (g *gin) Record(content GinPostgresqlLog) int64 {
if content.SystemInsideIp == "" {
content.SystemInsideIp = g.insideIp
}
content.GoVersion = g.goVersion
return g.db.Table(g.tableName).Create(&content).RowsAffected
}

@ -176,8 +176,6 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 h1:NUzdAbFtCJSXU20AOXgeqaUwg8Ypg4MPYmL+d+rsB5c=
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 h1:O8uGbHCqlTp2P6QJSLmCojM4mN6UemYv8K+dCnmHmu0=
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=

@ -2,6 +2,7 @@ package golog
import (
"os"
"runtime"
)
type System struct {
@ -14,6 +15,7 @@ type System struct {
EGid int // 有效组ID
Pid int // 进程ID
PPid int // 父进程ID
Version string // 版本
}
func (s *System) Init() *System {
@ -26,5 +28,6 @@ func (s *System) Init() *System {
s.EGid = os.Getegid()
s.Pid = os.Getpid()
s.PPid = os.Getppid()
s.Version = runtime.Version()
return s
}

@ -1,6 +1,9 @@
package golog
import (
"runtime"
"strconv"
"strings"
"testing"
)
@ -8,4 +11,7 @@ func TestSystem(t *testing.T) {
var s System
s.Init()
t.Logf("%+v", s)
t.Logf("%+v", runtime.Version())
goVersion, _ := strconv.ParseFloat(strings.TrimPrefix(runtime.Version(), "go"), 64)
t.Logf("%+v", goVersion)
}

Loading…
Cancel
Save