Skip to content

Commit

Permalink
v0.0.7 版本发布
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed Mar 6, 2020
2 parents d985882 + 195e8b1 commit 3378271
Show file tree
Hide file tree
Showing 14 changed files with 432 additions and 51 deletions.
6 changes: 4 additions & 2 deletions FUTURE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
## ✒ 未来版本的新特性 (Features in future version)

### v0.0.7
* 尝试丢弃标准库的 log 实现,自己实现日志的输出
* 支持关闭文件信息的获取,避免 runtime.Caller 方法的调用,提高性能
* 重构日志输出的模块,抛弃了标准库的 log 设计
* 增加日志处理器模块,支持用户自定义日志处理逻辑,大大地提高了扩展能力
* 支持不输出文件信息,避免 runtime.Caller 方法的调用,大大地提高了性能
* 支持调整时间格式化输出,让用户自定义时间输出的格式

### v0.0.6
* 支持按照文件大小自动划分日志文件
Expand Down
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## ✒ 历史版本的特性介绍 (Features in old version)

### v0.0.7
> 此版本发布于 2020-03-06
* 重构日志输出的模块,抛弃了标准库的 log 设计
* 增加日志处理器模块,支持用户自定义日志处理逻辑,大大地提高了扩展能力
* 支持不输出文件信息,避免 runtime.Caller 方法的调用,大大地提高了性能
* 支持调整时间格式化输出,让用户自定义时间输出的格式

### v0.0.6
> 此版本发布于 2020-03-05
* 支持按照文件大小自动划分日志文件
Expand Down
18 changes: 10 additions & 8 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

### 🥇 Features

* Modularization design, easy to extend your logger with wrapper and handler
* Level-based logging, and there are four levels to use
* Enable or disable Logger, you can disable or switch to a higher level in your production environment
* Log file supports, and you can customer the name of your log file.
* Duration rolling supports, which means it will roll to a new log file by duration automatically, such as one day one log file.
* File size rolling supports, which means it will roll to a new log file by file size automatically, such as one 64 MB one log file.
* Log handler supports, you can extend logger with your own log handler easily.
* High-performance supports, by avoiding to call runtime.Caller
* Time format supports, you can format time in your way.

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

Expand All @@ -34,7 +38,7 @@ module your_project_name
go 1.14

require (
github.com/FishGoddess/logit v0.0.6
github.com/FishGoddess/logit v0.0.7
)
```

Expand Down Expand Up @@ -77,6 +81,7 @@ func main() {
* [change_log_level](./_examples/change_log_level.go)
* [log_to_file](./_examples/log_to_file.go)
* [wrapper](./_examples/wrapper.go)
* [handler](./_examples/logger_handler.go)

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

Expand All @@ -90,19 +95,16 @@ $ go test -v ./_examples/benchmarks_test.go -bench=. -benchtime=20s
| test case | times ran (large is better) | ns/op (small is better) | B/op (small is better) | allocs/op (small is better) |
| -----------|--------|-------------|-------------|-------------|
| **logit** |   4405342 | 5409 ns/op |   904 B/op | 12 allocs/op |
| **logit (without file info)** | 20341443 | 1130 ns/op |     32 B/op |   4 allocs/op |
| **logit** |   8617952 | 2807 ns/op |   352 B/op | 20 allocs/op |
| logrus |   2990408 | 7991 ns/op | 1633 B/op | 52 allocs/op |
| Golang log |   5308578 | 4539 ns/op |   920 B/op | 12 allocs/op |
| Golog | 15536137 | 1556 ns/op |   232 B/op | 16 allocs/op |

> Environment:I7-6700HQ CPU @ 2.6 GHZ, 16 GB RAM
**Notice that golog's output is without file info, and fetch file info will call runtime.Caller, which is expensive,**
**so it has no doubts that golog runs fast. However, we think file info is useful in check errors,**
**so we keep this feature, and provide a switch to turn off it for high-performance (coming soon).**

_Logit is based on Golang log, so it looks like not better than Golang log. Don't worry, we will redesign the implement of log output!_
**Notice that fetch file info will call runtime.Caller, which is expensive.**
**However, we think file info is useful in check errors,**
**so we keep this feature, and provide a switch to turn off it for high-performance.**

### 👥 Contributing

Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

### 🥇 功能特性

* 支持日志级别控制,目前一共有四个日志级别
* 独特的日志输出模块设计,使用 wrapper 和 handler 装载特定的模块,实现扩展功能
* 支持日志级别控制,一共有四个日志级别,分别是 debug,info,warn 和 error。
* 支持开启或者关闭日志功能,线上环境可以关闭或调高日志级别
* 支持记录日志到文件中,自定义日志文件名
* 支持按照时间间隔进行自动划分日志文件,比如每一天划分一个日志文件
* 支持按照文件大小进行自动划分日志文件,比如每 64 MB 划分一个日志文件
* 增加日志处理器模块,支持用户自定义日志处理逻辑,具有很高的扩展能力
* 支持不输出文件信息,避免 runtime.Caller 方法的调用,具有很高的性能
* 支持调整时间格式化输出,让用户自定义时间输出的格式

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

Expand All @@ -34,7 +38,7 @@ module your_project_name
go 1.14

require (
github.com/FishGoddess/logit v0.0.6
github.com/FishGoddess/logit v0.0.7
)
```

