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


Golang TextFormatter.TimestampFormat方法代码示例

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


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

示例1: InitializeLogger

func InitializeLogger(developerModeFlag bool) {
	logger = log.New()

	if developerModeFlag {
		customFormatter := new(log.TextFormatter)
		customFormatter.FullTimestamp = true
		customFormatter.TimestampFormat = "2006-01-02 15:04:05"
		log.SetFormatter(customFormatter)

		log.SetLevel(log.DebugLevel)
		logger.Level = log.DebugLevel
		logger.Formatter = customFormatter
	} else {
		customFormatter := new(log.JSONFormatter)
		customFormatter.TimestampFormat = "2006-01-02 15:04:05"

		log.SetFormatter(customFormatter)
		customFormatter.DisableTimestamp = false

		log.SetLevel(log.InfoLevel)
		logger.Level = log.InfoLevel
		logger.Formatter = customFormatter
	}

	logger.Out = os.Stdout

}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:27,代码来源:log.go

示例2: NewCustomizedLogger

func NewCustomizedLogger(level string, developerModeFlag bool) (*log.Logger, error) {
	logger := log.New()

	lv, err := log.ParseLevel(level)
	if err != nil {
		return nil, err
	}
	logger.Level = lv

	if developerModeFlag {
		customFormatter := new(log.TextFormatter)
		customFormatter.FullTimestamp = true
		customFormatter.TimestampFormat = "2006-01-02 15:04:05"
		log.SetFormatter(customFormatter)

		log.SetLevel(log.DebugLevel)
		logger.Level = lv
		logger.Formatter = customFormatter
	} else {
		customFormatter := new(log.JSONFormatter)
		customFormatter.TimestampFormat = "2006-01-02 15:04:05"

		log.SetFormatter(customFormatter)
		customFormatter.DisableTimestamp = false

		log.SetLevel(log.InfoLevel)
		logger.Level = lv
		logger.Formatter = customFormatter
	}

	logger.Out = os.Stdout

	return logger, nil
}
开发者ID:Ritsyy,项目名称:almighty-core,代码行数:34,代码来源:log.go

示例3: LogInit

// LogInit is a utility function to initialize logging
func LogInit(filename string) {
	f, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.Fatal("Unable to open Log file ", err)
	}
	Logger.Out = f
	customFormatter := new(logrus.TextFormatter)
	customFormatter.TimestampFormat = "2016-03-28 15:04:05"
	Logger.Formatter = customFormatter
	customFormatter.FullTimestamp = true
	customFormatter.DisableColors = true
}
开发者ID:aravindavk,项目名称:glusterrest_old,代码行数:13,代码来源:utils.go

示例4: 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

示例5: init

func init() {
	configError = config.LoadConfig()

	// Logger
	formatter := new(logrus.TextFormatter)
	formatter.TimestampFormat = time.RFC3339
	formatter.FullTimestamp = true
	logrus.SetFormatter(formatter)
	logrus.SetOutput(os.Stdout)

	// Uid & Gid
	currentUser, err := user.Current()
	if err != nil {
		gid = 0
		uid = 0
	} else {
		// Non-parsable uid & gid should never be seen
		gid, _ = strconv.ParseUint(currentUser.Gid, 10, 64)
		uid, _ = strconv.ParseUint(currentUser.Uid, 10, 64)
	}

	setFlags()
	RootCmd.AddCommand(mountCmd)
}
开发者ID:ovh,项目名称:svfs,代码行数:24,代码来源:mount.go


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