Solution for Google App Engine?

https://cloud.google.com/appengine/docs/go/logs/
This commit is contained in:
Manu Mtz-Almeida 2015-05-24 01:00:17 +02:00
parent a2105ce34c
commit e2adae9003
2 changed files with 8 additions and 21 deletions

View File

@ -4,13 +4,11 @@
package gin package gin
import ( import "log"
"log"
"os"
)
var debugLogger = log.New(os.Stdout, "[GIN-debug] ", 0)
func init() {
log.SetFlags(0)
}
func IsDebugging() bool { func IsDebugging() bool {
return ginMode == debugCode return ginMode == debugCode
} }
@ -25,7 +23,7 @@ func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
func debugPrint(format string, values ...interface{}) { func debugPrint(format string, values ...interface{}) {
if IsDebugging() { if IsDebugging() {
debugLogger.Printf(format, values...) log.Printf("[GIN-debug] "+format, values...)
} }
} }

View File

@ -9,13 +9,12 @@ import (
"errors" "errors"
"io" "io"
"log" "log"
"os"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
var cachedDebugLogger *log.Logger = nil
// TODO // TODO
// func debugRoute(httpMethod, absolutePath string, handlers HandlersChain) { // func debugRoute(httpMethod, absolutePath string, handlers HandlersChain) {
// func debugPrint(format string, values ...interface{}) { // func debugPrint(format string, values ...interface{}) {
@ -60,20 +59,10 @@ func TestDebugPrintError(t *testing.T) {
func setup(w io.Writer) { func setup(w io.Writer) {
SetMode(DebugMode) SetMode(DebugMode)
if cachedDebugLogger == nil { log.SetOutput(w)
cachedDebugLogger = debugLogger
debugLogger = log.New(w, debugLogger.Prefix(), 0)
} else {
panic("setup failed")
}
} }
func teardown() { func teardown() {
SetMode(TestMode) SetMode(TestMode)
if cachedDebugLogger != nil { log.SetOutput(os.Stdout)
debugLogger = cachedDebugLogger
cachedDebugLogger = nil
} else {
panic("teardown failed")
}
} }