Skip to content

Commit

Permalink
v0.1.3 版本发布
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed Apr 5, 2020
2 parents 7387004 + 02e1fd5 commit 4e11548
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
# ide
.idea/
*.iml
.vscode/*
8 changes: 6 additions & 2 deletions FUTURE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
## ✒ 未来版本的新特性 (Features in future version)

### v0.1.4
### v0.1.5
* 完善 DurationRollingFile 结构,加入文件个数限制
* 完善 SizeRollingFile 结构,加入文件个数限制

### v0.1.3
### v0.1.4
* 更改内置日志处理器的换行符(\n)为系统的换行符
* 继续完善配置文件,主要针对内置的日志处理器做适配
* DefaultHandler 和 wrapper 进行配置文件的适配
* JsonHandler 和 wrapper 进行配置文件的适配

### v0.1.3
* 增加配置文件中是否开启文件信息记录的选项

### v0.1.2
* 加入配置文件的支持,以近似 Json 格式的配置文件来增加日志记录的灵活性
* 修复 Logger 中 DebugFunc,InfoFunc,WarnFunc,ErrorFunc 等几个方法的文件信息错误问题
Expand Down
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## ✒ 历史版本的特性介绍 (Features in old version)

### v0.1.3
> 此版本发布于 2020-04-05
* 增加配置文件中是否开启文件信息记录的选项

### v0.1.2
> 此版本发布于 2020-03-30
* 加入配置文件的支持,以近似 Json 格式的配置文件来增加日志记录的灵活性
Expand Down
5 changes: 3 additions & 2 deletions README.en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 📝 logit

[![License](./license.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
[![License](_icon/license.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
[![Go Doc](_icon/godoc.svg)](https://pkg.go.dev/github.com/FishGoddess/logit?tab=doc)

**logit** is an easy-to-use, also level-based and config file first logger for [GoLang](https://golang.org) applications.

Expand Down Expand Up @@ -41,7 +42,7 @@ module your_project_name
go 1.14

require (
github.com/FishGoddess/logit v0.1.2
github.com/FishGoddess/logit v0.1.3
)
```

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 📝 logit

[![License](./license.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
[![License](_icon/license.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
[![Go Doc](_icon/godoc.svg)](https://pkg.go.dev/github.com/FishGoddess/logit?tab=doc)


**logit** 是一个简单易用并且是基于级别控制和配置文件的日志库,可以应用于所有的 [GoLang](https://golang.org) 应用程序中。

Expand Down Expand Up @@ -41,7 +43,7 @@ module your_project_name
go 1.14

require (
github.com/FishGoddess/logit v0.1.2
github.com/FishGoddess/logit v0.1.3
)
```

Expand Down
6 changes: 5 additions & 1 deletion _examples/config/logit-config-template.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# logit 配置文件的模板
# logit 配置文件的模板 v0.1.3

# 日志级别,可取值有 debug,info,warn,error,off
"level": "info",

# 是否需要记录文件信息,可取值有 true,false
# 注意记录文件信息会有运行时操作,比较消耗性能,确保您是必须要记录才开启这个选项
"caller": false,

# 日志处理器,您可以添加多个日志处理器
# 只有当你使用 RegisterHandler 将你自定义的日志处理器注册进 logit 才可以在这里使用
"handlers":{
Expand Down
7 changes: 6 additions & 1 deletion _examples/config/logit-config-template.en.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# logit config template
# logit config template v0.1.3

# Logger level, all valid value is debug,info,warn,error,off
"level": "info",

# Caller will determine weather you need caller info or not. All valid value is true and false
# Notice that adding caller will use runtime method which costs lots of time.
# So set it to true only when you really need it.
"caller": false,

# Logger handler, you can add more than one handlers to your logger
# Only you has registered your handler to logit by logit.RegisterHandler then it can be used here
"handlers":{
Expand Down
16 changes: 16 additions & 0 deletions _icon/godoc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
15 changes: 13 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type Config struct {
// If the level of log is smaller than this Level, this log will be ignored.
Level Level

// NeedFileInfo will determine weather you need caller info or not.
// Notice that adding caller will use runtime method which costs lots of time,
// so set it to true only when you really need it.
NeedFileInfo bool

// Handlers is how to handle a log in logger.
// We provide some handlers and you can use them directly.
// See logit.Handler.
Expand All @@ -45,6 +50,11 @@ type fileConfig struct {
// Level is the level in string form.
Level string `json:"level"`

// Caller will determine weather you need caller info or not.
// Notice that adding caller will use runtime method which costs lots of time,
// so set it to true only when you really need it.
Caller bool `json:"caller"`

// Handlers is the mapping to config file.
Handlers map[string]map[string]string `json:"handlers"`
}
Expand Down Expand Up @@ -79,8 +89,9 @@ func parseConfig(fileConfig fileConfig) (Config, error) {
}

return Config{
Level: level,
Handlers: handlers,
Level: level,
NeedFileInfo: fileConfig.Caller,
Handlers: handlers,
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,4 @@ Package logit provides an easy way to use foundation for your logging operations
package logit // import "github.com/FishGoddess/logit"

// Version is the version string representation of logit.
const Version = "v0.1.2"
const Version = "v0.1.3"
9 changes: 8 additions & 1 deletion logger_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ func nextFilename(directory string) func(now time.Time) string {
// NewLoggerFrom returns a logger with given config.
// See logit.Config.
func NewLoggerFrom(config Config) *Logger {
return NewLogger(config.Level, config.Handlers...)

// 判断是否需要开启文件信息的记录
logger := NewLogger(config.Level, config.Handlers...)
if config.NeedFileInfo {
logger.EnableFileInfo()
}

return logger
}

// NewLoggerFromConfigFile returns a logger with config file.
Expand Down

0 comments on commit 4e11548

Please sign in to comment.