Skip to content

Commit

Permalink
refactor: log
Browse files Browse the repository at this point in the history
  • Loading branch information
andy2046 committed Mar 12, 2020
1 parent 6fa4bb4 commit e4f79e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions docs/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (



## <a name="Config">type</a> [Config](/src/target/log.go?s=545:725#L29)
## <a name="Config">type</a> [Config](/src/target/log.go?s=580:760#L30)
``` go
type Config struct {
Level Level
Expand Down Expand Up @@ -93,7 +93,7 @@ Logging Levels.



## <a name="Logger">type</a> [Logger](/src/target/log.go?s=201:510#L16)
## <a name="Logger">type</a> [Logger](/src/target/log.go?s=201:545#L16)
``` go
type Logger interface {
Debug(v ...interface{})
Expand All @@ -105,6 +105,7 @@ type Logger interface {
Warnf(format string, v ...interface{})
Errorf(format string, v ...interface{})
SetLevel(l Level)
LevelLogger(l Level) *log.Logger
}
```
Logger is the Logging interface.
Expand All @@ -115,7 +116,7 @@ Logger is the Logging interface.



### <a name="NewLogger">func</a> [NewLogger](/src/target/log.go?s=1275:1315#L71)
### <a name="NewLogger">func</a> [NewLogger](/src/target/log.go?s=1340:1380#L74)
``` go
func NewLogger(options ...Option) Logger
```
Expand All @@ -125,7 +126,7 @@ NewLogger returns a new Logger.



## <a name="Option">type</a> [Option](/src/target/log.go?s=772:800#L40)
## <a name="Option">type</a> [Option](/src/target/log.go?s=807:835#L41)
``` go
type Option = func(*Config) error
```
Expand Down
9 changes: 9 additions & 0 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type (
Warnf(format string, v ...interface{})
Errorf(format string, v ...interface{})
SetLevel(l Level)
LevelLogger(l Level) *log.Logger
}

// Config used to init Logger.
Expand Down Expand Up @@ -65,6 +66,8 @@ var (
WarnHandler: os.Stdout,
ErrorHandler: os.Stderr,
}

_ Logger = &defaultLogger{}
)

// NewLogger returns a new Logger.
Expand Down Expand Up @@ -117,6 +120,12 @@ func (dl *defaultLogger) Errorf(format string, v ...interface{}) {
dl.logf(ERROR, format, v...)
}

func (dl *defaultLogger) LevelLogger(l Level) *log.Logger {
dl.RLock()
defer dl.RUnlock()
return dl.loggerz[l]
}

func (dl *defaultLogger) log(level Level, v ...interface{}) {
dl.RLock()
defer dl.RUnlock()
Expand Down

0 comments on commit e4f79e8

Please sign in to comment.