Expand Down Expand Up @@ -77,6 +81,7 @@ func main() {
* [change_log_level](./_examples/change_log_level.go)
* [log_to_file](./_examples/log_to_file.go)
* [wrapper](./_examples/wrapper.go)
* [handler](./_examples/logger_handler.go)

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

Expand All @@ -90,19 +95,16 @@ $ go test -v ./_examples/benchmarks_test.go -bench=. -benchtime=20s
| 测试 | 单位时间内运行次数 (large is better) | ns/op (small is better) | B/op (small is better) | allocs/op (small is better) |
| -----------|--------|-------------|-------------|-------------|
| **logit** |   4405342 | 5409 ns/op |   904 B/op | 12 allocs/op |
| **logit (关闭文件信息)** | 20341443 | 1130 ns/op |     32 B/op |   4 allocs/op |
| **logit** |   8617952 | 2807 ns/op |   352 B/op | 20 allocs/op |
| logrus |   2990408 | 7991 ns/op | 1633 B/op | 52 allocs/op |
| Golang log |   5308578 | 4539 ns/op |   920 B/op | 12 allocs/op |
| Golog | 15536137 | 1556 ns/op |   232 B/op | 16 allocs/op |

> 测试环境:I7-6700HQ CPU @ 2.6 GHZ,16 GB RAM
**注意:golog 库是不会输出文件信息的,也就是少了运行时操作(runtime.Caller 方法),性能自然会高很多**
**注意:输出文件信息会有运行时操作(runtime.Caller 方法),非常影响性能**
**但是这个功能感觉还是比较实用的,尤其是在查找错误的时候,所以我们还是加了这个功能!**
**如果你更在乎性能,那我们也提供了一个选项可以关闭文件信息的查询(开发中)!**

_由于目前的 logit 是基于 Golang log 的,所以成绩相比更差,后续会重新设计内部日志输出模块,所以当前成绩仅供参考!_
**如果你更在乎性能,那我们也提供了一个选项可以关闭文件信息的查询!**

### 👥 贡献者

Expand Down
4 changes: 4 additions & 0 deletions _examples/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ func main() {

// If you want format your message, just add arguments!
logit.Info("format info message! id = %d, content = %s", 1, "info!")

// If you want to output log with file info, try this:
logit.EnableFileInfo()
logit.Info("Show file info!")
}
11 changes: 10 additions & 1 deletion _examples/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ func main() {

// If you want format your message, just add arguments!
logger.Error("format info message! id = %d, content = %s", 1, "info!")
}

// If you want format your time, try this:
logger.SetFormatOfTime("2006/01/02 15:04:05")
logger.Info("What time is it now?")

// If you want to output log with file info, try this:
logger.EnableFileInfo()
logger.Info("What file is it? Which line?")
logger.DisableFileInfo()
}
59 changes: 59 additions & 0 deletions _examples/logger_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2020 Ye Zi Jie. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: fish
// Email: [email protected]
// Created at 2020/03/06 16:01:00

