-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Will
committed
Aug 14, 2024
1 parent
26e63ee
commit b91588b
Showing
376 changed files
with
203,497 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,83 @@ | ||
package log | ||
|
||
import "log" | ||
import ( | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
var verbose int | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
func Debugf(fmt string, v ...interface{}) { | ||
if verbose > 0 { | ||
log.Printf(fmt, v...) | ||
type Logger zerolog.Logger | ||
|
||
var logger Logger | ||
|
||
func init() { | ||
writer := zerolog.ConsoleWriter{ | ||
NoColor: true, | ||
Out: os.Stderr, | ||
TimeFormat: time.DateTime, | ||
} | ||
|
||
logger = Logger(zerolog.New(writer).With().Timestamp().Logger()) | ||
} | ||
|
||
func Global() *Logger { | ||
return &logger | ||
} | ||
|
||
func SetVerbose(level int) { | ||
verbose = level | ||
switch level { | ||
case 1: | ||
zerolog.SetGlobalLevel(zerolog.DebugLevel) | ||
case 2: | ||
zerolog.SetGlobalLevel(zerolog.TraceLevel) | ||
default: | ||
zerolog.SetGlobalLevel(zerolog.InfoLevel) | ||
} | ||
} | ||
|
||
func Debugf(format string, v ...interface{}) { | ||
(*zerolog.Logger)(&logger).Debug().Msg(fmt.Sprintf(format, v...)) | ||
} | ||
|
||
func Fatal(err error) { | ||
(*zerolog.Logger)(&logger).Fatal().Msg(err.Error()) | ||
} | ||
|
||
func (l *Logger) Debug(msg string, kv ...interface{}) { | ||
format((*zerolog.Logger)(l).Debug(), kv...).Msg(msg) | ||
} | ||
|
||
func (l *Logger) Info(msg string, kv ...interface{}) { | ||
format((*zerolog.Logger)(l).Info(), kv...).Msg(msg) | ||
} | ||
|
||
func (l *Logger) Warn(msg string, kv ...interface{}) { | ||
format((*zerolog.Logger)(l).Warn(), kv...).Msg(msg) | ||
} | ||
|
||
func (l *Logger) Error(msg string, kv ...interface{}) { | ||
format((*zerolog.Logger)(l).Error(), kv...).Msg(msg) | ||
} | ||
|
||
func format(event *zerolog.Event, kv ...interface{}) *zerolog.Event { | ||
for i := 0; i < len(kv)-1; i += 2 { | ||
key := kv[i].(string) | ||
val := kv[i+1] | ||
switch v := val.(type) { | ||
case string: | ||
event = event.Str(key, v) | ||
case int: | ||
event = event.Int(key, v) | ||
case uint: | ||
event = event.Uint(key, v) | ||
case fmt.Stringer: | ||
event = event.Str(key, v.String()) | ||
default: | ||
event = event.Str(key, fmt.Sprintf("%v", v)) | ||
} | ||
|
||
} | ||
return event | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
vendor/github.com/mattn/go-colorable/colorable_appengine.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.