Skip to content

Commit

Permalink
调整代码
Browse files Browse the repository at this point in the history
  • Loading branch information
陈壁浩 committed Jul 21, 2024
1 parent fd65623 commit 1e433a8
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 69 deletions.
12 changes: 6 additions & 6 deletions config/dev/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions config/dev/log.yaml
Original file line number Diff line number Diff line change
@@ -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 # 切割日志
Expand All @@ -17,6 +17,6 @@
#max_age: "10d" # 文件保存时间
#date_format: "%Y-%m-%d-%H-%M" # 文件后缀格式

driver: aliyun_sls
level: trace
formatter: json
#driver: aliyun_sls
#level: trace
#formatter: json
7 changes: 1 addition & 6 deletions docs/src/guide/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ description:

### 框架模块优化

- [ ] 框架
- [ ] 是否抽取配置等魔术编码,例如 `"app.pid"`
- [ ] 文件创建相关(app 获取路径时,有些可以判断并创建)
- [ ] 获取各类 Folder 时就校验并判断,而不是分散在 app 或者 cron 服务里判断

- [ ] 日志
- [ ] 同时支持多个日志输出
- [ ] 同时支持多个日志输出,并且接管gin的日志输出
- [ ] 统一优化日志打印格式
- [ ] 可选固定 json 字段顺序打印配置(强迫症可选)

- [ ] model 代码生成功能优化
- [ ] 生成更符合业务调用场景
- [ ] 其他数据源如sqlite的字段优化
- [ ] 联动

- [ ] 调试模式
- [ ] 文件监控比服务启动还提前,编译完成前修改文件可能会导致空指针
Expand Down
2 changes: 1 addition & 1 deletion framework/provider/app/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *AppService) AppID() string {

// Version 实现版本
func (s *AppService) Version() string {
return GobVersion
return framework.Version
}

// IsToolMode 是否纯工具运行模式
Expand Down
4 changes: 0 additions & 4 deletions framework/provider/app/version.go

This file was deleted.

29 changes: 0 additions & 29 deletions framework/provider/log/services/custom.go

This file was deleted.

8 changes: 3 additions & 5 deletions framework/provider/log/services/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 // 输出
}

Expand All @@ -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
}
}

Expand Down
14 changes: 6 additions & 8 deletions framework/provider/log/services/rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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"
Expand Down Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions framework/provider/log/services/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
4 changes: 4 additions & 0 deletions framework/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package framework

// Version gob的版本
const Version = "0.1.16"

0 comments on commit 1e433a8

Please sign in to comment.