Skip to content

Commit 4c4e34c

Browse files
committed
添加log使用文档
1 parent f29759f commit 4c4e34c

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

doc/log_test.png

27.2 KB
Loading

log/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## crab log
2+
crab log 是一个轻量级log库,支持不同级别不同颜色输出,按天滚动输出日志文件等常用日志功能
3+
4+
## Example
5+
[![Example Output](doc/log_test.png)](log/log_test.go)
6+
7+
```go
8+
package log
9+
10+
import (
11+
"testing"
12+
"time"
13+
)
14+
15+
func TestLog(t *testing.T) {
16+
Debug("default log begin")
17+
Infof("%v test log", time.Now())
18+
19+
l := NewLogger()
20+
l.Debug("logger 1111111111")
21+
l.Info("logger 2222222222")
22+
l.Warningf("logger 33333 %v", time.Now())
23+
l.Errorf("logger color %v xxxxxx", time.Now().UnixNano())
24+
l.SetColor(false)
25+
l.Errorf("logger no color %v yyyyyy", time.Now().UnixNano())
26+
Infof("%v default has color test log", time.Now())
27+
28+
l.SetOutputFile("./vvv.log").SetRolling(true)
29+
l.Info(time.Now())
30+
}
31+
32+
```
33+
34+
## Installing
35+
36+
### Using *go get*
37+
```bash
38+
$ go get github.com/dearcode/crab/log
39+
```
40+
After this command *log* is ready to use. Its source will be in:
41+
```bash
42+
$GOPATH/src/github.com/dearcode/crab/log
43+
```
44+
45+
You can use `go get -u` to update the package.
46+
47+
## Documentation
48+
49+
For docs, see http://godoc.org/github.com/dearcode/crab/log or run:
50+
```bash
51+
$ godoc github.com/dearcode/crab/log
52+
```
53+

log/log_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
)
77

88
func TestLog(t *testing.T) {
9-
Debug("default log begin 11111111")
10-
Debugf("%s, %+v", "abc", mlog)
9+
Debug("default log begin")
1110
Infof("%v test log", time.Now())
1211

1312
l := NewLogger()
13+
l.Debug("logger 1111111111")
1414
l.Info("logger 2222222222")
15+
l.Warningf("logger 33333 %v", time.Now())
1516
l.Errorf("logger color %v xxxxxx", time.Now().UnixNano())
1617
l.SetColor(false)
1718
l.Errorf("logger no color %v yyyyyy", time.Now().UnixNano())

0 commit comments

Comments
 (0)