コード例 #1
0
ファイル: logger.go プロジェクト: latam-airlines/crane
func Setup(config Configurer, debug bool) error {
	if logger == nil {
		logger = log.New()
	}

	var err error

	if logger.Level, err = log.ParseLevel(config.Level); err != nil {
		return err
	}

	if debug {
		logger.Level = log.DebugLevel
	}

	switch config.Formatter {
	case "text":
		formatter := new(log.TextFormatter)
		formatter.ForceColors = config.Colored
		formatter.FullTimestamp = true
		logger.Formatter = formatter
		break
	case "json":
		formatter := new(log.JSONFormatter)
		logger.Formatter = formatter
		break
	default:
		return errors.New("Formato de lo log desconocido")
	}

	switch config.Output {
	case "console":
		logger.Out = os.Stdout
		break
	case "file":
		fileName := "mesos-framework-factory.log"
		if config.FileName != "" {
			fileName = config.FileName
		}

		logFile, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
		if err != nil {
			logger.Warnln("Error al abrir el archivo")
		}
		logger.Out = logFile
		break
	default:
		return errors.New("Output de logs desconocido")
	}

	return nil
}
コード例 #2
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
}
コード例 #3
0
ファイル: cli.go プロジェクト: ch3lo/crane
func setupLogger(config configuration.Loggging, debug bool) error {
	var err error

	if util.Log.Level, err = log.ParseLevel(config.Level); err != nil {
		return err
	}

	if debug {
		util.Log.Level = log.DebugLevel
	}

	switch config.Formatter {
	case "text":
		formatter := new(log.TextFormatter)
		formatter.ForceColors = config.Colored
		formatter.FullTimestamp = true
		util.Log.Formatter = formatter
		break
	case "json":
		formatter := new(log.JSONFormatter)
		util.Log.Formatter = formatter
		break
	default:
		return errors.New("Formato de lo log desconocido")
	}

	switch config.Output {
	case "console":
		util.Log.Out = os.Stdout
		break
	case "file":
		util.Log.Out = logFile
		break
	default:
		return errors.New("Output de logs desconocido")
	}

	return nil
}