summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-01 18:53:41 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-01 18:53:41 -0400
commit100cd181bcc9fc46981cc2a4b88c05ad459fbc8f (patch)
tree2b2a8f07fa2760721e9418c39c51d751618ada5a /modules
parent03c2468c2fa68e5b3c5cb6c498a155e7d725ccdb (diff)
downloadgitea-100cd181bcc9fc46981cc2a4b88c05ad459fbc8f.tar.gz
gitea-100cd181bcc9fc46981cc2a4b88c05ad459fbc8f.zip
Add router log config option
Diffstat (limited to 'modules')
-rw-r--r--modules/base/conf.go2
-rw-r--r--modules/middleware/context.go14
-rw-r--r--modules/middleware/logger.go6
3 files changed, 19 insertions, 3 deletions
diff --git a/modules/base/conf.go b/modules/base/conf.go
index cfc85ff51e..23c7276bf1 100644
--- a/modules/base/conf.go
+++ b/modules/base/conf.go
@@ -50,6 +50,7 @@ var (
AppLogo string
AppUrl string
OfflineMode bool
+ RouterLog bool
ProdMode bool
Domain string
SecretKey string
@@ -327,6 +328,7 @@ func NewConfigContext() {
AppUrl = Cfg.MustValue("server", "ROOT_URL")
Domain = Cfg.MustValue("server", "DOMAIN")
OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
+ RouterLog = Cfg.MustBool("server", "ROUTER_LOG", true)
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
diff --git a/modules/middleware/context.go b/modules/middleware/context.go
index 1330172fde..31fdca681a 100644
--- a/modules/middleware/context.go
+++ b/modules/middleware/context.go
@@ -106,11 +106,19 @@ 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) {
- log.Error("%s: %v", title, err)
- if martini.Dev != martini.Prod {
- ctx.Data["ErrorMsg"] = err
+ if err != nil {
+ log.Error("%s: %v", title, err)
+ if martini.Dev != martini.Prod {
+ ctx.Data["ErrorMsg"] = err
+ }
}
+ switch status {
+ case 404:
+ ctx.Data["Title"] = "Page Not Found"
+ case 500:
+ ctx.Data["Title"] = "Internal Server Error"
+ }
ctx.HTML(status, fmt.Sprintf("status/%d", status))
}
diff --git a/modules/middleware/logger.go b/modules/middleware/logger.go
index fc8e1a8115..d815b90c26 100644
--- a/modules/middleware/logger.go
+++ b/modules/middleware/logger.go
@@ -12,6 +12,8 @@ import (
"time"
"github.com/go-martini/martini"
+
+ "github.com/gogits/gogs/modules/base"
)
var isWindows bool
@@ -22,6 +24,10 @@ func init() {
func Logger() martini.Handler {
return func(res http.ResponseWriter, req *http.Request, ctx martini.Context, log *log.Logger) {
+ if !base.RouterLog {
+ return
+ }
+
start := time.Now()
log.Printf("Started %s %s", req.Method, req.URL.Path)