Skip to content

Commit

Permalink
发布 v0.2.4 版本
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed May 27, 2020
2 parents ed5891e + a580b65 commit 31ebb99
Show file tree
Hide file tree
Showing 19 changed files with 497 additions and 59 deletions.
8 changes: 8 additions & 0 deletions FUTURE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## ✒ 未来版本的新特性 (Features in future version)

### v0.2.5
* 修复配置文件中出现转义字符导致解析出错的问题

### v0.2.4
* 新增屏蔽某个日志级别的日志处理器
* 修正某些文档的语法问题
* 修复部分单元测试引用外部文件(比如 _examples 中的文件)的问题

### v0.2.3
* 祝大家五一劳动节快乐!
* ~~增加 timeout_handler.go,里面是带超时功能的日志处理器包装器~~
Expand Down
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## ✒ 历史版本的特性介绍 (Features in old version)

### v0.2.4
> 此版本发布于 2020-05-27
* 新增屏蔽某个日志级别的日志处理器
* 修正某些文档的语法问题
* 修复部分单元测试引用外部文件(比如 _examples 中的文件)的问题

### v0.2.3
> 此版本发布于 2020-05-01
* 祝大家五一劳动节快乐!
Expand Down
4 changes: 2 additions & 2 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

_Check [HISTORY.md](./HISTORY.md) and [FUTURE.md](./FUTURE.md) to know about more information._

> v0.1.x is an interim version and will not be updated but fixed from now on. Next version v0.2.x is a big update which will bring new features and user experience, also it will be updated and maintained for a long time!
> v0.1.x and older versions will not be supported anymore, please update to v0.2.x as quickly as possible. You will get some brand-new user experiences and supports for a long time!
### 🚀 Installation

Expand All @@ -44,7 +44,7 @@ module your_project_name
go 1.14

require (
github.com/FishGoddess/logit v0.2.3
github.com/FishGoddess/logit v0.2.4
)
```

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

_历史版本的特性请查看 [HISTORY.md](./HISTORY.md)。未来版本的新特性和计划请查看 [FUTURE.md](./FUTURE.md)_

> v0.1.x 版本只是一个特性过渡版本,目前已经停止更新,只进行维护和修复。下一个大更新版本 v0.2.x 将带来全新的特性和使用体验(其中一点就是做减法),并保持长期更新和维护
> v0.1.x 及以下版本已经停止维护,请尽快升级到 v0.2.x 版本!您将感受到全新的使用体验,并可以享受长期的更新和维护
### 🚀 安装方式

Expand All @@ -45,7 +45,7 @@ module your_project_name
go 1.14

require (
github.com/FishGoddess/logit v0.2.3
github.com/FishGoddess/logit v0.2.4
)
```

Expand Down
33 changes: 32 additions & 1 deletion _examples/config/logit-config-template.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# logit 配置文件的模板 v0.2.1-alpha
# logit 配置文件的模板 v0.2.4
# 注意:以 # 开头的是注释,不参与配置文件的解析,注释必须是单独的一行,不能写在属性的后面
# 语法是基于 Json 并作了一些改动使其更适合做配置文件,所以要注意双引号和逗号这些格式
# 下面所有涉及目录路径的都使用 / 或者 \\ 而不能是 \,否则会造成配置解析出错,这个问题后续会进行修复

# 日志级别,可取值有 debug,info,warn,error,off
# 如果不配置的话,默认是 debug
Expand Down Expand Up @@ -130,5 +131,35 @@
"file": {
"path": "D:/error.log"
}
},

# level shielded 日志处理器
# 这个日志处理器一共有四个:!debug,!info,!warn,!error
# 它们只是一个包装器,做了一个日志级别的过滤,比如 !debug 的日志处理器就只会处理 debug 级别之外的日志
# 每个日志处理器内部可以添加多个日志处理器,比如 console 日志处理器,甚至是再添加一个 level shielded 日志处理器
# 所以日志怎么处理还是要靠具体添加的日志处理器,您可以添加所有注册进 logit 或者说上面出现的日志处理器
"!debug": {
"console": {},
"file": {
"path": "D:/non-debug.log"
}
},
"!info": {
"console": {},
"file": {
"path": "D:/non-info.log"
}
},
"!warn": {
"console": {},
"file": {
"path": "D:/non-warn.log"
}
},
"!error": {
"console": {},
"file": {
"path": "D:/non-error.log"
}
}
}
34 changes: 33 additions & 1 deletion _examples/config/logit-config-template.en.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# logit config template v0.2.1-alpha
# logit config template v0.2.4
# Notice that starting with # is comment, and it must be a new line
# Grammar is based on Json, but adds more features to let it become more configured and easy-to-read
# You should always use / or \\ instead of \. This problem will be fixed in future version

# Logger level, all valid values are debug, info, warn, error, off
# Default is "debug"
Expand Down Expand Up @@ -136,5 +137,36 @@
"file": {
"path": "D:/error.log"
}
},

# level shielded handlers
# There are four kinds of this handlers: !debug, !info, !warn, !error
# They are only a wrapper which only does a log level filtering
# For example, the !debug level shielded handler only handles logs in all levels except debug level
# Every level shielded handler can have many handlers, such as console handler, even one more level shielded handler
# So how to handle logs is dependent to specifically added handlers, and you can add all registered handlers above
"!debug": {
"console": {},
"file": {
"path": "D:/non-debug.log"
}
},
"!info": {
"console": {},
"file": {
"path": "D:/non-info.log"
}
},
"!warn": {
"console": {},
"file": {
"path": "D:/non-warn.log"
}
},
"!error": {
"console": {},
"file": {
"path": "D:/non-error.log"
}
}
}
25 changes: 0 additions & 25 deletions _examples/level_based_handler.conf

