Add some log

This commit is contained in:
Unknown 2014-03-19 04:48:45 -04:00
parent b192b70aec
commit bd9d90d8c4
6 changed files with 22 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import (
"os/exec" "os/exec"
"path" "path"
"path/filepath" "path/filepath"
"strings"
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/Unknwon/goconfig" "github.com/Unknwon/goconfig"
@ -63,9 +64,10 @@ func newLogService() {
} }
// Log level. // Log level.
level, ok := logLevels[Cfg.MustValue("log."+mode, "LEVEL", "Trace")] levelName := Cfg.MustValue("log."+mode, "LEVEL", "Trace")
level, ok := logLevels[levelName]
if !ok { if !ok {
fmt.Printf("Unknown log level: %s\n", Cfg.MustValue("log."+mode, "LEVEL", "Trace")) fmt.Printf("Unknown log level: %s\n", levelName)
os.Exit(2) os.Exit(2)
} }
@ -99,6 +101,7 @@ func newLogService() {
} }
log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), mode, config) log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), mode, config)
log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName)
} }
func newMailService() { func newMailService() {

View File

@ -67,8 +67,13 @@ func (ctx *Context) RenderWithErr(msg, tpl string, form auth.Form) {
// Handle handles and logs error by given status. // Handle handles and logs error by given status.
func (ctx *Context) Handle(status int, title string, err error) { func (ctx *Context) Handle(status int, title string, err error) {
ctx.Data["ErrorMsg"] = err
log.Error("%s: %v", title, err) log.Error("%s: %v", title, err)
if martini.Dev == martini.Prod {
ctx.Render.HTML(500, "status/500", ctx.Data)
return
}
ctx.Data["ErrorMsg"] = err
ctx.Render.HTML(status, fmt.Sprintf("status/%d", status), ctx.Data) ctx.Render.HTML(status, fmt.Sprintf("status/%d", status), ctx.Data)
} }

View File

@ -7,6 +7,7 @@ package repo
import ( import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
) )
@ -23,6 +24,7 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
_, err := models.CreateRepository(ctx.User, form.RepoName, form.Description, _, err := models.CreateRepository(ctx.User, form.RepoName, form.Description,
form.Language, form.License, form.Visibility == "private", form.InitReadme == "on") form.Language, form.License, form.Visibility == "private", form.InitReadme == "on")
if err == nil { if err == nil {
log.Trace("%s Repository created: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, form.RepoName)
ctx.Render.Redirect("/"+ctx.User.Name+"/"+form.RepoName, 302) ctx.Render.Redirect("/"+ctx.User.Name+"/"+form.RepoName, 302)
return return
} else if err == models.ErrRepoAlreadyExist { } else if err == models.ErrRepoAlreadyExist {
@ -48,6 +50,7 @@ func SettingPost(ctx *middleware.Context) {
if err := models.DeleteRepository(ctx.User.Id, ctx.Repo.Repository.Id, ctx.User.LowerName); err != nil { if err := models.DeleteRepository(ctx.User.Id, ctx.Repo.Repository.Id, ctx.User.LowerName); err != nil {
ctx.Handle(200, "repo.Delete", err) ctx.Handle(200, "repo.Delete", err)
log.Trace("%s Repository deleted: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.Repo.Repository.LowerName)
return return
} }
} }

View File

@ -46,6 +46,7 @@ func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) {
ctx.Data["IsSuccess"] = true ctx.Data["IsSuccess"] = true
ctx.Render.HTML(200, "user/setting", ctx.Data) ctx.Render.HTML(200, "user/setting", ctx.Data)
log.Trace("%s User setting updated: %s", ctx.Req.RequestURI, ctx.User.LowerName)
} }
func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) { func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) {
@ -82,6 +83,7 @@ func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) {
ctx.Data["Owner"] = user ctx.Data["Owner"] = user
ctx.Render.HTML(200, "user/password", ctx.Data) ctx.Render.HTML(200, "user/password", ctx.Data)
log.Trace("%s User password updated: %s", ctx.Req.RequestURI, ctx.User.LowerName)
} }
func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) { func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
@ -112,6 +114,7 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
"err": err.Error(), "err": err.Error(),
}) })
} else { } else {
log.Trace("%s User SSH key deleted: %s", ctx.Req.RequestURI, ctx.User.LowerName)
ctx.Render.JSON(200, map[string]interface{}{ ctx.Render.JSON(200, map[string]interface{}{
"ok": true, "ok": true,
}) })
@ -137,6 +140,7 @@ func SettingSSHKeys(ctx *middleware.Context, form auth.AddSSHKeyForm) {
return return
} }
ctx.Handle(200, "ssh.AddPublicKey", err) ctx.Handle(200, "ssh.AddPublicKey", err)
log.Trace("%s User SSH key added: %s", ctx.Req.RequestURI, ctx.User.LowerName)
return return
} else { } else {
ctx.Data["AddSSHKeySuccess"] = true ctx.Data["AddSSHKeySuccess"] = true

View File

@ -6,6 +6,7 @@ package user
import ( import (
"fmt" "fmt"
"strings"
"github.com/codegangsta/martini" "github.com/codegangsta/martini"
"github.com/martini-contrib/render" "github.com/martini-contrib/render"
@ -14,6 +15,7 @@ import (
"github.com/gogits/gogs/models" "github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware"
) )
@ -146,6 +148,7 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) {
return return
} }
log.Trace("%s User created: %s", ctx.Req.RequestURI, strings.ToLower(form.UserName))
ctx.Render.Redirect("/user/login") ctx.Render.Redirect("/user/login")
} }

2
web.go
View File

@ -47,8 +47,8 @@ func checkRunMode() {
} }
func runWeb(*cli.Context) { func runWeb(*cli.Context) {
log.Info("%s %s", base.AppName, base.AppVer)
checkRunMode() checkRunMode()
log.Info("%s %s", base.AppName, base.AppVer)
m := martini.Classic() m := martini.Classic()