Skip to content

Commit

Permalink
Merge pull request #122 from LucienShui/chore/change_error_log
Browse files Browse the repository at this point in the history
Chore/change error log
  • Loading branch information
LucienShui authored Oct 6, 2021
2 parents 6087d98 + 53b71a3 commit 0d54ca2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ func load(filename string) {
logging.Panic(
"open file failed",
zap.String("pwd", pwd),
zap.String("err", err.Error()),
zap.Error(err),
)
}

err = json.Unmarshal(data, &Config)
if err != nil {
logging.Panic("parse Config failed", zap.String("err", err.Error()))
logging.Panic("parse Config failed", zap.Error(err))
}

exportConfig(filename, Config)
Expand Down
8 changes: 4 additions & 4 deletions handler/paste/paste.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ func Create(context *gin.Context) {
}

if err := context.ShouldBindJSON(&body); err != nil {
logging.Warn("bind body failed", context, zap.String("err", err.Error()))
logging.Warn("bind body failed", context, zap.Error(err))
common.ErrWrongParamType.Abort(context)
return
}

if err := validator(body); err != nil {
logging.Info("param validate failed", zap.String("err", err.Error()))
logging.Info("param validate failed", zap.Error(err))
err.Abort(context)
return
}
Expand All @@ -64,7 +64,7 @@ func Create(context *gin.Context) {
}

if err := paste.Save(); err != nil {
logging.Error("save failed", context, zap.String("err", err.Error()))
logging.Error("save failed", context, zap.Error(err))
common.ErrSaveFailed.Abort(context)
return
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func Get(context *gin.Context) {
case common.ErrWrongPassword:
errorResponse = err.(*common.ErrorResponse)
default:
logging.Error("query from db failed", context, zap.String("err", err.Error()))
logging.Error("query from db failed", context, zap.Error(err))
errorResponse = common.ErrQueryDBFailed
}

Expand Down
2 changes: 1 addition & 1 deletion handler/token/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ func init() {
}

if err = AuthMiddleware.MiddlewareInit(); err != nil {
logging.Panic("jwt middleware init failed", zap.String("err", err.Error()))
logging.Panic("jwt middleware init failed", zap.Error(err))
}
}
6 changes: 3 additions & 3 deletions model/dao/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func init() {
pwd, _ := os.Getwd()
logging.Info("using sqlite", zap.String("database_type", config.Config.Database.Type), zap.String("work_dir", pwd))
if DB, err = gorm.Open(sqlite.Open(sqlitePath), gormConfig); err != nil {
logging.Panic("sqlite connect failed", zap.String("sqlite_path", sqlitePath), zap.String("err", err.Error()))
logging.Panic("sqlite connect failed", zap.String("sqlite_path", sqlitePath), zap.Error(err))
return
}
logging.Info("sqlite connect success", zap.String("sqlite_path", sqlitePath))
} else {
if DB, err = gorm.Open(mysql.Open(formatWithConfig(config.Config.Database))); err != nil {
logging.Panic("connect to mysql failed", zap.String("err", err.Error()))
logging.Panic("connect to mysql failed", zap.Error(err))
return
}
logging.Info("mysql connected")
Expand Down Expand Up @@ -83,7 +83,7 @@ func CreateTable(object interface{}) {
logging.Warn("Table not found, start creating", tableName)

if err := migrator.CreateTable(object); err != nil {
logging.Panic("Create table failed", tableName, zap.String("err", err.Error()))
logging.Panic("Create table failed", tableName, zap.Error(err))
}
}
}
2 changes: 1 addition & 1 deletion router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ func init() {

func Run(address string, port uint16) {
if err := router.Run(fmt.Sprintf("%s:%d", address, port)); err != nil {
logging.Panic("Run server failed", zap.String("err", err.Error()))
logging.Panic("Run server failed", zap.Error(err))
}
}

0 comments on commit 0d54ca2

Please sign in to comment.