优化日志
This commit is contained in:
parent
43bb73a0f6
commit
924aa5cbd6
@ -211,7 +211,7 @@ func (c *client) GetSlaveClient(ctx *gin.Context, dbFlag string) (*gorm.DB, erro
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 20:23 2022/6/5
|
||||
func (c *client) getLogInstance(logConf *LogConfig) (*zap.Logger, error) {
|
||||
func (c *client) getLogInstance(logConf *logger.InputLogConfig) (*zap.Logger, error) {
|
||||
if nil == logConf {
|
||||
return nil, nil
|
||||
}
|
||||
@ -257,7 +257,7 @@ func (c *client) getGormClient() (*gorm.DB, error) {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 18:41 2022/6/11
|
||||
func (c *client) GetDatabaseClient(conf *Mysql, logConf *LogConfig) (*gorm.DB, error) {
|
||||
func (c *client) GetDatabaseClient(conf *Mysql, logConf *logger.InputLogConfig) (*gorm.DB, error) {
|
||||
var (
|
||||
instance *gorm.DB
|
||||
err error
|
||||
|
27
define.go
27
define.go
@ -9,7 +9,6 @@ package mysql
|
||||
|
||||
import (
|
||||
"git.zhangdeman.cn/zhangdeman/logger"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
// DBConfig 数据库连接的配置
|
||||
@ -27,30 +26,6 @@ type DBConfig struct {
|
||||
Connection Connection `json:"connection" yaml:"connection"` // 连接数量配置
|
||||
}
|
||||
|
||||
// LogConfig 日志配置
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 10:51 下午 2021/3/1
|
||||
type LogConfig struct {
|
||||
Name string `json:"name" yaml:"name"` // 日志文件名
|
||||
Path string `json:"path" yaml:"path"` // 日志文件路径
|
||||
Format string `json:"format" yaml:"format"` // 文件格式
|
||||
TimeIntervalType logger.TimeIntervalType `json:"time_interval_type" yaml:"time_interval_type"` // 日志切割规则
|
||||
DivisionChar string `json:"division_char" yaml:"division_char"` // 文件名分隔符
|
||||
LogLevel zapcore.Level `json:"log_level" yaml:"log_level"` // 日志等级
|
||||
Console bool `json:"console" yaml:"console"` // 是否进行控制台日志输出
|
||||
UseJson bool `json:"use_json" yaml:"use_json"` // 日志是否使用JSON格式
|
||||
FileLine bool `json:"file_line" yaml:"file_line"` // 日志是否打印行号
|
||||
MessageKey string `json:"message_key" yaml:"message_key"` // message 字段
|
||||
LevelKey string `json:"level_key" yaml:"level_key"` // level 字段
|
||||
TimeKey string `json:"time_key" yaml:"time_key"` // 时间字段
|
||||
CallerKey string `json:"caller_key" yaml:"caller_key"` // 记录日志的文件的代码行数
|
||||
UseShortFile bool `json:"use_short_file" yaml:"use_short_file"` // 是否使用短文件格式
|
||||
CallerSkip int `json:"caller_skip" yaml:"caller_skip"` // 日志记录的文件跳过多少层
|
||||
MaxAge int `json:"max_age" yaml:"max_age"` // 日志最长保存时间, 单位 : 秒
|
||||
}
|
||||
|
||||
// cfgFile 配置文件定义
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
@ -78,7 +53,7 @@ const (
|
||||
//
|
||||
// Date : 15:19 2022/6/9
|
||||
type Database struct {
|
||||
Logger *LogConfig `json:"logger" yaml:"logger"` // 日志配置
|
||||
Logger *logger.InputLogConfig `json:"logger" yaml:"logger"` // 日志配置
|
||||
Master *Mysql `json:"master" yaml:"master"` // 主库配置
|
||||
Slave *Mysql `json:"slave" yaml:"slave"` // 从库配置
|
||||
}
|
||||
|
6
go.mod
6
go.mod
@ -3,7 +3,7 @@ module git.zhangdeman.cn/zhangdeman/mysql
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220514052229-cf395d3dc4c3
|
||||
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220612104513-3f63f6c673f5
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f
|
||||
github.com/gin-gonic/gin v1.7.7
|
||||
github.com/pkg/errors v0.9.1
|
||||
@ -31,8 +31,8 @@ require (
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
|
||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||
github.com/ugorji/go/codec v1.1.7 // indirect
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
|
6
go.sum
6
go.sum
@ -1,5 +1,7 @@
|
||||
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220514052229-cf395d3dc4c3 h1:T41tE9F2Gy8eKVSKtTPhf7RaRT12qHEXTfx4IJuoIS4=
|
||||
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220514052229-cf395d3dc4c3/go.mod h1:0A5BV9pE31nuFE60TLbP7BIhhV/fcWoi+fHrcV2clJw=
|
||||
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220612104513-3f63f6c673f5 h1:avCnxHO3ubhYwz+DNFE+0OjHUJq+P2R53pKiq8dFLjM=
|
||||
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20220612104513-3f63f6c673f5/go.mod h1:0A5BV9pE31nuFE60TLbP7BIhhV/fcWoi+fHrcV2clJw=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f h1:yAxxukVUdSM5wn264el+QiAEB0OBN/5H7Xw9Z6rLzUY=
|
||||
git.zhangdeman.cn/zhangdeman/util v0.0.0-20220609072516-022a755fdf2f/go.mod h1:YI/XeTmrr9+8dxa4ThPkmNcEE8WHG5pZkKujpSWwIxM=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
@ -72,10 +74,14 @@ github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2/go.mod h1:hzfGeI
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
|
||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
|
||||
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
|
||||
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
Loading…
Reference in New Issue
Block a user