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 c56c594 commit fae2fb7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
30 changes: 29 additions & 1 deletion config/dev/log.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,32 @@ level: trace

#driver: aliyun_sls
#level: trace
#formatter: json
#formatter: json

#################### 改造成: https://blog.csdn.net/xmcy001122/article/details/119916227

# 启用的日志通道
enable: console,single

console:
level: trace
formatter: text

single:
level: trace
folder: ./storage/log/
file: gob_single.log

rotate:
level: trace # 日志级别
folder: ./storage/log/
file: gob_rotate.log # 保存的日志文件
rotate_count: 10 # 最多日志文件个数
rotate_size: 120000 # 每个日志大小
rotate_time: "1m" # 切割时间
max_age: "10d" # 文件保存时间
date_format: "%Y-%m-%d-%H-%M" # 文件后缀格式

aliyun_sls:
level: trace
formatter: json
3 changes: 1 addition & 2 deletions framework/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func (container *GobContainer) Bind(provider ServiceProvider) error {
}
// 实例化方法
params := provider.Params(container)
method := provider.Register(container)
instance, err := method(params...)
instance, err := provider.Register(container)(params...)
if err != nil {
fmt.Println("bind service provider ", key, " error: ", err)
return errors.New(err.Error())
Expand Down
11 changes: 6 additions & 5 deletions framework/provider/log/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ var _ framework.ServiceProvider = (*LogProvider)(nil)

// Register 注册 GobAppService 方法
func (provider *LogProvider) Register(container framework.Container) framework.NewInstance {





if provider.Driver == "" {
configContainer, err := container.Make(contract.ConfigKey)
if err != nil {
// 默认使用console
return services.NewConsoleLogService
}
configContainer := container.MustMake(contract.ConfigKey)
config := configContainer.(contract.Config)
provider.Driver = strings.ToLower(config.GetString("log.driver"))
}
Expand Down

0 comments on commit fae2fb7

Please sign in to comment.