forked from forgejo/forgejo
Add some log
This commit is contained in:
parent
b192b70aec
commit
bd9d90d8c4
6 changed files with 22 additions and 4 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
"github.com/Unknwon/goconfig"
|
||||
|
@ -63,9 +64,10 @@ func newLogService() {
|
|||
}
|
||||
|
||||
// Log level.
|
||||
level, ok := logLevels[Cfg.MustValue("log."+mode, "LEVEL", "Trace")]
|
||||
levelName := Cfg.MustValue("log."+mode, "LEVEL", "Trace")
|
||||
level, ok := logLevels[levelName]
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -99,6 +101,7 @@ func newLogService() {
|
|||
}
|
||||
|
||||
log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), mode, config)
|
||||
log.Info("Log Mode: %s(%s)", strings.Title(mode), levelName)
|
||||
}
|
||||
|
||||
func newMailService() {
|
||||
|
|
|
@ -67,8 +67,13 @@ func (ctx *Context) RenderWithErr(msg, tpl string, form auth.Form) {
|
|||
|
||||
// Handle handles and logs error by given status.
|
||||
func (ctx *Context) Handle(status int, title string, err error) {
|
||||
ctx.Data["ErrorMsg"] = 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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue