コード例 #1
1
ファイル: log.go プロジェクト: hobeone/rss2go
func SetupLogger(logger *logrus.Logger) {
	fmter := &prefixed.TextFormatter{}
	logger.Formatter = fmter
	logger.Out = os.Stdout
	// Only log the info severity or above.
	logger.Level = logrus.InfoLevel
}
コード例 #2
0
// Create a logrus logger that writes its out output to a buffer for inspection
func getLogrusLogger() (*logrus.Logger, *bytes.Buffer) {
	var logrusLogger *logrus.Logger = logrus.New()

	buffer := &bytes.Buffer{}
	logrusLogger.Out = buffer
	logrusLogger.Formatter = new(logrus.JSONFormatter)
	logrusLogger.Level = logrus.DebugLevel

	return logrusLogger, buffer
}
コード例 #3
0
ファイル: app.go プロジェクト: ts33kr/boot
// Build an adequate instance of the structured logger for this
// application instance. The journal builder may draw data from the
// app instance to configure the journal correctly. This method only
// instantiates a very basic journal; anything more complicated than
// that should be implementing using a boot.Provider to do it.
func (app *App) makeJournal(level logrus.Level) *logrus.Logger {
	const m = "begin writing application journal"
	var journal *logrus.Logger = &logrus.Logger{}
	formatter := new(logrus.TextFormatter)  // std
	journal.Level = level                   // use requested level
	journal.Out = os.Stdout                 // all goes to stdout
	journal.Hooks = make(logrus.LevelHooks) // empty
	journal.Formatter = formatter           // set formatter
	formatter.ForceColors = false           // act smart
	formatter.DisableColors = false         // make pretty
	formatter.DisableTimestamp = false      // is useful
	formatter.FullTimestamp = false         // numbers
	formatter.TimestampFormat = time.StampMilli
	formatter.DisableSorting = false // order!
	moment := time.Now().Format(app.TimeLayout)
	journal.WithField("time", moment).Info(m)
	return journal // is ready to use
}
コード例 #4
0
ファイル: fatal.go プロジェクト: dansimau/ringpop-go
func main() {
	var logrusLogger *logrus.Logger = logrus.New()
	logrusLogger.Formatter = new(logrus.JSONFormatter)

	if len(os.Args) != 2 {
		logrus.Error("Must pass an arg to test program...")
		os.Exit(0)
	}

	switch os.Args[1] {
	case "logrus.Fatal":
		logrusLogger.Fatal("fatal error")
	case "logrus.Fatalf":
		logrusLogger.Fatalf("fatal error%s", "fatal error")
	case "bark.Fatal":
		bark.NewLoggerFromLogrus(logrusLogger).Fatal("fatal error")
	case "bark.Fatalf":
		bark.NewLoggerFromLogrus(logrusLogger).Fatalf("fatal error%s", "fatal error")
	}

	logrus.Error("Expected fatal methods to exit...")
	os.Exit(0)
}