Skip to content

Commit

Permalink
Change Echo logger to Zap logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ybkuroki committed Oct 4, 2020
1 parent a895f57 commit 3ecf841
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 48 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ require (
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/stretchr/testify v1.6.1
github.com/valyala/fasttemplate v1.1.1 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
Expand Down
29 changes: 29 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
Expand All @@ -58,8 +59,12 @@ github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/labstack/echo-contrib v0.9.0 h1:hKBA2SnxdxR7sghH0J04zq/pImnKRmgvmQ6MvY9hug4=
github.com/labstack/echo-contrib v0.9.0/go.mod h1:TsFE5Vv0LRpZLoh4mMmaaAxzcTH+1CBFiUtVhwlegzU=
github.com/labstack/echo/v4 v4.1.6/go.mod h1:kU/7PwzgNxZH4das4XNsSpBSOD09XIF5YEPzjpkGnGE=
Expand Down Expand Up @@ -108,6 +113,7 @@ github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -129,21 +135,36 @@ github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPU
github.com/valyala/fasttemplate v1.1.1 h1:o7HedfIt0u4jgkQnk0jkUOUI45c0CbFgcOOVUpo/txI=
github.com/valyala/fasttemplate v1.1.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
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/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw=
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190607181551-461777fb6f67/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
Expand Down Expand Up @@ -172,14 +193,21 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190608022120-eacb66d2a7c3/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/boj/redistore.v1 v1.0.0-20160128113310-fc113767cd6b h1:U/Uqd1232+wrnHOvWNaxrNqn/kFnr4yu4blgPtQt0N8=
gopkg.in/boj/redistore.v1 v1.0.0-20160128113310-fc113767cd6b/go.mod h1:fgfIZMlsafAHpspcks2Bul+MWUNw/2dyQmjC2faKjtg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M=
Expand All @@ -192,3 +220,4 @@ gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
70 changes: 35 additions & 35 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,78 @@ package logger
import (
"database/sql/driver"
"fmt"
"io"
"os"
"reflect"
"regexp"
"strings"
"time"
"unicode"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/ybkuroki/go-webapp-sample/config"
"go.uber.org/zap"
)

var logger *Logger

// Logger is an alternative implementation of *gorm.Logger
type Logger struct {
elogger echo.Logger
zap *zap.SugaredLogger
}

// GetLogger is return Logger
func GetLogger() *Logger {
return logger
}

// GetEchoLogger is return echo's logger
func GetEchoLogger() echo.Logger {
return logger.elogger
// GetZapLogger returns zapSugaredLogger
func GetZapLogger() *zap.SugaredLogger {
return logger.zap
}

// NewLogger create logger object for *gorm.DB from *echo.Logger
func newLogger(elog echo.Logger) *Logger {
return &Logger{elogger: elog}
// newLogger create logger object for *gorm.DB from *echo.Logger
func newLogger(zap *zap.SugaredLogger) *Logger {
return &Logger{zap: zap}
}

// InitLogger initialize logger.
func InitLogger(e *echo.Echo, config *config.Config) {
// logging for each request.
e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{
Format: strings.Replace(config.Log.Format, "${level}", "INFO", 1) + "\n",
}))
zap, err := zap.NewDevelopment()
if err != nil {
fmt.Printf("Error")
}
defer zap.Sync()
sugar := zap.Sugar()
// set package varriable logger.
logger = newLogger(sugar)

e.Use(RequestLoggerMiddleware)

// logging for the start and end of controller processes.
// ref: https://echo.labstack.com/guide/customization
e.Use(MyLoggerMiddleware)

// set logformat for echo logger.
e.Logger.SetHeader(config.Log.Format)
e.Logger.SetLevel(config.Log.Level)
e.Use(ActionLoggerMiddleware)
}

// if the log file exists, write both console and the log file.
if config.Log.FilePath != "" {
logfile, err := os.OpenFile(config.Log.FilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 066)
if err != nil {
panic("Cannot open the log file. Please check this file path. Path: " + config.Log.FilePath + ", Error: " + err.Error())
// RequestLoggerMiddleware is middleware for logging the contents of requests.
func RequestLoggerMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
req := c.Request()
res := c.Response()
if err := next(c); err != nil {
c.Error(err)
}

e.Logger.SetOutput(io.MultiWriter(logfile, os.Stdout))
GetZapLogger().Infof("Uri: %s, Method: %s, Status: %d", req.RequestURI, req.Method, res.Status)
return nil
}

// set package varriable logger.
logger = newLogger(e.Logger)
}

// MyLoggerMiddleware is middleware for logging the start and end of controller processes.
// ActionLoggerMiddleware is middleware for logging the start and end of controller processes.
// ref: https://echo.labstack.com/cookbook/middleware
func MyLoggerMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
func ActionLoggerMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Logger().Debug(c.Path() + " Action Start")
GetZapLogger().Debug(c.Path() + " Action Start")
if err := next(c); err != nil {
c.Error(err)
}
c.Logger().Debug(c.Path() + " Action End")
GetZapLogger().Debugf(c.Path() + " Action End")
return nil
}
}
Expand All @@ -94,7 +94,7 @@ func (l *Logger) Print(values ...interface{}) {
func (l *Logger) Println(values []interface{}) {
sql := createLog(values)
if sql != "" {
l.elogger.Debug(sql)
l.zap.Debugf(sql)
}
}

Expand Down
6 changes: 3 additions & 3 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func getConnection(config *config.Config) string {

// InitDB initialize a database connection.
func InitDB() {
logger.GetEchoLogger().Info("Try database connection")
logger.GetZapLogger().Infof("Try database connection")
conf := config.GetConfig()
db, err := gorm.Open(conf.Database.Dialect, getConnection(conf))
if err != nil {
logger.GetEchoLogger().Error("Failure database connection")
logger.GetZapLogger().Errorf("Failure database connection")
}
logger.GetEchoLogger().Info(fmt.Sprintf("Success database connection, %s:%s", conf.Database.Host, conf.Database.Port))
logger.GetZapLogger().Infof("Success database connection, %s:%s", conf.Database.Host, conf.Database.Port)
db.LogMode(true)
db.SetLogger(logger.GetLogger())
rep = &Repository{}
Expand Down
4 changes: 2 additions & 2 deletions service/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func AuthenticateByUsernameAndPassword(username string, password string) (bool,
account := model.Account{}
result, err := account.FindByName(rep, username)
if err != nil {
logger.GetEchoLogger().Error(err)
logger.GetZapLogger().Errorf(err.Error())
return false, nil
}

if err := bcrypt.CompareHashAndPassword([]byte(result.Password), []byte(password)); err != nil {
logger.GetEchoLogger().Error(err)
logger.GetZapLogger().Errorf(err.Error())
return false, nil
}

Expand Down
12 changes: 6 additions & 6 deletions service/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func FindAllBooks() *[]model.Book {
book := model.Book{}
result, err := book.FindAll(rep)
if err != nil {
logger.GetEchoLogger().Error(err.Error)
logger.GetZapLogger().Errorf(err.Error())
return nil
}
return result
Expand All @@ -25,7 +25,7 @@ func FindAllBooksByPage(page int, size int) *model.Page {
book := model.Book{}
result, err := book.FindAllByPage(rep, page, size)
if err != nil {
logger.GetEchoLogger().Error(err.Error)
logger.GetZapLogger().Errorf(err.Error())
return nil
}
return result
Expand All @@ -37,7 +37,7 @@ func FindBooksByTitle(title string, page int, size int) *model.Page {
book := model.Book{}
result, err := book.FindByTitle(rep, title, page, size)
if err != nil {
logger.GetEchoLogger().Error(err.Error)
logger.GetZapLogger().Errorf(err.Error())
return nil
}
return result
Expand Down Expand Up @@ -73,7 +73,7 @@ func RegisterBook(dto *dto.RegBookDto) (*model.Book, map[string]string) {
})

if err != nil {
logger.GetEchoLogger().Error(err)
logger.GetZapLogger().Errorf(err.Error())
return nil, map[string]string{"error": "transaction error"}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ func EditBook(dto *dto.ChgBookDto) (*model.Book, map[string]string) {
})

if err != nil {
logger.GetEchoLogger().Error(err)
logger.GetZapLogger().Errorf(err.Error())
return nil, map[string]string{"error": "transaction error"}
}

Expand Down Expand Up @@ -158,7 +158,7 @@ func DeleteBook(dto *dto.ChgBookDto) (*model.Book, map[string]string) {
})

if err != nil {
logger.GetEchoLogger().Error(err)
logger.GetZapLogger().Errorf(err.Error())
return nil, map[string]string{"error": "transaction error"}
}

Expand Down
4 changes: 2 additions & 2 deletions service/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func FindAllCategories() *[]model.Category {
category := model.Category{}
result, err := category.FindAll(rep)
if err != nil {
logger.GetEchoLogger().Error(err.Error)
logger.GetZapLogger().Errorf(err.Error())
return nil
}
return result
Expand All @@ -24,7 +24,7 @@ func FindAllFormats() *[]model.Format {
format := model.Format{}
result, err := format.FindAll(rep)
if err != nil {
logger.GetEchoLogger().Error(err.Error)
logger.GetZapLogger().Errorf(err.Error())
return nil
}
return result
Expand Down

0 comments on commit 3ecf841

Please sign in to comment.