func TestSetFilenameDisplay(t *testing.T) { var msg string server := httptest.NewServer(stdhttp.HandlerFunc(func(w stdhttp.ResponseWriter, r *stdhttp.Request) { b, err := ioutil.ReadAll(r.Body) if err != nil { msg = err.Error() return } msg = string(b) })) defer server.Close() header := make(stdhttp.Header, 0) header.Set("Content-Type", "text/plain") hLog, err := New(server.URL, "POST", header) if err != nil { t.Fatalf("Error initializing HTTP received '%s'", err) } hLog.SetBuffersAndWorkers(0, 1) hLog.SetTimestampFormat("MST") hLog.SetFilenameDisplay(log.Llongfile) log.RegisterHandler(hLog, log.DebugLevel, log.TraceLevel, log.InfoLevel, log.NoticeLevel, log.WarnLevel, log.PanicLevel, log.AlertLevel, log.FatalLevel) log.Alert("alert") if msg != "UTC ALERT github.com/go-playground/log/handlers/http/http_test.go:166 alert" { t.Errorf("Expected '%s' Got '%s'", "UTC ALERT github.com/go-playground/log/handlers/http/http_test.go:166 alert", msg) } }
func main() { cLog := console.New() log.RegisterHandler(cLog, log.AllLevels...) // Trace defer log.Trace("trace").End() log.Debug("debug") log.Info("info") log.Notice("notice") log.Warn("warn") log.Error("error") // log.Panic("panic") // this will panic log.Alert("alert") // log.Fatal("fatal") // this will call os.Exit(1) // logging with fields can be used with any of the above log.WithFields(log.F("key", "value")).Info("test info") }