From 364cacf6593887728e2fca7c69eae57509ba8a33 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 8 Jun 2015 22:00:28 +0800 Subject: [PATCH] record the critical logs in Prod --- router.go | 57 +++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/router.go b/router.go index e9f45615..2d5ed78d 100644 --- a/router.go +++ b/router.go @@ -857,48 +857,29 @@ func (p *ControllerRegistor) recoverPanic(context *beecontext.Context) { if err == USERSTOPRUN { return } - if RunMode == "dev" { - if !RecoverPanic { - panic(err) - } else { - if ErrorsShow { - if _, ok := ErrorMaps[fmt.Sprint(err)]; ok { - exception(fmt.Sprint(err), context) - return - } - } - var stack string - Critical("the request url is ", context.Input.Url()) - Critical("Handler crashed with error", err) - for i := 1; ; i++ { - _, file, line, ok := runtime.Caller(i) - if !ok { - break - } - Critical(fmt.Sprintf("%s:%d", file, line)) - stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d", file, line)) - } - showErr(err, context, stack) - } + if !RecoverPanic { + panic(err) } else { - if !RecoverPanic { - panic(err) - } else { - // in production model show all infomation - if ErrorsShow { + if ErrorsShow { + if _, ok := ErrorMaps[fmt.Sprint(err)]; ok { exception(fmt.Sprint(err), context) - } else { - Critical("the request url is ", context.Input.Url()) - Critical("Handler crashed with error", err) - for i := 1; ; i++ { - _, file, line, ok := runtime.Caller(i) - if !ok { - break - } - Critical(fmt.Sprintf("%s:%d", file, line)) - } + return } } + var stack string + Critical("the request url is ", context.Input.Url()) + Critical("Handler crashed with error", err) + for i := 1; ; i++ { + _, file, line, ok := runtime.Caller(i) + if !ok { + break + } + Critical(fmt.Sprintf("%s:%d", file, line)) + stack = stack + fmt.Sprintln(fmt.Sprintf("%s:%d", file, line)) + } + if RunMode == "dev" { + showErr(err, context, stack) + } } } }