package main

import (
"fmt"
"os"
"time"

"github.com/FishGoddess/logit"
)

func main() {

// Create a logger holder.
// Default handler is logit.DefaultLoggerHandler.
logger := logit.NewLogger(os.Stdout, logit.InfoLevel)
logger.Info("before logging...")

// Customize your own handler.
handlers1 := func(logger *logit.Logger, level logit.LoggerLevel, now time.Time, msg string) bool {
logger.Writer().Write([]byte("handlers1: " + msg + "\n"))
return true
}

handlers2 := func(logger *logit.Logger, level logit.LoggerLevel, now time.Time, msg string) bool {
logger.Writer().Write([]byte("handlers2: " + msg + "\n"))
return true
}

// Add handlers to logger.
// There are three handlers in logger because logger has a default handler inside after creating.
// See logit.DefaultLoggerHandler.
logger.AddHandlers(handlers1, handlers2)
fmt.Println("fmt =========================================")
logger.Info("after adding handlers...")

// Set handlers to logger.
// There are two handlers in logger because the default handler inside was removed.
logger.SetHandlers(handlers1, handlers2)
fmt.Println("fmt =========================================")
logger.Info("after setting handlers...")
}
46 changes: 45 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Package logit provides an easy way to use foundation for your logging operations
// If you want format your message, just add arguments!
logit.Info("format info message! id = %d, content = %s", 1, "info!")
// If you want to output log with file info, try this:
logit.EnableFileInfo()
logit.Info("Show file info!")
2. logger:
// NewStdoutLogger creates a new Logger holder to standard output, generally a terminal or a console.
Expand All @@ -54,6 +58,15 @@ Package logit provides an easy way to use foundation for your logging operations
// If you want format your message, just add arguments!
logger.Info("format info message! id = %d, content = %s", 1, "info!")
// If you want format your time, try this:
logger.SetFormatOfTime("2006/01/02 15:04:05")
logger.Info("What time is it now?")
// If you want to output log with file info, try this:
logger.EnableFileInfo()
logger.Info("What file is it? Which line?")
logger.DisableFileInfo()
3. enable or disable:
// Every new Logger is running.
Expand Down Expand Up @@ -117,8 +130,39 @@ Package logit provides an easy way to use foundation for your logging operations
logger = logit.NewDefaultSizeRollingLogger("D:/", logit.DebugLevel)
logger.Info("64 MB rolling!!!")
6. logger handler:
// Create a logger holder.
// Default handler is logit.DefaultLoggerHandler.
logger := logit.NewLogger(os.Stdout, logit.InfoLevel)
logger.Info("before logging...")
// Customize your own handler.
handlers1 := func(logger *logit.Logger, level logit.LoggerLevel, now time.Time, msg string) bool {
logger.Writer().Write([]byte("handlers1: " + msg + "\n"))
return true
}
handlers2 := func(logger *logit.Logger, level logit.LoggerLevel, now time.Time, msg string) bool {
logger.Writer().Write([]byte("handlers2: " + msg + "\n"))
return true
}
// Add handlers to logger.
// There are three handlers in logger because logger has a default handler inside after creating.
// See logit.DefaultLoggerHandler.
logger.AddHandlers(handlers1, handlers2)
fmt.Println("fmt =========================================")
logger.Info("after adding handlers...")
// Set handlers to logger.
// There are two handlers in logger because the default handler inside was removed.
logger.SetHandlers(handlers1, handlers2)
fmt.Println("fmt =========================================")
logger.Info("after setting handlers...")
*/
package logit // import "github.com/FishGoddess/logit"

// Version is the version string representation of the "logit" package.
const Version = "0.0.6"
const Version = "0.0.7"
Loading

0 comments on commit 3378271

Please sign in to comment.