// TestLogEntryMessageReceived checks if invoking Logrus' log.Error // method causes an XML payload containing the log entry message is received // by a HTTP server emulating an Airbrake-compatible endpoint. func TestLogEntryMessageReceived(t *testing.T) { log := logrus.New() ts := startAirbrakeServer(t) defer ts.Close() hook := NewHook(ts.URL, testAPIKey, "production") log.Hooks.Add(hook) log.Error(expectedMsg) select { case received := <-noticeError: if received.Message != expectedMsg { t.Errorf("Unexpected message received: %s", received.Message) } case <-time.After(time.Second): t.Error("Timed out; no notice received by Airbrake API") } }
// TestLogEntryMessageReceived confirms that, when passing an error type using // logrus.Fields, a HTTP server emulating an Airbrake endpoint receives the // error message returned by the Error() method on the error interface // rather than the logrus.Entry.Message string. func TestLogEntryWithErrorReceived(t *testing.T) { log := logrus.New() ts := startAirbrakeServer(t) defer ts.Close() hook := NewHook(ts.URL, testAPIKey, "production") log.Hooks.Add(hook) log.WithFields(logrus.Fields{ "error": &customErr{expectedMsg}, }).Error(unintendedMsg) select { case received := <-noticeError: if received.Message != expectedMsg { t.Errorf("Unexpected message received: %s", received.Message) } if received.Class != expectedClass { t.Errorf("Unexpected error class: %s", received.Class) } case <-time.After(time.Second): t.Error("Timed out; no notice received by Airbrake API") } }
package util import ( "os" "github.com/heems/bssim/Godeps/_workspace/src/github.com/Sirupsen/logrus" ) func init() { SetupLogging() } var log = logrus.New() // LogFormats is a map of formats used for our logger, keyed by name. // TODO: write custom TextFormatter (don't print module=name explicitly) and // fork logrus to add shortfile var LogFormats = map[string]*logrus.TextFormatter{ "nocolor": &logrus.TextFormatter{DisableColors: true, FullTimestamp: true, TimestampFormat: "2006-01-02 15:04:05.000000", DisableSorting: true}, "color": &logrus.TextFormatter{DisableColors: false, FullTimestamp: true, TimestampFormat: "15:04:05:000", DisableSorting: true}, } var defaultLogFormat = "color" // Logging environment variables const ( envLogging = "IPFS_LOGGING" envLoggingFmt = "IPFS_LOGGING_FMT" ) // loggers is the set of loggers in the system var loggers = map[string]*logrus.Entry{}
func getTestLogger() *logrus.Logger { l := logrus.New() l.Out = ioutil.Discard return l }