• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang logrus.TextFormatter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

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


示例2: init

func init() {
	formatter := log.TextFormatter{}
	formatter.DisableTimestamp = false
	formatter.DisableColors = true
	log.SetFormatter(&formatter)
	//log.SetLevel(log.InfoLevel)
}
开发者ID:chenhuaying,项目名称:logflume,代码行数:7,代码来源:logflume.go


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


示例4: loadLogging

func loadLogging() {
	// XXX (mmr) : find a better way to do this
	log = logrus.New()
	fmt := new(logrus.TextFormatter)
	fmt.FullTimestamp = true
	log.Formatter = fmt
	log.Level = logrus.DebugLevel
}
开发者ID:joaodubas,项目名称:pglogger,代码行数:8,代码来源:main.go


示例5: init

func init() {
	Log = log.New()
	Log.Level = log.InfoLevel

	formatter := new(log.TextFormatter)
	formatter.FullTimestamp = true
	Log.Formatter = formatter
}
开发者ID:DXTR66,项目名称:buildbulb,代码行数:8,代码来源:logger.go


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


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


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


示例9: makeLogger

// makeLogger configures the package level Logger instance
func makeLogger(conf *BaseConfiguration) {
	levelName, err := logrus.ParseLevel(conf.LogLevel)
	if err != nil {
		defer Logger.Warnf("%s is not a valid level. Defaulting to info.", conf.LogLevel)
		levelName = logrus.InfoLevel
	}

	logOut, err := os.OpenFile(conf.LogFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)

	if err != nil {
		defer Logger.Warnf("%s. Defaulting to Stderr.", err)
		logOut = os.Stderr
	}

	formatter := new(logrus.TextFormatter)
	formatter.DisableColors = true
	Logger = logrus.Logger{
		Out:       logOut,
		Formatter: formatter,
		Level:     levelName,
	}
	Logger.Infof("Initialized at level %s", Logger.Level)
}
开发者ID:pombredanne,项目名称:go-serv,代码行数:24,代码来源:server.go


示例10: Init

func (m *middlewareLogger) Init(app *App) error {
	err := os.MkdirAll(app.dotPath+"/log", 0777)
	if err != nil && !os.IsExist(err) {
		return err
	}

	m.logger = logrus.New()
	logFormatter := new(logrus.TextFormatter)
	logFormatter.FullTimestamp = true
	m.logger.Formatter = logFormatter
	app.logger = m.logger

	m.file = m.openLogFile(app)
	m.logger.Out = m.file

	app.AddCronTask("remove old log files", func() {
		m.removeLogFiles(app, time.Now().AddDate(0, 0, -7))
	}, func(in time.Time) time.Time {
		return in.Add(1 * time.Hour)
	})

	app.AddCronTask("rotate log files", func() {
		app.Log().Println("Rotating log files")
		if m.file != nil {
			newFile := m.openLogFile(app)
			oldFile := m.file
			m.logger.Out = newFile
			m.file = newFile
			oldFile.Close()
		}
	}, func(in time.Time) time.Time {
		return in.Add(24 * time.Hour)
	})
	app.requestMiddlewares = append(app.requestMiddlewares, requestMiddlewareLogBefore)
	return nil
}
开发者ID:hypertornado,项目名称:prago,代码行数:36,代码来源:log.go


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


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


示例13: init

func init() {
	cobra.OnInitialize(initConfig)
	customFormatter := new(log.TextFormatter)
	customFormatter.FullTimestamp = true
	log.SetFormatter(customFormatter)
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:6,代码来源:fusis.go


示例14: Format

func (t *intgFmt) Format(e *log.Entry) ([]byte, error) {
	e.Message = strings.Join([]string{"[INTG-TEST]", e.Message}, " ")
	nt := log.TextFormatter{}
	return nt.Format(e)
}
开发者ID:jojimt,项目名称:netplugin,代码行数:5,代码来源:mesos_test.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang test.NewNullLogger函数代码示例发布时间:2022-05-28
下一篇:
Golang logrus.Logger类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap