Skip to content

Commit

Permalink
v0.2.2-alpha 版本预发布
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed Apr 28, 2020
2 parents 5674df3 + c432bcd commit 2224639
Show file tree
Hide file tree
Showing 36 changed files with 557 additions and 161 deletions.
6 changes: 4 additions & 2 deletions FUTURE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
## ✒ 未来版本的新特性 (Features in future version)

### v0.2.x
* 改造全局使用的 logger,可以使用一个默认的配置文件或者 flag 参数来初始化全局 logger
* 增加 level_handler.go,里面是不同日志级别的日志处理器包装器,可以传一堆的 handler 进去
* 增加 timeout_handler.go,里面是带超时功能的日志处理器包装器

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

### v0.2.1-alpha
* 将 console handler 简化,目前使用 RegisterHandler 构造
* 从 file handler 中抽取出 duration rolling 和 size rolling 两个日志处理器
Expand Down
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## ✒ 历史版本的特性介绍 (Features in old version)

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

### v0.2.1-alpha
> 此版本发布于 2020-04-27
* 将 console handler 简化,目前使用 RegisterHandler 构造
Expand Down
45 changes: 24 additions & 21 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.2.1-alpha
github.com/FishGoddess/logit v0.2.2-alpha
)
```

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 Down
42 changes: 24 additions & 18 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.2.1-alpha
github.com/FishGoddess/logit v0.2.2-alpha
)
```

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 Down
12 changes: 9 additions & 3 deletions _examples/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// 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
Expand All @@ -33,8 +33,11 @@ func main() {
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()
// 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:
Expand All @@ -44,4 +47,7 @@ func main() {
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.
}
8 changes: 5 additions & 3 deletions _examples/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: fish
// Author: FishGoddess
// Email: [email protected]
// Created at 2020/03/02 20:51:29

Expand All @@ -30,8 +30,10 @@ import (
//"go.uber.org/zap/zapcore"
)

// 时间格式化字符串
const timeFormat = "2006-01-02 15:04:05"
const (
// 时间格式化字符串
timeFormat = "2006-01-02 15:04:05"
)

type nopWriter struct{}

Expand Down
30 changes: 30 additions & 0 deletions _examples/config/logit-config-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,35 @@
# 如果不配置的话,默认是 2006-01-02 15:04:05
# "timeFormat": "unix",
"timeFormat": "2006年01月02日"
},

# level based 日志处理器
# 这个日志处理器一共有四个:debug,info,warn,error
# 它们只是一个包装器,做了一个日志级别的过滤,比如 debug 的日志处理器就只会处理 debug 级别的日志
# 每个日志处理器内部可以添加多个日志处理器,比如 console 日志处理器,甚至是再添加一个 level based 日志处理器
# 所以日志怎么处理还是要靠具体添加的日志处理器,您可以添加所有注册进 logit 或者说上面出现的日志处理器
"debug": {
"console": {},
"file": {
"path": "D:/debug.log"
}
},
"info": {
"console": {},
"file": {
"path": "D:/info.log"
}
},
"warn": {
"console": {},
"file": {
"path": "D:/warn.log"
}
},
"error": {
"console": {},
"file": {
"path": "D:/error.log"
}
}
}
31 changes: 31 additions & 0 deletions _examples/config/logit-config-template.en.conf
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,36 @@
# Default is 2006-01-02 15:04:05
# "timeFormat": "unix",
"timeFormat": "2006-01-02"
},

# level based 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 handler only handles logs in debug level
# Every level based handler can have many handlers, such as console handler, even one more level based 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:/debug.log"
}
},
"info": {
"console": {},
"file": {
"path": "D:/info.log"
}
},
"warn": {
"console": {},
"file": {
"path": "D:/warn.log"
}
},
"error": {
"console": {},
"file": {
"path": "D:/error.log"
}
}
}
4 changes: 2 additions & 2 deletions _examples/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: fish
// Author: FishGoddess
// Email: [email protected]
// Created at 2020/03/30 14:21:28

Expand Down Expand Up @@ -44,7 +44,7 @@ func main() {
// }
// }
//
logger := logit.NewLoggerFrom("./logger.conf")
logger := logit.NewLoggerFromPath("./logger.conf")
logger.Info("I am working!")
logger.Info("My level is " + logger.Level().String())
fmt.Println("fmt ==============================================")
Expand Down
2 changes: 1 addition & 1 deletion _examples/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: fish
// Author: FishGoddess
// Email: [email protected]
// Created at 2020/03/06 16:01:00

Expand Down
16 changes: 10 additions & 6 deletions _examples/level_and_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: fish
// Author: FishGoddess
// Email: [email protected]
// Created at 2020/03/01 15:10:19

Expand All @@ -22,20 +22,24 @@ import "github.com/FishGoddess/logit"

func main() {

// Use logit.Debug method to output a debug level message.
// Also, Info/Warn/Error method is available.
logit.Debug("Default logger level is debug.")

// Change logger level to info level.
// So debug log will be ignored.
logit.ChangeLevelTo(logit.InfoLevel)
// Change logger level to info level, so logs in debug level will be ignored.
// 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.
logit.Me().ChangeLevelTo(logit.InfoLevel)
logit.Debug("You never see me!")

// In particular, you can change level to OffLevel to disable the logger.
// So the info message next line will not be logged!
level := logit.ChangeLevelTo(logit.OffLevel)
level := logit.Me().ChangeLevelTo(logit.OffLevel)
logit.Info("I will not be logged!")

// Enable the Logger.
// The info message next line will be logged again!
logit.ChangeLevelTo(level)
logit.Me().ChangeLevelTo(level)
logit.Info("I am running again!")
}
25 changes: 25 additions & 0 deletions _examples/level_based_handler.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"handlers": {
"debug": {
"file": {
"path": "Z:/debug.log"
}
},
"info": {
"file": {
"path": "Z:/info.log"
}
},
"warn": {
"file": {
"path": "Z:/warn.log"
}
},
"error": {
"file": {
"path": "Z:/error.log"
}
},
"console": {
"encoder": "json"
}
}
2 changes: 1 addition & 1 deletion _examples/log_to_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: fish
// Author: FishGoddess
// Email: [email protected]
// Created at 2020/03/03 23:39:39

Expand Down
2 changes: 1 addition & 1 deletion _examples/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: fish
// Author: FishGoddess
// Email: [email protected]
// Created at 2020/03/01 14:51:46

Expand Down
2 changes: 1 addition & 1 deletion _examples/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: fish
// Author: FishGoddess
// Email: [email protected]
// Created at 2020/03/05 17:30:21

Expand Down
Loading

0 comments on commit 2224639

Please sign in to comment.