Skip to content

Commit

Permalink
祝大家五一劳动节快乐!
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed May 1, 2020
2 parents 2b84170 + 98ebc9d commit ed5891e
Show file tree
Hide file tree
Showing 48 changed files with 2,655 additions and 2,016 deletions.
15 changes: 15 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# convert to lf on checkout.
*.go text eol=lf
*.mod text eol=lf
*.sum text eol=lf
*.md text eol=lf
*.svg text eol=lf
*.conf text eol=lf

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.jpeg binary
35 changes: 29 additions & 6 deletions FUTURE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
## ✒ 未来版本的新特性 (Features in future version)

### v0.2.0
* 继续完善配置文件,主要针对内置的日志处理器做适配
* 合并目前的 DefaultHandler 和 JsonHandler
* DefaultHandler 和 wrapper 进行配置文件的适配
* 加入 FileHandler,专门负责文件相关的日志处理器
* 增加分级日志处理器包装器,不同的级别可以使用不同的日志处理器
### v0.2.3
* 祝大家五一劳动节快乐!
* ~~增加 timeout_handler.go,里面是带超时功能的日志处理器包装器~~
> 取消这个特性是因为,一般在需要获取某个执行时间很长甚至可能一直阻塞的操作的结果时才需要超时,
> 对于日志输出而言,我们并不需要获取日志输出操作的结果,所以这个特性意义不大。
> 还有一个原因就是,实现超时需要使用并发,在超时的任务里终止某个任务,
> 而 Go 语言并没有提供可以停止并销毁一个 goroutine 的方法,所以即使超时了,也没有办法终止这个任务
> 甚至可能造成 goroutine 的阻塞。综合上述,取消这个超时功能的日志处理器包装器。
### v0.2.2-alpha
* 改造全局使用的 logger,可以使用一个默认的配置文件来初始化全局 logger,方便使用
* 增加 levelBasedHandler,里面是不同日志级别的日志处理器包装器,可以传一堆的 handler 进去

### v0.2.1-alpha
* 将 console handler 简化,目前使用 RegisterHandler 构造
* 从 file handler 中抽取出 duration rolling 和 size rolling 两个日志处理器
* 屏蔽了 HandlerOf 和 EncoderOf,只暴露特定的 API
* 新增 TextEncoder 和 JsonEncoder 两个方法,可以获取到具体的日志编码器
* 新增 NewConsoleHandler 和 NewFileHandler,分别对应控制台和文件日志处理器
* 新增 NewDurationRollingHandler 和 NewSizeRollingHandler,分别对应时间间隔滚动和文件大小滚动的日志处理器
* 删除了大量创建 Logger 的方法,这些方法会让人看起来很复杂很繁琐
* 去除原有 Config 加 fileConfig 的配置设计,现在直接使用一个映射配置,然后组装成需要的参数

### v0.2.0-alpha
* 将 wrapper 修改为 writer
* 剔除了 default handler 和 json handler,整合进 standard handler 中
* 提取出一个 encoder,方便内置处理器引用
* 加入 console handler,专门负责输出到控制台的日志处理器
* 加入 file handler,专门负责文件相关的日志处理器,包含时间滚动和大小滚动和不滚动的功能

