You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by mi...@apache.org on 2023/02/21 05:29:56 UTC

[shardingsphere-on-cloud] branch main updated: feat:cli add logger (#216)

This is an automated email from the ASF dual-hosted git repository.

miaoliyao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/shardingsphere-on-cloud.git


The following commit(s) were added to refs/heads/main by this push:
     new 6bee145  feat:cli add logger (#216)
6bee145 is described below

commit 6bee14573ce26713b61de82574e397969c156fe1
Author: lltgo <ll...@outlook.com>
AuthorDate: Tue Feb 21 13:29:51 2023 +0800

    feat:cli add logger (#216)
---
 pitr/cli/go.mod                            |  8 ++-
 pitr/cli/go.sum                            | 18 +++++++
 pitr/cli/internal/cmd/backup.go            | 30 ++++++-----
 pitr/cli/internal/cmd/resotre.go           | 32 ++++++------
 pitr/cli/internal/cmd/root.go              | 22 ++++----
 pitr/cli/internal/cmd/show.go              | 32 ++++++------
 pitr/cli/main.go                           | 24 ++++++++-
 pitr/cli/{main.go => pkg/logging/field.go} | 34 +++++++++----
 pitr/cli/pkg/logging/log.go                | 69 +++++++++++++++++++++++++
 pitr/cli/pkg/logging/zap_log.go            | 82 ++++++++++++++++++++++++++++++
 10 files changed, 286 insertions(+), 65 deletions(-)

diff --git a/pitr/cli/go.mod b/pitr/cli/go.mod
index 187e2bb..27eab04 100644
--- a/pitr/cli/go.mod
+++ b/pitr/cli/go.mod
@@ -2,8 +2,14 @@ module github.com/apache/shardingsphere-on-cloud/pitr/cli
 
 go 1.20
 
+require (
+	github.com/spf13/cobra v1.6.1
+	go.uber.org/zap v1.24.0
+)
+
 require (
 	github.com/inconshreveable/mousetrap v1.0.1 // indirect
-	github.com/spf13/cobra v1.6.1 // indirect
 	github.com/spf13/pflag v1.0.5 // indirect
+	go.uber.org/atomic v1.7.0 // indirect
+	go.uber.org/multierr v1.6.0 // indirect
 )
diff --git a/pitr/cli/go.sum b/pitr/cli/go.sum
index 442875a..9726ac1 100644
--- a/pitr/cli/go.sum
+++ b/pitr/cli/go.sum
@@ -1,10 +1,28 @@
+github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
 github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
 github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
+github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
 github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
 github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
+go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
+go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
+go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
+go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
+go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
+go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
+go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/pitr/cli/internal/cmd/backup.go b/pitr/cli/internal/cmd/backup.go
index 62a2fff..946f7a8 100644
--- a/pitr/cli/internal/cmd/backup.go
+++ b/pitr/cli/internal/cmd/backup.go
@@ -21,6 +21,8 @@ import (
 	"fmt"
 
 	"github.com/spf13/cobra"
+
+	"github.com/apache/shardingsphere-on-cloud/pitr/cli/pkg/logging"
 )
 
 const (
@@ -35,45 +37,45 @@ var Backup = &cobra.Command{
 
 		host, err := cmd.Flags().GetString(host)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:host:%s", host))
+		logging.Info(fmt.Sprintf("flags:host:%s", host))
 
 		port, err := cmd.Flags().GetUint16(port)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:port:%d", port))
+		logging.Info(fmt.Sprintf("flags:port:%d", port))
 
 		un, err := cmd.Flags().GetString(username)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:username:%s", un))
+		logging.Info(fmt.Sprintf("flags:username:%s", un))
 
 		pw, err := cmd.Flags().GetString(password)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:password:%s", pw))
+		logging.Info(fmt.Sprintf("flags:password:%s", pw))
 
 		agentPort, err := cmd.Flags().GetUint16(agentPort)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:agentPort:%d", agentPort))
+		logging.Info(fmt.Sprintf("flags:agentPort:%d", agentPort))
 
 		backupPath, err := cmd.Flags().GetString(dnBackupPath)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:backupPath:%s", backupPath))
+		logging.Info(fmt.Sprintf("flags:backupPath:%s", backupPath))
 
 		threadsNum, err := cmd.Flags().GetUint16(dnThreadsNum)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:threadsNum:%d", threadsNum))
+		logging.Info(fmt.Sprintf("flags:threadsNum:%d", threadsNum))
 	},
 }
 
diff --git a/pitr/cli/internal/cmd/resotre.go b/pitr/cli/internal/cmd/resotre.go
index 4c25d06..95393e3 100644
--- a/pitr/cli/internal/cmd/resotre.go
+++ b/pitr/cli/internal/cmd/resotre.go
@@ -21,6 +21,8 @@ import (
 	"fmt"
 
 	"github.com/spf13/cobra"
+
+	"github.com/apache/shardingsphere-on-cloud/pitr/cli/pkg/logging"
 )
 
 const (
@@ -34,47 +36,47 @@ var Restore = &cobra.Command{
 	Run: func(cmd *cobra.Command, args []string) {
 		host, err := cmd.Flags().GetString(host)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:host:%s", host))
+		logging.Info(fmt.Sprintf("flags:host:%s", host))
 
 		port, err := cmd.Flags().GetUint16(port)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:port:%d", port))
+		logging.Info(fmt.Sprintf("flags:port:%d", port))
 
 		un, err := cmd.Flags().GetString(username)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:username:%s", un))
+		logging.Info(fmt.Sprintf("flags:username:%s", un))
 
 		pw, err := cmd.Flags().GetString(password)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:password:%s", pw))
+		logging.Info(fmt.Sprintf("flags:password:%s", pw))
 
 		agentPort, err := cmd.Flags().GetUint16(agentPort)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:agentPort:%d", agentPort))
+		logging.Info(fmt.Sprintf("flags:agentPort:%d", agentPort))
 
 		csn, err := cmd.Flags().GetString(csn)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:csn:%s", csn))
+		logging.Info(fmt.Sprintf("flags:csn:%s", csn))
 
 		id, err := cmd.Flags().GetString(backupRecordID)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:id:%s", id))
+		logging.Info(fmt.Sprintf("flags:id:%s", id))
 
-		fmt.Println("Restore...")
+		logging.Info("Restore...")
 	},
 }
 
diff --git a/pitr/cli/internal/cmd/root.go b/pitr/cli/internal/cmd/root.go
index 9232eea..fef013e 100644
--- a/pitr/cli/internal/cmd/root.go
+++ b/pitr/cli/internal/cmd/root.go
@@ -21,6 +21,8 @@ import (
 	"fmt"
 
 	"github.com/spf13/cobra"
+
+	"github.com/apache/shardingsphere-on-cloud/pitr/cli/pkg/logging"
 )
 
 const (
@@ -37,33 +39,33 @@ var Root = &cobra.Command{
 	Run: func(cmd *cobra.Command, args []string) {
 		host, err := cmd.Flags().GetString(host)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:host:%s", host))
+		logging.Info(fmt.Sprintf("flags:host:%s", host))
 
 		port, err := cmd.Flags().GetUint16(port)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:port:%d", port))
+		logging.Info(fmt.Sprintf("flags:port:%d", port))
 
 		un, err := cmd.Flags().GetString(username)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:username:%s", un))
+		logging.Info(fmt.Sprintf("flags:username:%s", un))
 
 		pw, err := cmd.Flags().GetString(password)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:password:%s", pw))
+		logging.Info(fmt.Sprintf("flags:password:%s", pw))
 
 		agentPort, err := cmd.Flags().GetUint16(agentPort)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:agentPort:%d", agentPort))
+		logging.Info(fmt.Sprintf("flags:agentPort:%d", agentPort))
 	},
 	CompletionOptions: cobra.CompletionOptions{
 		DisableDefaultCmd: true,
diff --git a/pitr/cli/internal/cmd/show.go b/pitr/cli/internal/cmd/show.go
index 664fd2d..3860bb6 100644
--- a/pitr/cli/internal/cmd/show.go
+++ b/pitr/cli/internal/cmd/show.go
@@ -21,6 +21,8 @@ import (
 	"fmt"
 
 	"github.com/spf13/cobra"
+
+	"github.com/apache/shardingsphere-on-cloud/pitr/cli/pkg/logging"
 )
 
 var Show = &cobra.Command{
@@ -29,47 +31,47 @@ var Show = &cobra.Command{
 	Run: func(cmd *cobra.Command, args []string) {
 		host, err := cmd.Flags().GetString(host)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:host:%s", host))
+		logging.Info(fmt.Sprintf("flags:host:%s", host))
 
 		port, err := cmd.Flags().GetUint16(port)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:port:%d", port))
+		logging.Info(fmt.Sprintf("flags:port:%d", port))
 
 		un, err := cmd.Flags().GetString(username)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:username:%s", un))
+		logging.Info(fmt.Sprintf("flags:username:%s", un))
 
 		pw, err := cmd.Flags().GetString(password)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:password:%s", pw))
+		logging.Info(fmt.Sprintf("flags:password:%s", pw))
 
 		agentPort, err := cmd.Flags().GetUint16(agentPort)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:agentPort:%d", agentPort))
+		logging.Info(fmt.Sprintf("flags:agentPort:%d", agentPort))
 
 		csn, err := cmd.Flags().GetString(csn)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:csn:%s", csn))
+		logging.Info(fmt.Sprintf("flags:csn:%s", csn))
 
 		id, err := cmd.Flags().GetString(backupRecordID)
 		if err != nil {
-			fmt.Println(err)
+			logging.Error(err.Error())
 		}
-		fmt.Println(fmt.Sprintf("flags:id:%s", id))
+		logging.Info(fmt.Sprintf("flags:id:%s", id))
 
-		fmt.Println("Restore...")
+		logging.Info("Restore...")
 	},
 }
 
diff --git a/pitr/cli/main.go b/pitr/cli/main.go
index 1d772f4..643fffa 100644
--- a/pitr/cli/main.go
+++ b/pitr/cli/main.go
@@ -20,11 +20,33 @@ package main
 import (
 	"fmt"
 
+	"go.uber.org/zap"
+	"go.uber.org/zap/zapcore"
+
 	"github.com/apache/shardingsphere-on-cloud/pitr/cli/internal/cmd"
+	"github.com/apache/shardingsphere-on-cloud/pitr/cli/pkg/logging"
 )
 
 func main() {
+	prodConfig := zap.NewProductionConfig()
+	prodConfig.Encoding = "console"
+	prodConfig.DisableCaller = true
+	prodConfig.DisableStacktrace = true
+	prodConfig.EncoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder
+	prodConfig.Level = zap.NewAtomicLevelAt(zapcore.InfoLevel)
+	prodConfig.EncoderConfig.ConsoleSeparator = "  "
+
+	logger, err := prodConfig.Build(
+		zap.WithCaller(false),
+		zap.AddCallerSkip(1),
+		zap.AddStacktrace(zapcore.FatalLevel),
+	)
+	if err != nil {
+		panic(fmt.Errorf("an unknown error occured in the zap-log"))
+	}
+	logging.Init(logger)
+
 	if err := cmd.Root.Execute(); err != nil {
-		fmt.Println(fmt.Sprintf("Err: %s", err))
+		logging.Error(fmt.Sprintf("Err: %s", err))
 	}
 }
diff --git a/pitr/cli/main.go b/pitr/cli/pkg/logging/field.go
similarity index 56%
copy from pitr/cli/main.go
copy to pitr/cli/pkg/logging/field.go
index 1d772f4..2119278 100644
--- a/pitr/cli/main.go
+++ b/pitr/cli/pkg/logging/field.go
@@ -15,16 +15,32 @@
 * limitations under the License.
  */
 
-package main
+package logging
 
-import (
-	"fmt"
+type ILog interface {
+	Field(k FieldKey, v string) ILog
+	Fields(m map[FieldKey]string) ILog
 
-	"github.com/apache/shardingsphere-on-cloud/pitr/cli/internal/cmd"
-)
+	Debug(s string)
+	Info(s string)
+	Warn(s string)
+	Error(s string)
+	Panic(s string)
+}
+
+type FieldKey string
 
-func main() {
-	if err := cmd.Root.Execute(); err != nil {
-		fmt.Println(fmt.Sprintf("Err: %s", err))
-	}
+func (f FieldKey) String() string {
+	return string(f)
 }
+
+const (
+	ErrorKey   FieldKey = "error"
+	RequestID  FieldKey = "requestID"
+	Stack      FieldKey = "stack"
+	Duration   FieldKey = "duration"
+	Path       FieldKey = "path"       // original routing path
+	RequestUri FieldKey = "requestUri" // http requesting uri
+	HttpMethod FieldKey = "httpMethod"
+	HttpStatus FieldKey = "httpStatus"
+)
diff --git a/pitr/cli/pkg/logging/log.go b/pitr/cli/pkg/logging/log.go
new file mode 100644
index 0000000..b2d2209
--- /dev/null
+++ b/pitr/cli/pkg/logging/log.go
@@ -0,0 +1,69 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package logging
+
+import "go.uber.org/zap"
+
+var l *ZapLogger
+
+func Log() ILog {
+	return l
+}
+
+func Init(logger *zap.Logger) ILog {
+	l = &ZapLogger{logger: logger}
+	return l
+}
+
+func Field(k FieldKey, v string) ILog {
+	m := map[FieldKey]string{k: v}
+	for k, v := range l.fields {
+		m[k] = v
+	}
+	return &ZapLogger{logger: l.logger, fields: m}
+}
+
+func Fields(m map[FieldKey]string) ILog {
+	if m == nil {
+		m = map[FieldKey]string{}
+	}
+	for k, v := range l.fields {
+		m[k] = v
+	}
+	return &ZapLogger{logger: l.logger, fields: m}
+}
+
+func Debug(s string) {
+	l.logger.Debug(s, fields(l)...)
+}
+
+func Info(s string) {
+	l.logger.Info(s, fields(l)...)
+}
+
+func Warn(s string) {
+	l.logger.Warn(s, fields(l)...)
+}
+
+func Error(s string) {
+	l.logger.Error(s, fields(l)...)
+}
+
+func Panic(s string) {
+	l.logger.Panic(s, fields(l)...)
+}
diff --git a/pitr/cli/pkg/logging/zap_log.go b/pitr/cli/pkg/logging/zap_log.go
new file mode 100644
index 0000000..cfda378
--- /dev/null
+++ b/pitr/cli/pkg/logging/zap_log.go
@@ -0,0 +1,82 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License.  You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package logging
+
+import (
+	"go.uber.org/zap"
+	"go.uber.org/zap/zapcore"
+)
+
+type ZapLogger struct {
+	fields map[FieldKey]string
+	logger *zap.Logger
+}
+
+func NewLog(l *zap.Logger) ILog {
+	return &ZapLogger{logger: l}
+}
+
+func (z *ZapLogger) Field(k FieldKey, v string) ILog {
+	m := map[FieldKey]string{k: v}
+	for k, v := range z.fields {
+		m[k] = v
+	}
+	return &ZapLogger{logger: z.logger, fields: m}
+}
+
+func (z *ZapLogger) Fields(m map[FieldKey]string) ILog {
+	if m == nil {
+		m = map[FieldKey]string{}
+	}
+	for k, v := range z.fields {
+		m[k] = v
+	}
+	return &ZapLogger{logger: z.logger, fields: m}
+}
+
+func (z *ZapLogger) Debug(s string) {
+	z.logger.Debug(s, fields(z)...)
+}
+
+func (z *ZapLogger) Info(s string) {
+	z.logger.Info(s, fields(z)...)
+}
+
+func (z *ZapLogger) Warn(s string) {
+	z.logger.Warn(s, fields(z)...)
+}
+
+func (z *ZapLogger) Error(s string) {
+	z.logger.Error(s, fields(z)...)
+}
+
+func (z *ZapLogger) Panic(s string) {
+	z.logger.Panic(s, fields(z)...)
+}
+
+func fields(z *ZapLogger) []zap.Field {
+	fields := make([]zap.Field, 0, len(z.fields))
+	for k, v := range z.fields {
+		fields = append(fields, zap.Field{
+			Key:    k.String(),
+			Type:   zapcore.StringType,
+			String: v,
+		})
+	}
+	return fields
+}