Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-01-12 10:23:17 +03:00
parent bec4b6f98c
commit 5becd73213
2 changed files with 9 additions and 17 deletions

View File

@ -205,7 +205,6 @@ func (l *zeroLogger) String() string {
}
func (l *zeroLogger) Options() logger.Options {
// FIXME: How to return full opts?
return l.opts.Options
}
@ -213,12 +212,7 @@ func (l *zeroLogger) Options() logger.Options {
func NewLogger(opts ...logger.Option) logger.Logger {
// Default options
options := Options{
Options: logger.Options{
Level: 100,
Fields: make(map[string]interface{}),
Out: os.Stderr,
Context: context.Background(),
},
Options: logger.NewOptions(opts...),
ReportCaller: false,
UseAsDefault: false,
Mode: Production,
@ -226,7 +220,6 @@ func NewLogger(opts ...logger.Option) logger.Logger {
}
l := &zeroLogger{opts: options}
_ = l.Init(opts...)
return l
}

View File

@ -13,7 +13,7 @@ import (
func TestName(t *testing.T) {
l := NewLogger()
l.Init()
if l.String() != "zerolog" {
t.Errorf("error: name expected 'zerolog' actual: %s", l.String())
}
@ -23,13 +23,12 @@ func TestName(t *testing.T) {
func TestWithOutput(t *testing.T) {
logger.DefaultLogger = NewLogger(logger.WithOutput(os.Stdout))
logger.DefaultLogger.Init()
logger.Infof(context.TODO(), "testing: %s", "WithOutput")
}
func TestSetLevel(t *testing.T) {
logger.DefaultLogger = NewLogger()
logger.Init(logger.WithLevel(logger.DebugLevel))
logger.Debugf(context.TODO(), "test show debug: %s", "debug msg")
@ -39,25 +38,25 @@ func TestSetLevel(t *testing.T) {
func TestWithReportCaller(t *testing.T) {
logger.DefaultLogger = NewLogger(ReportCaller())
logger.DefaultLogger.Init()
logger.Infof(context.TODO(), "testing: %s", "WithReportCaller")
}
func TestWithOut(t *testing.T) {
logger.DefaultLogger = NewLogger(logger.WithOutput(os.Stdout))
logger.DefaultLogger.Init()
logger.Infof(context.TODO(), "testing: %s", "WithOut")
}
func TestWithDevelopmentMode(t *testing.T) {
logger.DefaultLogger = NewLogger(WithDevelopmentMode(), WithTimeFormat(time.Kitchen))
logger.DefaultLogger.Init()
logger.Infof(context.TODO(), "testing: %s", "DevelopmentMode")
}
func TestWithFields(t *testing.T) {
logger.DefaultLogger = NewLogger()
logger.DefaultLogger.Init()
logger.Fields(map[string]interface{}{
"sumo": "demo",
"human": true,
@ -67,7 +66,7 @@ func TestWithFields(t *testing.T) {
func TestWithError(t *testing.T) {
logger.DefaultLogger = NewLogger()
logger.DefaultLogger.Init()
logger.Fields(map[string]interface{}{"error": errors.New("I am Error")}).Errorf(context.TODO(), "testing: %s", "WithError")
}
@ -78,6 +77,6 @@ func TestWithHooks(t *testing.T) {
})
logger.DefaultLogger = NewLogger(WithHooks([]zerolog.Hook{simpleHook}))
logger.DefaultLogger.Init()
logger.Infof(context.TODO(), "testing: %s", "WithHooks")
}