From 508bf37424befdb2ac80c078deebeb6180ca1d7b Mon Sep 17 00:00:00 2001 From: alanwooo Date: Wed, 30 Mar 2016 20:49:43 +0800 Subject: [PATCH] Replace the beego log module with the new logger for the files under the controllers directory --- controllers/base.go | 6 +++--- controllers/itemdetail.go | 11 +++++------ controllers/login.go | 5 ++--- controllers/password.go | 33 +++++++++++++++++---------------- controllers/register.go | 7 +++---- 5 files changed, 30 insertions(+), 32 deletions(-) diff --git a/controllers/base.go b/controllers/base.go index 836aa13..58df9a3 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -16,10 +16,10 @@ package controllers import ( - "log" "os" "strings" + "github.com/vmware/harbor/utils/log" "github.com/astaxie/beego" "github.com/beego/i18n" ) @@ -127,7 +127,7 @@ func init() { log.Printf("Config path: %s", configPath) beego.AppConfigPath = configPath if err := beego.ParseConfig(); err != nil { - beego.Warning("Failed to parse config file: ", configPath, "error: ", err) + log.Warningf("Failed to parse config file: %s, error: %v", configPath, err) } } @@ -150,7 +150,7 @@ func init() { for _, lang := range langs { if err := i18n.SetMessage(lang, "static/i18n/"+"locale_"+lang+".ini"); err != nil { - beego.Error("Fail to set message file:" + err.Error()) + log.Errorf("Fail to set message file: %s", err.Error()) } } } diff --git a/controllers/itemdetail.go b/controllers/itemdetail.go index e13fe14..8950834 100644 --- a/controllers/itemdetail.go +++ b/controllers/itemdetail.go @@ -21,8 +21,7 @@ import ( "os" "github.com/vmware/harbor/dao" - - "github.com/astaxie/beego" + "github.com/vmware/harbor/utils/log" ) // ItemDetailController handles requet to /registry/detail, which shows the detail of a project. @@ -37,7 +36,7 @@ func (idc *ItemDetailController) Get() { projectID, _ := idc.GetInt64("project_id") if projectID <= 0 { - beego.Error("Invalid project id:", projectID) + log.Errorf("Invalid project id: %d", projectID) idc.Redirect("/signIn", http.StatusFound) return } @@ -45,7 +44,7 @@ func (idc *ItemDetailController) Get() { project, err := dao.GetProjectByID(projectID) if err != nil { - beego.Error("Error occurred in GetProjectById:", err) + log.Errorf("Error occurred in GetProjectById: %v", err) idc.CustomAbort(http.StatusInternalServerError, "Internal error.") } @@ -70,13 +69,13 @@ func (idc *ItemDetailController) Get() { roleList, err := dao.GetUserProjectRoles(userID, projectID) if err != nil { - beego.Error("Error occurred in GetUserProjectRoles:", err) + log.Errorf("Error occurred in GetUserProjectRoles: %v", err) idc.CustomAbort(http.StatusInternalServerError, "Internal error.") } isAdmin, err := dao.IsAdminRole(userID) if err != nil { - beego.Error("Error occurred in IsAdminRole:", err) + log.Errorf("Error occurred in IsAdminRole: %v", err) idc.CustomAbort(http.StatusInternalServerError, "Internal error.") } diff --git a/controllers/login.go b/controllers/login.go index 70068de..b35b0ae 100644 --- a/controllers/login.go +++ b/controllers/login.go @@ -20,8 +20,7 @@ import ( "github.com/vmware/harbor/auth" "github.com/vmware/harbor/models" - - "github.com/astaxie/beego" + "github.com/vmware/harbor/utils/log" ) // IndexController handles request to / @@ -52,7 +51,7 @@ func (c *CommonController) Login() { user, err := auth.Login(models.AuthModel{principal, password}) if err != nil { - beego.Error("Error occurred in UserLogin:", err) + log.Errorf("Error occurred in UserLogin: %v", err) c.CustomAbort(http.StatusUnauthorized, "") } diff --git a/controllers/password.go b/controllers/password.go index 9929c4f..3d569b6 100644 --- a/controllers/password.go +++ b/controllers/password.go @@ -25,6 +25,7 @@ import ( "github.com/vmware/harbor/dao" "github.com/vmware/harbor/models" "github.com/vmware/harbor/utils" + "github.com/vmware/harbor/utils/log" "github.com/astaxie/beego" ) @@ -51,25 +52,25 @@ func (cc *CommonController) UpdatePassword() { sessionUserID := cc.GetSession("userId") if sessionUserID == nil { - beego.Warning("User does not login.") + log.Warning("User does not login.") cc.CustomAbort(http.StatusUnauthorized, "please_login_first") } oldPassword := cc.GetString("old_password") if oldPassword == "" { - beego.Error("Old password is blank") + log.Error("Old password is blank") cc.CustomAbort(http.StatusBadRequest, "Old password is blank") } queryUser := models.User{UserID: sessionUserID.(int), Password: oldPassword} user, err := dao.CheckUserPassword(queryUser) if err != nil { - beego.Error("Error occurred in CheckUserPassword:", err) + log.Errorf("Error occurred in CheckUserPassword: %v", err) cc.CustomAbort(http.StatusInternalServerError, "Internal error.") } if user == nil { - beego.Warning("Password input is not correct") + log.Warning("Password input is not correct") cc.CustomAbort(http.StatusForbidden, "old_password_is_not_correct") } @@ -78,7 +79,7 @@ func (cc *CommonController) UpdatePassword() { updateUser := models.User{UserID: sessionUserID.(int), Password: password, Salt: user.Salt} err = dao.ChangeUserPassword(updateUser, oldPassword) if err != nil { - beego.Error("Error occurred in ChangeUserPassword:", err) + log.Errorf("Error occurred in ChangeUserPassword: %v", err) cc.CustomAbort(http.StatusInternalServerError, "Internal error.") } } else { @@ -116,7 +117,7 @@ func (cc *CommonController) SendEmail() { queryUser := models.User{Email: email} exist, err := dao.UserExists(queryUser, "email") if err != nil { - beego.Error("Error occurred in UserExists:", err) + log.Errorf("Error occurred in UserExists: %v", err) cc.CustomAbort(http.StatusInternalServerError, "Internal error.") } if !exist { @@ -125,7 +126,7 @@ func (cc *CommonController) SendEmail() { messageTemplate, err := template.ParseFiles("views/reset-password-mail.tpl") if err != nil { - beego.Error("Parse email template file failed:", err) + log.Errorf("Parse email template file failed: %v", err) cc.CustomAbort(http.StatusInternalServerError, err.Error()) } @@ -137,7 +138,7 @@ func (cc *CommonController) SendEmail() { } uuid, err := dao.GenerateRandomString() if err != nil { - beego.Error("Error occurred in GenerateRandomString:", err) + log.Errorf("Error occurred in GenerateRandomString: %v", err) cc.CustomAbort(http.StatusInternalServerError, "Internal error.") } err = messageTemplate.Execute(message, messageDetail{ @@ -147,13 +148,13 @@ func (cc *CommonController) SendEmail() { }) if err != nil { - beego.Error("message template error:", err) + log.Errorf("Message template error: %v", err) cc.CustomAbort(http.StatusInternalServerError, "internal_error") } config, err := beego.AppConfig.GetSection("mail") if err != nil { - beego.Error("Can not load app.conf:", err) + log.Errorf("Can not load app.conf: %v", err) cc.CustomAbort(http.StatusInternalServerError, "internal_error") } @@ -166,7 +167,7 @@ func (cc *CommonController) SendEmail() { err = mail.SendMail() if err != nil { - beego.Error("send email failed:", err) + log.Errorf("Send email failed: %v", err) cc.CustomAbort(http.StatusInternalServerError, "send_email_failed") } @@ -187,7 +188,7 @@ func (rpc *ResetPasswordController) Get() { resetUUID := rpc.GetString("reset_uuid") if resetUUID == "" { - beego.Error("Reset uuid is blank.") + log.Error("Reset uuid is blank.") rpc.Redirect("/", http.StatusFound) return } @@ -195,7 +196,7 @@ func (rpc *ResetPasswordController) Get() { queryUser := models.User{ResetUUID: resetUUID} user, err := dao.GetUser(queryUser) if err != nil { - beego.Error("Error occurred in GetUser:", err) + log.Errorf("Error occurred in GetUser: %v", err) rpc.CustomAbort(http.StatusInternalServerError, "Internal error.") } @@ -218,11 +219,11 @@ func (cc *CommonController) ResetPassword() { queryUser := models.User{ResetUUID: resetUUID} user, err := dao.GetUser(queryUser) if err != nil { - beego.Error("Error occurred in GetUser:", err) + log.Errorf("Error occurred in GetUser: %v", err) cc.CustomAbort(http.StatusInternalServerError, "Internal error.") } if user == nil { - beego.Error("User does not exist") + log.Error("User does not exist") cc.CustomAbort(http.StatusBadRequest, "User does not exist") } @@ -232,7 +233,7 @@ func (cc *CommonController) ResetPassword() { user.Password = password err = dao.ResetUserPassword(*user) if err != nil { - beego.Error("Error occurred in ResetUserPassword:", err) + log.Errorf("Error occurred in ResetUserPassword: %v", err) cc.CustomAbort(http.StatusInternalServerError, "Internal error.") } } else { diff --git a/controllers/register.go b/controllers/register.go index 1058197..466f4e4 100644 --- a/controllers/register.go +++ b/controllers/register.go @@ -22,8 +22,7 @@ import ( "github.com/vmware/harbor/dao" "github.com/vmware/harbor/models" - - "github.com/astaxie/beego" + "github.com/vmware/harbor/utils/log" ) // RegisterController handles request to /register @@ -53,7 +52,7 @@ func (rc *CommonController) SignUp() { _, err := dao.Register(user) if err != nil { - beego.Error("Error occurred in Register:", err) + log.Errorf("Error occurred in Register: %v", err) rc.CustomAbort(http.StatusInternalServerError, "Internal error.") } } @@ -73,7 +72,7 @@ func (rc *CommonController) UserExists() { exist, err := dao.UserExists(user, target) if err != nil { - beego.Error("Error occurred in UserExists:", err) + log.Errorf("Error occurred in UserExists: %v", err) rc.CustomAbort(http.StatusInternalServerError, "Internal error.") } rc.Data["json"] = exist