func main() { runtime.GOMAXPROCS(runtime.NumCPU()) logger := log.New(os.Stdout, "[tango] ", log.Ldefault()) t := tango.Classic(logger) t.Use(tpongo2.New()) t.Get("/json", new(JsonAction)) t.Get("/pongo", new(PongoAction)) t.Get("/string", new(StringAction)) t.Run(":8001") }
func TestLogger1(t *testing.T) { buff := bytes.NewBufferString("") recorder := httptest.NewRecorder() n := NewWithLog(log.New(buff, "[tango] ", 0)) n.Use(Logging()) n.UseHandler(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { rw.WriteHeader(http.StatusNotFound) })) req, err := http.NewRequest("GET", "http://localhost:3000/foobar", nil) if err != nil { t.Error(err) } n.ServeHTTP(recorder, req) expect(t, recorder.Code, http.StatusNotFound) refute(t, len(buff.String()), 0) }
func NewLogger(out io.Writer) Logger { l := log.New(out, "[tango] ", log.Ldefault()) l.SetOutputLevel(log.Ldebug) return l }