|
|
@@ -113,14 +113,21 @@ func RouterHandler(level log.Level) func(ctx *macaron.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
// SetLogMsgID set msgID in Context |
|
|
|
func SetLogMsgID() func(ctx *macaron.Context) { |
|
|
|
return func(ctx *macaron.Context) { |
|
|
|
func SetLogMsgID() macaron.Handler { |
|
|
|
return func(ctx *macaron.Context, sess session.Store) { |
|
|
|
start := time.Now() |
|
|
|
|
|
|
|
uuid := gouuid.NewV4().String() |
|
|
|
ctx.Data["MsgID"] = uuid |
|
|
|
|
|
|
|
log.Info("Started %s %s for %s", log.ColoredMethod(ctx.Req.Method), ctx.Req.URL.RequestURI(), ctx.RemoteAddr(), ctx.Data["MsgID"]) |
|
|
|
// Get user from session if logged in. |
|
|
|
user, _ := auth.SignedInUser(ctx, sess) |
|
|
|
var username string |
|
|
|
if user != nil { |
|
|
|
username = user.Name |
|
|
|
} |
|
|
|
|
|
|
|
log.Info("%s Started %s %s for %s", username, log.ColoredMethod(ctx.Req.Method), ctx.Req.URL.RequestURI(), ctx.RemoteAddr(), ctx.Data["MsgID"]) |
|
|
|
|
|
|
|
rw := ctx.Resp.(macaron.ResponseWriter) |
|
|
|
ctx.Next() |
|
|
@@ -148,7 +155,7 @@ func NewMacaron() *macaron.Macaron { |
|
|
|
m.Use(macaron.Logger()) |
|
|
|
} |
|
|
|
} |
|
|
|
m.Use(SetLogMsgID()) |
|
|
|
//m.Use(SetLogMsgID()) |
|
|
|
// Access Logger is similar to Router Log but more configurable and by default is more like the NCSA Common Log format |
|
|
|
if setting.EnableAccessLog { |
|
|
|
setupAccessLogger(m) |
|
|
@@ -256,6 +263,7 @@ func NewMacaron() *macaron.Macaron { |
|
|
|
DisableDebug: !setting.EnablePprof, |
|
|
|
})) |
|
|
|
m.Use(context.Contexter()) |
|
|
|
m.Use(SetLogMsgID()) |
|
|
|
// OK we are now set-up enough to allow us to create a nicer recovery than |
|
|
|
// the default macaron recovery |
|
|
|
m.Use(context.Recovery()) |
|
|
|