Skip to content

Commit

Permalink
Add OFF level for log
Browse files Browse the repository at this point in the history
  • Loading branch information
subchen committed Sep 29, 2017
1 parent 718ed33 commit 6b6d7ec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func IsErrorEnabled() bool {
return std.IsErrorEnabled()
}

// Indicate whether output fatal message
func IsFatalEnabled() bool {
return std.IsFatalEnabled()
}

// Output a debug message
func Debug(obj ...interface{}) {
std.Debug(obj...)
Expand Down
11 changes: 10 additions & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
L_WARN
L_ERROR
L_FATAL
L_OFF

// Bits or'ed together to control what's printed.
F_TIME = 1 << iota
Expand All @@ -44,13 +45,15 @@ var (
"WARN",
"ERROR",
"FATAL",
"OFF",
}
levelStrWithColor = []string{
"\033[34mDEBUG\033[0m",
"\033[32mINFO\033[0m",
"\033[33mWARN\033[0m",
"\033[31mERROR\033[0m",
"\033[35mFATAL\033[0m",
"OFF",
}

buffer = sync.Pool{
Expand Down Expand Up @@ -177,6 +180,10 @@ func (l *Logger) IsErrorEnabled() bool {
return l.level <= L_ERROR
}

func (l *Logger) IsFatalEnabled() bool {
return l.level <= L_FATAL
}

func (l *Logger) Debug(obj ...interface{}) {
if l.level <= L_DEBUG {
l.log(L_DEBUG, fmt.Sprint(obj...))
Expand Down Expand Up @@ -232,7 +239,9 @@ func (l *Logger) Errorf(msg string, args ...interface{}) {
}

func (l *Logger) Fatalf(msg string, args ...interface{}) {
l.log(L_FATAL, fmt.Sprintf(msg, args...))
if l.level <= L_FATAL {
l.log(L_FATAL, fmt.Sprintf(msg, args...))
}
}

func (l *Logger) log(level int, msg string) {
Expand Down

0 comments on commit 6b6d7ec

Please sign in to comment.