### v0.1.5
* 完善 Json 处理器没有做字符转义的修复方案,详情查询 [issue/1](https://github.com/FishGoddess/logit/issues/1)
Expand Down
28 changes: 28 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
## ✒ 历史版本的特性介绍 (Features in old version)

### v0.2.3
> 此版本发布于 2020-05-01
* 祝大家五一劳动节快乐!

### v0.2.2-alpha
> 此版本发布于 2020-04-28
* 改造全局使用的 logger,可以使用一个默认的配置文件来初始化全局 logger,方便使用
* 增加 levelBasedHandler,里面是不同日志级别的日志处理器包装器,可以传一堆的 handler 进去

### v0.2.1-alpha
> 此版本发布于 2020-04-27
* 将 console handler 简化,目前使用 RegisterHandler 构造
* 从 file handler 中抽取出 duration rolling 和 size rolling 两个日志处理器
* 屏蔽了 HandlerOf 和 EncoderOf,只暴露特定的 API
* 新增 TextEncoder 和 JsonEncoder 两个方法,可以获取到具体的日志编码器
* 新增 NewConsoleHandler 和 NewFileHandler,分别对应控制台和文件日志处理器
* 新增 NewDurationRollingHandler 和 NewSizeRollingHandler,分别对应时间间隔滚动和文件大小滚动的日志处理器
* 删除了大量创建 Logger 的方法,这些方法会让人看起来很复杂很繁琐
* 去除原有 Config 加 fileConfig 的配置设计,现在直接使用一个映射配置,然后组装成需要的参数

### v0.2.0-alpha
> 此版本发布于 2020-04-24
* 将 wrapper 修改为 writer
* 剔除了 default handler 和 json handler,整合进 standard handler 中
* 提取出一个 encoder,方便内置处理器引用
* 加入 console handler,专门负责输出到控制台的日志处理器
* 加入 file handler,专门负责文件相关的日志处理器,包含时间滚动和大小滚动和不滚动的功能

### v0.1.5
> 此版本发布于 2020-04-19
* 完善 Json 处理器没有做字符转义的修复方案,详情查询 [issue/1](https://github.com/FishGoddess/logit/issues/1)
Expand Down
49 changes: 27 additions & 22 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module your_project_name
go 1.14

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

Expand All @@ -69,26 +69,29 @@ import (

func main() {

// Log as you want.
logit.Debug("I am a debug message!")
logit.Info("I am an info message!")
logit.Warn("I am a warn message!")
logit.Error("I am an error message!")

// Change logger level.
logit.ChangeLevelTo(logit.DebugLevel)

// If you want to output log with file info, try this:
logit.EnableFileInfo()
logit.Info("Show file info!")

// If you have a long log and it is made of many variables, try this:
// The msg is the return value of msgGenerator.
logit.DebugFunc(func() string {
// Use time as the source of random number generator.
r := rand.New(rand.NewSource(time.Now().Unix()))
return "debug rand int: " + strconv.Itoa(r.Intn(100))
})
// Log messages with four levels.
logit.Debug("I am a debug message!")
logit.Info("I am an info message!")
logit.Warn("I am a warn message!")
logit.Error("I am an error message!")

// Notice that logit has blocked some methods for more refreshing method list.
// If you want to use some higher level methods, you should call logit.Me() to
// get the fully functional logger, then call what you want to call.
// For example, if you want to output log with file info, try this:
logit.Me().EnableFileInfo()
logit.Info("Show file info!")

// If you have a long log and it is made of many variables, try this:
// The msg is the return value of msgGenerator.
logit.DebugFunc(func() string {
// Use time as the source of random number generator.
r := rand.New(rand.NewSource(time.Now().Unix()))
return "debug rand int: " + strconv.Itoa(r.Intn(100))
})

// If a config file "logit.conf" in "./", then logit will load it automatically.
// This is more convenience to use config file and logger.
}
```

Expand All @@ -99,11 +102,13 @@ func main() {
* [level_and_disable](./_examples/level_and_disable.go)
* [config_file](./_examples/config_file.go)
* [handler](./_examples/handler.go)
* [wrapper](./_examples/wrapper.go)
* [writer](./_examples/writer.go)
* [log_to_file](./_examples/log_to_file.go)

_Check more examples in [_examples](./_examples)._

_Learn more about config file in [_examples/config](./_examples/config)._

### 🔥 Benchmarks

```bash
Expand Down
46 changes: 27 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module your_project_name
go 1.14

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

Expand All @@ -70,23 +70,29 @@ import (

func main() {

// Log messages with four levels.
logit.Debug("I am a debug message!")
logit.Info("I am an info message!")
logit.Warn("I am a warn message!")
logit.Error("I am an error message!")

// If you want to output log with file info, try this:
logit.EnableFileInfo()
logit.Info("Show file info!")

// If you have a long log and it is made of many variables, try this:
// The msg is the return value of msgGenerator.
logit.DebugFunc(func() string {
// Use time as the source of random number generator.
r := rand.New(rand.NewSource(time.Now().Unix()))
return "debug rand int: " + strconv.Itoa(r.Intn(100))
})
// Log messages with four levels.
logit.Debug("I am a debug message!")
logit.Info("I am an info message!")
logit.Warn("I am a warn message!")
logit.Error("I am an error message!")

// Notice that logit has blocked some methods for more refreshing method list.
// If you want to use some higher level methods, you should call logit.Me() to
// get the fully functional logger, then call what you want to call.
// For example, if you want to output log with file info, try this:
logit.Me().EnableFileInfo()
logit.Info("Show file info!")

// If you have a long log and it is made of many variables, try this:
// The msg is the return value of msgGenerator.
logit.DebugFunc(func() string {
// Use time as the source of random number generator.
r := rand.New(rand.NewSource(time.Now().Unix()))
return "debug rand int: " + strconv.Itoa(r.Intn(100))
})

// If a config file "logit.conf" in "./", then logit will load it automatically.
// This is more convenience to use config file and logger.
}
```

Expand All @@ -97,11 +103,13 @@ func main() {
* [level_and_disable](./_examples/level_and_disable.go)
* [config_file](./_examples/config_file.go)
* [handler](./_examples/handler.go)
* [wrapper](./_examples/wrapper.go)
* [writer](./_examples/writer.go)
* [log_to_file](./_examples/log_to_file.go)

_更多使用案例请查看 [_examples](./_examples) 目录。_

_配置文件模板请查看 [_examples/config](./_examples/config) 目录。_

### 🔥 性能测试

```bash
Expand Down
46 changes: 26 additions & 20 deletions _examples/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,42 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: fish
// Author: FishGoddess
// Email: [email protected]
// Created at 2020/02/29 21:59:13
package main

import (
"math/rand"
"strconv"
"time"
"math/rand"
"strconv"
"time"

"github.com/FishGoddess/logit"
"github.com/FishGoddess/logit"
)

func main() {

// Log messages with four levels.
logit.Debug("I am a debug message!")
logit.Info("I am an info message!")
logit.Warn("I am a warn message!")
logit.Error("I am an error message!")
// Log messages with four levels.
logit.Debug("I am a debug message!")
logit.Info("I am an info message!")
logit.Warn("I am a warn message!")
logit.Error("I am an error message!")

// If you want to output log with file info, try this:
logit.EnableFileInfo()
logit.Info("Show file info!")
// Notice that logit has blocked some methods for more refreshing method list.
// If you want to use some higher level methods, you should call logit.Me() to
// get the fully functional logger, then call what you want to call.
// For example, if you want to output log with file info, try this:
logit.Me().EnableFileInfo()
logit.Info("Show file info!")

// If you have a long log and it is made of many variables, try this:
// The msg is the return value of msgGenerator.
logit.DebugFunc(func() string {
// Use time as the source of random number generator.
r := rand.New(rand.NewSource(time.Now().Unix()))
return "debug rand int: " + strconv.Itoa(r.Intn(100))
})
// If you have a long log and it is made of many variables, try this:
// The msg is the return value of msgGenerator.
logit.DebugFunc(func() string {
// Use time as the source of random number generator.
r := rand.New(rand.NewSource(time.Now().Unix()))
return "debug rand int: " + strconv.Itoa(r.Intn(100))
})

// If a config file "logit.conf" in "./", then logit will load it automatically.
// This is more convenience to use config file and logger.
}
Loading

0 comments on commit ed5891e

Please sign in to comment.