git clone https://gitee.com/leijmdas/gobase.git
func (suite *TestHttpCliWecliQuerySuite) Test014_clone() { var cfg = ichubconfig.FindBeanIchubConfig() cfg.Read() var ccc = cfg.Clone().(*ichubconfig.IchubConfig) ccc.Web.Server.Name = "12" golog.Info(ccc) golog.Error(ccc) golog.Stat(ccc) }
package goutils import ( "context" "git.ichub.com/general/webcli120/goconfig/base/basedto" "git.ichub.com/general/webcli120/goconfig/base/baseutils" "git.ichub.com/general/webcli120/goconfig/base/fileutils" "github.com/gogf/gf/util/gconv" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/glog" "strings" "github.com/sirupsen/logrus" ) /* * @Description: * @FilePath: \goconfig\common\base\baseutils\golog\go_log.go */ var logdir = fileutils.FindRootDir() + "/logs" func init() { fileutils.MakedirAll(logdir) } const ( RotateSize = "100M" // 1024 * 1024 * 20 logfile_server = "ichub.log" logfile_rule = "ichub_rule.log" logfile_stat = "ichub_stat.log" logfile_cli = "ichub_cli.log" logfile_err = "ichub_err.log" ) // https://blog.csdn.net/weixin_51261234/article/details/124504638 type GoLog struct { basedto.BaseEntitySingle Name string *glog.Logger } func NewGoLog() *GoLog { var log = &GoLog{Logger: glog.New()} return log.init() } func (golog *GoLog) init() *GoLog { golog.Logger.SetConfigWithMap(g.Map{ "path": logdir, "level": "all", "file": logfile_server, "stdout": true, "StStatus": 0, "RotateSize": RotateSize, "format": "json", "RotateBackupLimit": 10, "RotateBackupExpire": "7d", "RotateBackupCompress": 9, }) golog.Logger.SetWriterColorEnable(true) return golog } func StdTextProc(v ...any) string { var vv = gconv.SliceStr(v) var s = strings.Join(vv, "\\n") var Buffer = new(strings.Builder) for _, line := range strings.Split(s, "\\n") { line = strings.ReplaceAll(line, `\"`, `"`) Buffer.WriteString(strings.ReplaceAll(line, "\\\\", `\`)) Buffer.WriteString("\r\n") } return Buffer.String() } func IfNil(v ...any) { for i := 0; i < len(v); i++ { if baseutils.IfPtrNil(v[i]) { v[i] = "nil" } } } func Info(v ...any) { IfNil(v...) FindBeanGoLog().Info(context.Background(), v...) logrus.Info(v...) } func Debug(v ...interface{}) { IfNil(v...) FindBeanGoLog().Debug(context.Background(), v...) } func Warn(v ...interface{}) { IfNil(v...) FindBeanGoLog().Warning(context.Background(), v...) }
package goutils import ( "context" "fmt" "git.ichub.com/general/webcli120/goconfig/base/basedto" "github.com/gogf/gf/os/glog" ) type GoLogerr struct { basedto.BaseEntitySingle *GoLog } func NewGoLogServerErr() *GoLogerr { var g = &GoLogerr{ GoLog: NewGoLog(), } g.Logger.SetFile(logfile_err) g.Logger.SetLevel(glog.LEVEL_ERRO) return g } func Errorf(f string, v ...interface{}) { IfNil(v...) FindBeanGoLogerr().Errorf(context.Background(), f, v) } func Error(v ...interface{}) { IfNil(v...) fmt.Println(v...) FindBeanGoLogerr().Error(context.Background(), v...) }
package goutils import ( "context" "git.ichub.com/general/webcli120/goconfig/base/basedto" "git.ichub.com/general/webcli120/goconfig/base/baseutils" "git.ichub.com/general/webcli120/goconfig/base/fileutils" "github.com/gogf/gf/util/gconv" "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/glog" "strings" "github.com/sirupsen/logrus" ) /* * @Description: * @FilePath: \goconfig\common\base\baseutils\golog\go_log.go */ var logdir = fileutils.FindRootDir() + "/logs" func init() { fileutils.MakedirAll(logdir) } const ( RotateSize = "100M" // 1024 * 1024 * 20 logfile_server = "ichub.log" logfile_rule = "ichub_rule.log" logfile_stat = "ichub_stat.log" logfile_cli = "ichub_cli.log" logfile_err = "ichub_err.log" ) // https://blog.csdn.net/weixin_51261234/article/details/124504638 type GoLog struct { basedto.BaseEntitySingle Name string *glog.Logger } func NewGoLog() *GoLog { var log = &GoLog{Logger: glog.New()} return log.init() } func (golog *GoLog) init() *GoLog { golog.Logger.SetConfigWithMap(g.Map{ "path": logdir, "level": "all", "file": logfile_server, "stdout": true, "StStatus": 0, "RotateSize": RotateSize, "format": "json", "RotateBackupLimit": 10, "RotateBackupExpire": "7d", "RotateBackupCompress": 9, }) golog.Logger.SetWriterColorEnable(true) return golog } func StdTextProc(v ...any) string { var vv = gconv.SliceStr(v) var s = strings.Join(vv, "\\n") var Buffer = new(strings.Builder) for _, line := range strings.Split(s, "\\n") { line = strings.ReplaceAll(line, `\"`, `"`) Buffer.WriteString(strings.ReplaceAll(line, "\\\\", `\`)) Buffer.WriteString("\r\n") } return Buffer.String() } func IfNil(v ...any) { for i := 0; i < len(v); i++ { if baseutils.IfPtrNil(v[i]) { v[i] = "nil" } } } func Info(v ...any) { IfNil(v...) FindBeanGoLog().Info(context.Background(), v...) logrus.Info(v...) } func Debug(v ...interface{}) { IfNil(v...) FindBeanGoLog().Debug(context.Background(), v...) } func Warn(v ...interface{}) { IfNil(v...) FindBeanGoLog().Warning(context.Background(), v...) }