Add router log config option
parent
03c2468c2f
commit
100cd181bc
|
@ -15,9 +15,12 @@ LICENSES = Apache v2 License|GPL v2|MIT License|Affero GPL|Artistic License 2.0|
|
||||||
[server]
|
[server]
|
||||||
PROTOCOL = http
|
PROTOCOL = http
|
||||||
DOMAIN = localhost
|
DOMAIN = localhost
|
||||||
ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:3000/
|
ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/
|
||||||
|
HTTP_ADDR =
|
||||||
|
HTTP_PORT = 3000
|
||||||
; Disable CDN even in "prod" mode
|
; Disable CDN even in "prod" mode
|
||||||
OFFLINE_MODE = false
|
OFFLINE_MODE = false
|
||||||
|
ROUTER_LOG = true
|
||||||
; Generate steps:
|
; Generate steps:
|
||||||
; $ cd path/to/gogs/custom/https
|
; $ cd path/to/gogs/custom/https
|
||||||
; $ go run $GOROOT/src/pkg/crypto/tls/generate_cert.go -ca=true -duration=8760h0m0s -host=myhost.example.com
|
; $ go run $GOROOT/src/pkg/crypto/tls/generate_cert.go -ca=true -duration=8760h0m0s -host=myhost.example.com
|
||||||
|
|
|
@ -58,10 +58,10 @@ func NewTestEngine(x *xorm.Engine) (err error) {
|
||||||
case "postgres":
|
case "postgres":
|
||||||
var host, port = "127.0.0.1", "5432"
|
var host, port = "127.0.0.1", "5432"
|
||||||
fields := strings.Split(DbCfg.Host, ":")
|
fields := strings.Split(DbCfg.Host, ":")
|
||||||
if len(fields) > 0 {
|
if len(fields) > 0 && len(strings.TrimSpace(fields[0])) > 0 {
|
||||||
host = fields[0]
|
host = fields[0]
|
||||||
}
|
}
|
||||||
if len(fields) > 1 {
|
if len(fields) > 1 && len(strings.TrimSpace(fields[1])) > 0 {
|
||||||
port = fields[1]
|
port = fields[1]
|
||||||
}
|
}
|
||||||
cnnstr := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s",
|
cnnstr := fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s",
|
||||||
|
@ -91,10 +91,10 @@ func SetEngine() (err error) {
|
||||||
case "postgres":
|
case "postgres":
|
||||||
var host, port = "127.0.0.1", "5432"
|
var host, port = "127.0.0.1", "5432"
|
||||||
fields := strings.Split(DbCfg.Host, ":")
|
fields := strings.Split(DbCfg.Host, ":")
|
||||||
if len(fields) > 0 {
|
if len(fields) > 0 && len(strings.TrimSpace(fields[0])) > 0 {
|
||||||
host = fields[0]
|
host = fields[0]
|
||||||
}
|
}
|
||||||
if len(fields) > 1 {
|
if len(fields) > 1 && len(strings.TrimSpace(fields[1])) > 0 {
|
||||||
port = fields[1]
|
port = fields[1]
|
||||||
}
|
}
|
||||||
orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s",
|
orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s host=%s port=%s dbname=%s sslmode=%s",
|
||||||
|
|
|
@ -50,6 +50,7 @@ var (
|
||||||
AppLogo string
|
AppLogo string
|
||||||
AppUrl string
|
AppUrl string
|
||||||
OfflineMode bool
|
OfflineMode bool
|
||||||
|
RouterLog bool
|
||||||
ProdMode bool
|
ProdMode bool
|
||||||
Domain string
|
Domain string
|
||||||
SecretKey string
|
SecretKey string
|
||||||
|
@ -327,6 +328,7 @@ func NewConfigContext() {
|
||||||
AppUrl = Cfg.MustValue("server", "ROOT_URL")
|
AppUrl = Cfg.MustValue("server", "ROOT_URL")
|
||||||
Domain = Cfg.MustValue("server", "DOMAIN")
|
Domain = Cfg.MustValue("server", "DOMAIN")
|
||||||
OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
|
OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
|
||||||
|
RouterLog = Cfg.MustBool("server", "ROUTER_LOG", true)
|
||||||
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
|
SecretKey = Cfg.MustValue("security", "SECRET_KEY")
|
||||||
|
|
||||||
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
|
InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)
|
||||||
|
|
|
@ -106,11 +106,19 @@ 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) {
|
||||||
|
if err != nil {
|
||||||
log.Error("%s: %v", title, err)
|
log.Error("%s: %v", title, err)
|
||||||
if martini.Dev != martini.Prod {
|
if martini.Dev != martini.Prod {
|
||||||
ctx.Data["ErrorMsg"] = err
|
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))
|
ctx.HTML(status, fmt.Sprintf("status/%d", status))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-martini/martini"
|
"github.com/go-martini/martini"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/modules/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
var isWindows bool
|
var isWindows bool
|
||||||
|
@ -22,6 +24,10 @@ func init() {
|
||||||
|
|
||||||
func Logger() martini.Handler {
|
func Logger() martini.Handler {
|
||||||
return func(res http.ResponseWriter, req *http.Request, ctx martini.Context, log *log.Logger) {
|
return func(res http.ResponseWriter, req *http.Request, ctx martini.Context, log *log.Logger) {
|
||||||
|
if !base.RouterLog {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Printf("Started %s %s", req.Method, req.URL.Path)
|
log.Printf("Started %s %s", req.Method, req.URL.Path)
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,7 @@ func Config(ctx *middleware.Context) {
|
||||||
ctx.Data["AppUrl"] = base.AppUrl
|
ctx.Data["AppUrl"] = base.AppUrl
|
||||||
ctx.Data["Domain"] = base.Domain
|
ctx.Data["Domain"] = base.Domain
|
||||||
ctx.Data["OfflineMode"] = base.OfflineMode
|
ctx.Data["OfflineMode"] = base.OfflineMode
|
||||||
|
ctx.Data["RouterLog"] = base.RouterLog
|
||||||
ctx.Data["RunUser"] = base.RunUser
|
ctx.Data["RunUser"] = base.RunUser
|
||||||
ctx.Data["RunMode"] = strings.Title(martini.Env)
|
ctx.Data["RunMode"] = strings.Title(martini.Env)
|
||||||
ctx.Data["RepoRootPath"] = base.RepoRootPath
|
ctx.Data["RepoRootPath"] = base.RepoRootPath
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
<dd>{{.Domain}}</dd>
|
<dd>{{.Domain}}</dd>
|
||||||
<dt>Offline Mode</dt>
|
<dt>Offline Mode</dt>
|
||||||
<dd><i class="fa fa{{if .OfflineMode}}-check{{end}}-square-o"></i></dd>
|
<dd><i class="fa fa{{if .OfflineMode}}-check{{end}}-square-o"></i></dd>
|
||||||
|
<dt>Router Log</dt>
|
||||||
|
<dd><i class="fa fa{{if .RouterLog}}-check{{end}}-square-o"></i></dd>
|
||||||
<hr/>
|
<hr/>
|
||||||
<dt>Run User</dt>
|
<dt>Run User</dt>
|
||||||
<dd>{{.RunUser}}</dd>
|
<dd>{{.RunUser}}</dd>
|
||||||
|
|
3
web.go
3
web.go
|
@ -42,7 +42,7 @@ func newMartini() *martini.ClassicMartini {
|
||||||
m := martini.New()
|
m := martini.New()
|
||||||
m.Use(middleware.Logger())
|
m.Use(middleware.Logger())
|
||||||
m.Use(martini.Recovery())
|
m.Use(martini.Recovery())
|
||||||
m.Use(martini.Static("public"))
|
m.Use(martini.Static("public", martini.StaticOptions{SkipLogging: !base.RouterLog}))
|
||||||
m.MapTo(r, (*martini.Routes)(nil))
|
m.MapTo(r, (*martini.Routes)(nil))
|
||||||
m.Action(r.Handle)
|
m.Action(r.Handle)
|
||||||
return &martini.ClassicMartini{m, r}
|
return &martini.ClassicMartini{m, r}
|
||||||
|
@ -208,4 +208,5 @@ func runWeb(*cli.Context) {
|
||||||
qlog.Error(err.Error())
|
qlog.Error(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
qlog.Fatalf("Invalid protocol: %s", protocol)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue