Exemplo n.º 1
1
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
}
Exemplo n.º 2
1
func SetLogLevel(log *logrus.Logger, levelString string) error {
	level, err := logrus.ParseLevel(levelString)
	if err != nil {
		return err
	}
	log.Level = level
	return nil
}
Exemplo n.º 3
0
// Main is the top of the pile.  Start here.
func Main(log *logrus.Logger) {
	opts := NewOptions()
	if opts.Debug {
		log.Level = logrus.DebugLevel
	}

	if opts.FileStorePrefix == "" {
		opts.FileStorePrefix = "tmp"
	}

	server, err := NewServer(opts, log, nil)
	if err != nil {
		log.Fatal(err)
	}

	port := os.Getenv("PORT")
	if port == "" {
		port = "9839"
	}

	addr := fmt.Sprintf(":%s", port)
	log.WithFields(logrus.Fields{
		"addr": addr,
	}).Info("artifacts-service listening")

	server.Run(addr)
}
Exemplo n.º 4
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
}
Exemplo n.º 5
0
Arquivo: app.go Projeto: 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
}
Exemplo n.º 6
0
// MigratorMain is the entry point for the "migrate" cli command
func MigratorMain(log *logrus.Logger) {
	opts := NewOptions()
	if opts.Debug {
		log.Level = logrus.DebugLevel
	}

	log.Debug("spinning up database")

	db, err := metadata.NewDatabase(opts.DatabaseURL, log)
	if err != nil {
		log.Fatal(err)
	}

	log.Debug("migrating")

	err = db.Migrate(log)
	if err != nil {
		log.Fatal(err)
	}

	log.Info("database migration complete")
}