This file was deleted.

8 changes: 4 additions & 4 deletions _examples/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func main() {
})
defer durationRollingFile.Close()

// You can use it like using os.File!
durationRollingFile.Write([]byte("Hello!"))
// You can use it like using io.Writer!
durationRollingFile.Write([]byte("durationRollingFile!"))

// =================================================================================

Expand All @@ -43,6 +43,6 @@ func main() {
})
defer sizeRollingFile.Close()

// You can use it like using os.File!
sizeRollingFile.Write([]byte("Hello!"))
// You can use it like using io.Writer!
sizeRollingFile.Write([]byte("sizeRollingFile!"))
}
35 changes: 33 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,46 @@
package logit

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)

// 创建 TestParseConfigFile 测试案例的配置文件
func createParseConfigFileTestConfigFile(t *testing.T) string {

// 创建配置文件
configFile, err := ioutil.TempFile("", "TestParseConfigFile_*.conf")
if err != nil {
t.Fatal(err)
}
defer configFile.Close()

// 写入配置内容
configFile.WriteString(`
"level": "debug",
"caller": false,
"handlers": {
"console": {
"timeFormat": "unix",
"encoder": "json"
},
"file": {
"path": "` + escapeString(filepath.Join(os.TempDir(), "logit.log")) + `"
}
}
`)
return configFile.Name()
}

// 测试解析配置文件的方法
func TestParseConfigFile(t *testing.T) {

// 打开配置文件
file, err := os.Open("./_examples/logger.conf")
file, err := os.Open(createParseConfigFileTestConfigFile(t))
if err != nil {
t.Fatal(err)
}
Expand All @@ -54,7 +85,7 @@ func TestParseHandlersFromConfig(t *testing.T) {
"k1": "v1",
},
"file": {
"path": "Z:/TestParseHandlersFromConfig.log",
"path": escapeString(filepath.Join(os.TempDir(), "TestParseHandlersFromConfig.log")),
"k2": "v2",
},
},
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,5 @@ package logit // import "github.com/FishGoddess/logit"

const (
// Version is the version string representation of logit.
Version = "v0.2.3"
Version = "v0.2.4"
)
8 changes: 5 additions & 3 deletions handler_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package logit

import (
"os"
"path/filepath"
"strconv"
"testing"
"time"
Expand All @@ -36,7 +38,7 @@ func TestNewFileHandler(t *testing.T) {
}
}()

logger := NewLogger(DebugLevel, NewFileHandler("Z:/test.log", TextEncoder(), ""))
logger := NewLogger(DebugLevel, NewFileHandler(filepath.Join(os.TempDir(), "test.log"), TextEncoder(), ""))
for i := 0; i < 100; i++ {
logger.Info("我是第 " + strconv.Itoa(i) + " 条日志!")
}
Expand All @@ -46,7 +48,7 @@ func TestNewFileHandler(t *testing.T) {

// 测试创建随时间间隔滚动的文件日志处理器
func TestNewDurationRollingHandler(t *testing.T) {
logger := NewLogger(DebugLevel, NewDurationRollingHandler(time.Second, "Z:/", TextEncoder(), ""))
logger := NewLogger(DebugLevel, NewDurationRollingHandler(time.Second, os.TempDir(), TextEncoder(), ""))
for i := 0; i < 5; i++ {
logger.Info("1. info!!!!!!!! " + strconv.FormatInt(time.Now().Unix(), 10))
time.Sleep(time.Second)
Expand All @@ -56,7 +58,7 @@ func TestNewDurationRollingHandler(t *testing.T) {

// 测试按照文件大小自动划分日志文件的日志处理器
func TestNewSizeRollingHandler(t *testing.T) {
logger := NewLogger(DebugLevel, NewSizeRollingHandler(64*writer.KB, "Z:/", TextEncoder(), ""))
logger := NewLogger(DebugLevel, NewSizeRollingHandler(64*writer.KB, os.TempDir(), TextEncoder(), ""))
for i := 0; i < 2000; i++ {
logger.Debug("debug...")
logger.Info("info...")
Expand Down
6 changes: 3 additions & 3 deletions level_based_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewLevelBasedHandler(level Level, handlers ...Handler) Handler {
}

// Handle handles a log with handlers in lbh.
// Notice that the handle process will be interrupted if one of them
// Notice that the handling process will be interrupted if one of them
// returned false. However, this method will always return true, so the handlers
// after it will always be used.
func (lbh *levelBasedHandler) Handle(log *Log) bool {
Expand Down Expand Up @@ -101,7 +101,7 @@ func registerDebugLevelHandler() {
})
}

// ================================ info level handler ================================
// ================================ info level handler ================================

// registerInfoLevelHandler registers info level handler which
// only handles logs in info level.
Expand All @@ -127,7 +127,7 @@ func registerInfoLevelHandler() {
})
}

// ================================ warn level handler ================================
// ================================ warn level handler ================================

// registerWarnLevelHandler registers warn level handler which
// only handles logs in warn level.
Expand Down
Loading

0 comments on commit 31ebb99

Please sign in to comment.