当前位置: 首页>>代码示例>>Golang>>正文


Golang TextFormatter.ForceColors方法代码示例

本文整理汇总了Golang中github.com/Sirupsen/logrus.TextFormatter.ForceColors方法的典型用法代码示例。如果您正苦于以下问题:Golang TextFormatter.ForceColors方法的具体用法?Golang TextFormatter.ForceColors怎么用?Golang TextFormatter.ForceColors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/Sirupsen/logrus.TextFormatter的用法示例。


在下文中一共展示了TextFormatter.ForceColors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Setup

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
}
开发者ID:latam-airlines,项目名称:crane,代码行数:52,代码来源:logger.go

示例2: makeJournal

// 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
}
开发者ID:ts33kr,项目名称:boot,代码行数:23,代码来源:app.go

示例3: setupLogger

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
}
开发者ID:ch3lo,项目名称:crane,代码行数:39,代码来源:cli.go


注:本文中的github.com/Sirupsen/logrus.TextFormatter.ForceColors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。