diff --git a/config/dev/app.yaml b/config/dev/app.yaml index b983d4f..5492cfe 100644 --- a/config/dev/app.yaml +++ b/config/dev/app.yaml @@ -9,9 +9,9 @@ dev: # 调试模式 port: 8072 # 后端监听端口,默认 8072 monitor_folder: "" # 监听文件夹地址,为空或者不填默认为 AppFolder -sls: # 阿里云SLS服务 - endpoint: cn-guangzhou.log.aliyuncs.com - access_key_id: - access_key_secret: - project: gob-test - logstore: gob_test_logstore +#sls: # 阿里云SLS服务 +# endpoint: cn-guangzhou.log.aliyuncs.com +# access_key_id: +# access_key_secret: +# project: gob-test +# logstore: gob_test_logstore diff --git a/config/dev/log.yaml b/config/dev/log.yaml index b698631..a9cbe8a 100644 --- a/config/dev/log.yaml +++ b/config/dev/log.yaml @@ -1,11 +1,11 @@ -#driver: console -#formatter: text -#level: trace +driver: console +formatter: text +level: trace #driver: single #level: trace -#folder: /tmp/ +#folder: ./storage/log/single #file: gob_single.log #driver: rotate # 切割日志 @@ -17,6 +17,6 @@ #max_age: "10d" # 文件保存时间 #date_format: "%Y-%m-%d-%H-%M" # 文件后缀格式 -driver: aliyun_sls -level: trace -formatter: json \ No newline at end of file +#driver: aliyun_sls +#level: trace +#formatter: json \ No newline at end of file diff --git a/docs/src/guide/TODO.md b/docs/src/guide/TODO.md index 5c8c4f9..757b69c 100644 --- a/docs/src/guide/TODO.md +++ b/docs/src/guide/TODO.md @@ -9,20 +9,15 @@ description: ### 框架模块优化 -- [ ] 框架 - - [ ] 是否抽取配置等魔术编码,例如 `"app.pid"` 等 - - [ ] 文件创建相关(app 获取路径时,有些可以判断并创建) - - [ ] 获取各类 Folder 时就校验并判断,而不是分散在 app 或者 cron 服务里判断 - [ ] 日志 - - [ ] 同时支持多个日志输出 + - [ ] 同时支持多个日志输出,并且接管gin的日志输出 - [ ] 统一优化日志打印格式 - [ ] 可选固定 json 字段顺序打印配置(强迫症可选) - [ ] model 代码生成功能优化 - [ ] 生成更符合业务调用场景 - [ ] 其他数据源如sqlite的字段优化 - - [ ] 联动 - [ ] 调试模式 - [ ] 文件监控比服务启动还提前,编译完成前修改文件可能会导致空指针 diff --git a/framework/provider/app/service.go b/framework/provider/app/service.go index abbcc14..3db8882 100644 --- a/framework/provider/app/service.go +++ b/framework/provider/app/service.go @@ -58,7 +58,7 @@ func (s *AppService) AppID() string { // Version 实现版本 func (s *AppService) Version() string { - return GobVersion + return framework.Version } // IsToolMode 是否纯工具运行模式 diff --git a/framework/provider/app/version.go b/framework/provider/app/version.go deleted file mode 100644 index a7e2f97..0000000 --- a/framework/provider/app/version.go +++ /dev/null @@ -1,4 +0,0 @@ -package app - -// GobVersion gob的版本 -const GobVersion = "0.1.16" diff --git a/framework/provider/log/services/custom.go b/framework/provider/log/services/custom.go deleted file mode 100644 index fe97583..0000000 --- a/framework/provider/log/services/custom.go +++ /dev/null @@ -1,29 +0,0 @@ -package services - -import ( - "github.com/chenbihao/gob/framework" - "github.com/chenbihao/gob/framework/contract" - "io" -) - -type CustomLogService struct { - LogService -} - -func NewCustomLogService(params ...interface{}) (interface{}, error) { - c := params[0].(framework.Container) - level := params[1].(contract.LogLevel) - ctxFielder := params[2].(contract.CtxFielder) - formatter := params[3].(contract.Formatter) - output := params[4].(io.Writer) - - log := &CustomLogService{} - - log.SetLevel(level) - log.SetCtxFielder(ctxFielder) - log.SetFormatter(formatter) - - log.SetOutput(output) - log.c = c - return log, nil -} diff --git a/framework/provider/log/services/log.go b/framework/provider/log/services/log.go index 93a515b..5127d5a 100644 --- a/framework/provider/log/services/log.go +++ b/framework/provider/log/services/log.go @@ -17,7 +17,7 @@ type LogService struct { c framework.Container // 容器 level contract.LogLevel // 日志级别 formatter contract.Formatter // 日志格式化方法 - ctxFielder contract.CtxFielder // ctx获取上下文字段 + ctxFielder contract.CtxFielder // ctx 获取上下文字段 output io.Writer // 输出 } @@ -40,10 +40,8 @@ func (log *LogService) logf(ctx context.Context, level contract.LogLevel, msg st } if log.ctxFielder != nil { t := log.ctxFielder(ctx) - if t != nil { - for k, v := range t { - fs[k] = v - } + for k, v := range t { + fs[k] = v } } diff --git a/framework/provider/log/services/rotate.go b/framework/provider/log/services/rotate.go index 0ab1199..1c1aa55 100644 --- a/framework/provider/log/services/rotate.go +++ b/framework/provider/log/services/rotate.go @@ -7,7 +7,6 @@ import ( "github.com/chenbihao/gob/framework/util" rotatelogs "github.com/lestrrat-go/file-rotatelogs" "github.com/pkg/errors" - "os" "path/filepath" "time" ) @@ -33,15 +32,18 @@ func NewRotateLogService(params ...interface{}) (interface{}, error) { appService := c.MustMake(contract.AppKey).(contract.App) configService := c.MustMake(contract.ConfigKey).(contract.Config) + log := &RotateLogService{} + log.SetLevel(level) + log.SetCtxFielder(ctxFielder) + log.SetFormatter(formatter) + // 从配置文件中获取folder信息,否则使用默认的LogFolder文件夹 folder := appService.LogFolder() if configService.IsExist("log.folder") { folder = configService.GetString("log.folder") } // 如果folder不存在,则创建 - if !util.Exists(folder) { - os.MkdirAll(folder, os.ModePerm) - } + util.CreateFolderIfNotExists(folder) // 从配置文件中获取file信息,否则使用默认的gob.log file := "gob.log" @@ -85,10 +87,6 @@ func NewRotateLogService(params ...interface{}) (interface{}, error) { } // 设置基础信息 - log := &RotateLogService{} - log.SetLevel(level) - log.SetCtxFielder(ctxFielder) - log.SetFormatter(formatter) log.folder = folder log.file = file diff --git a/framework/provider/log/services/single.go b/framework/provider/log/services/single.go index bc06785..211fe33 100644 --- a/framework/provider/log/services/single.go +++ b/framework/provider/log/services/single.go @@ -38,9 +38,8 @@ func NewSingleLogService(params ...interface{}) (interface{}, error) { folder = configService.GetString("log.folder") } log.folder = folder - if !util.Exists(folder) { - os.MkdirAll(folder, os.ModePerm) - } + // 如果folder不存在,则创建 + util.CreateFolderIfNotExists(folder) log.file = "gob.log" if configService.IsExist("log.file") { diff --git a/framework/version.go b/framework/version.go new file mode 100644 index 0000000..2307c25 --- /dev/null +++ b/framework/version.go @@ -0,0 +1,4 @@ +package framework + +// Version gob的版本 +const Version = "0.1.16"