Skip to content

Commit

Permalink
祝大家平安夜、圣诞节快乐!
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed Dec 24, 2020
1 parent 6a80e53 commit 9687302
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 807 deletions.
3 changes: 3 additions & 0 deletions FUTURE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## ✒ 未来版本的新特性 (Features in future versions)

### v0.3.3
* 使用多个变量替代 map,避免哈希消耗性能

### v0.3.x
经过一段时间的实际使用,发现了一些不太方便的地方需要进行调整。
* Handler 的设计太过于抽象,导致很多日志库本身的功能实现过于剥离、插件化
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 versions)

### v0.3.2
> 此版本发布于 2020-12-24
* 废弃了 files 包
* 完善文档,第一个 v0.3.x 正式版
* 最后,祝大家平安夜、圣诞节快乐!

### v0.3.1-alpha
> 此版本发布于 2020-12-13
* 日志文件自动分割处理,支持 Checker 机制检查是否需要分割
Expand Down
5 changes: 2 additions & 3 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![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.
**logit** is a level-based and high-performance logger for [GoLang](https://golang.org) applications.

[阅读中文版的 Read me](./README.md)

Expand All @@ -13,7 +13,6 @@

* Modularization design, easy to extend your logger with encoders and writers
* Level-based logging, and there are four levels to use
* Config file supports, you can use a config file to change you logger flexibility even it has been a binary
* 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
* Time rolling supports, such as one day one log file
Expand All @@ -25,7 +24,7 @@

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

> Currently, stable version is v0.2.x, but a brand-new version v0.3.x is alpha with a more elegant design!
> The brand-new version v0.3.x is released with a more elegant design!
### 🚀 Installation

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![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) 应用程序中。
**logit** 是一个基于级别控制的高性能日志库,可以应用于所有的 [GoLang](https://golang.org) 应用程序中。

[Read me in English](./README.en.md)

Expand All @@ -13,7 +13,6 @@

* 独特的日志输出模块设计,使用 encoder 和 writer 装载特定的模块,实现扩展功能
* 支持日志级别控制,一共有四个日志级别,分别是 debug,info,warn 和 error
* 支持配置文件,可以让用户在项目编译成二进制之后还能灵活地控制日志的设置
* 支持开启或者关闭日志功能,线上环境可以关闭或调高日志级别
* 支持记录日志到文件中,并且可以自定义日志文件名
* 支持按照时间间隔进行自动分割日志文件,比如每一天分割一个日志文件
Expand All @@ -25,7 +24,7 @@

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

> 目前稳定的是 v0.2.x 版本,但是 v0.3.x 版本已经出了第一个体验版,这是一个全新设计的版本,废除了很多冗余设计!
> v0.3.x 版本已经出了第一个稳定版,这是一个全新设计的版本,废除了很多冗余设计!
### 🚀 安装方式

Expand Down
20 changes: 15 additions & 5 deletions _examples/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
package main

import (
"os"
"path/filepath"
"testing"
//"time"

"github.com/FishGoddess/logit"
"github.com/FishGoddess/logit/files"
//"github.com/kataras/golog"
//"github.com/sirupsen/logrus"
//"go.uber.org/zap"
Expand Down Expand Up @@ -175,10 +176,19 @@ func BenchmarkLogitLogger(b *testing.B) {

// ******************************************************

// 创建文件
func createFileOf(filePath string) (*os.File, error) {
err := os.MkdirAll(filepath.Dir(filePath), 0644)
if err != nil {
return nil, err
}
return os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
}

// 测试 logit 文件日志记录器的速度
func BenchmarkLogitFile(b *testing.B) {

file, _ := files.CreateFileOf("Z:/BenchmarkLogitFile.log")
file, _ := createFileOf("Z:/BenchmarkLogitFile.log")
logger := logit.NewLogger()
logger.SetLevel(logit.DebugLevel)
logger.TimeFormat(timeFormat)
Expand All @@ -204,7 +214,7 @@ func BenchmarkLogitFile(b *testing.B) {
//func BenchmarkGologFile(b *testing.B) {
//
// logger := golog.New()
// file, _ := files.CreateFileOf("Z:/BenchmarkGologFile.log")
// file, _ := createFileOf("Z:/BenchmarkGologFile.log")
// logger.SetOutput(file)
// logger.SetLevel("debug")
// logger.SetTimeFormat(timeFormat)
Expand Down Expand Up @@ -235,7 +245,7 @@ func BenchmarkLogitFile(b *testing.B) {
// enc.AppendString(t.Format(timeFormat))
// }
// encoder := zapcore.NewConsoleEncoder(config)
// file, _ := files.CreateFileOf("Z:/BenchmarkZapFile.log")
// file, _ := createFileOf("Z:/BenchmarkZapFile.log")
// writeSyncer := zapcore.AddSync(file)
// core := zapcore.NewCore(encoder, writeSyncer, zapcore.DebugLevel)
// logger := zap.New(core)
Expand All @@ -262,7 +272,7 @@ func BenchmarkLogitFile(b *testing.B) {
//func BenchmarkLogrusFile(b *testing.B) {
//
// logger := logrus.New()
// file, _ := files.CreateFileOf("Z:/BenchmarkLogrusFile.log")
// file, _ := createFileOf("Z:/BenchmarkLogrusFile.log")
// logger.SetOutput(file)
// logger.SetLevel(logrus.DebugLevel)
// logger.SetFormatter(&logrus.TextFormatter{
Expand Down
39 changes: 38 additions & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,47 @@ Package logit provides an easy way to use foundation for your logging operations
logger.SetEncoder(logit.TextEncoder())
logger.SetWarnEncoder(logit.JsonEncoder())
4. writer
// We provide a writer writing to file
// "./test.log" is the path of this file
writer, err := logit.NewFileWriter("Z:/test.log")
if err != nil {
panic(err)
}
defer writer.Close()
// Use Write() to write something to file underlying
writer.Write([]byte("Something new..."))
// Also, we provide some checkers for advanced features
// Every writing operation will call Check() in checker
// If one checker's Check() returns true, then this file will roll to a new file
// The old file will be renamed to be like "xxx.log.0000000001"
// These are all checkers we provide:
logit.NewTimeChecker(24 * time.Hour)
logit.NewSizeChecker(64 * logit.MB)
logit.NewCountChecker(1000)
// If you want to use one of them above, try this:
newWriter, err := logit.NewFileWriter("Z:/test_checker.log", logit.NewSizeChecker(128*logit.KB))
if err != nil {
panic(err)
}
defer newWriter.Close()
// Check how many files starting with "test_checker.log"?
for i := 0; i < 10000; i++ {
newWriter.Write([]byte(fmt.Sprintf("Something new with checker...%d\n", i)))
}
// Also, you can use more than one of them in a writer
//logit.NewFileWriter("Z:/test_checker.log", logit.NewTimeChecker(24*time.Hour), logit.NewSizeChecker(128*logit.KB))
*/
package logit // import "github.com/FishGoddess/logit"

const (
// Version is the version string representation of logit.
Version = "v0.3.0-alpha"
Version = "v0.3.2"
)
55 changes: 0 additions & 55 deletions files/doc.go

This file was deleted.

138 changes: 0 additions & 138 deletions files/duration_rolling_file.go

This file was deleted.

Loading

0 comments on commit 9687302

Please sign in to comment.