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


Golang Logger.WithField方法代码示例

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


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

示例1: newInstanceCleaner

func newInstanceCleaner(
	cs *compute.Service,
	log *logrus.Logger,
	rateLimiter ratelimit.RateLimiter,
	rateLimitMaxCalls uint64,
	rateLimitDuration time.Duration,
	cutoffTime time.Time,
	projectID string,
	filters []string,
	noop bool,
) *instanceCleaner {
	return &instanceCleaner{
		cs:  cs,
		log: log.WithField("component", "instance_cleaner"),

		projectID: projectID,
		filters:   filters,

		noop: noop,

		CutoffTime: cutoffTime,

		rateLimiter:       rateLimiter,
		rateLimitMaxCalls: rateLimitMaxCalls,
		rateLimitDuration: rateLimitDuration,
	}
}
开发者ID:travis-ci,项目名称:gcloud-cleanup,代码行数:27,代码来源:instance_cleaner.go

示例2: newImageCleaner

func newImageCleaner(
	cs *compute.Service,
	log *logrus.Logger,
	rateLimiter ratelimit.RateLimiter,
	rateLimitMaxCalls uint64,
	rateLimitDuration time.Duration,
	projectID,
	jobBoardURL string,
	filters []string,
	noop bool,
) *imageCleaner {
	return &imageCleaner{
		cs:  cs,
		log: log.WithField("component", "image_cleaner"),

		projectID:   projectID,
		jobBoardURL: jobBoardURL,
		filters:     filters,

		noop: noop,

		rateLimiter:       rateLimiter,
		rateLimitMaxCalls: rateLimitMaxCalls,
		rateLimitDuration: rateLimitDuration,
	}
}
开发者ID:travis-ci,项目名称:gcloud-cleanup,代码行数:26,代码来源:image_cleaner.go

示例3: Logging

//Logging logs http requests
func Logging(next http.Handler, log *logrus.Logger) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		srw := StatusResponseWriter{w, 0, 0}
		start := time.Now()
		next.ServeHTTP(&srw, r)
		end := time.Now()
		latency := end.Sub(start)

		log.WithField("client", r.RemoteAddr).WithField("latency", latency).WithField("length", srw.Length()).WithField("code", srw.Status()).Printf("%s %s %s", r.Method, r.URL, r.Proto)
	})
}
开发者ID:DamienFontaine,项目名称:lunarc,代码行数:12,代码来源:handlers.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: NewS3Store

// NewS3Store initializes an *S3Store.  Wow!
func NewS3Store(key, secret, bucket, regionName string,
	log *logrus.Logger, md metadata.LookupSaver) (*S3Store, error) {

	log.Debug("getting aws auth")
	auth, err := aws.GetAuth(key, secret)
	if err != nil {
		log.WithField("err", err).Error("failed to get auth")
		return nil, err
	}

	region, ok := aws.Regions[regionName]
	if !ok {
		log.WithFields(logrus.Fields{
			"region": regionName,
		}).Warn(fmt.Sprintf("nonexistent region, falling back to %s", aws.USEast.Name))
		region = aws.USEast
	}

	log.Debug("getting new s3 connection")
	s3Conn := s3.New(auth, region)
	b := s3Conn.Bucket(bucket)

	if b == nil || b.Name == "" {
		return nil, errNoBucket
	}

	log.WithFields(logrus.Fields{
		"bucket": b.Name,
	}).Debug("got back this bucket")

	return &S3Store{
		key:    key,
		secret: secret,
		bucket: bucket,

		log: log,
		md:  md,
		b:   b,
	}, nil
}
开发者ID:hamfist,项目名称:artifacts-service,代码行数:41,代码来源:s3_store.go

示例6: LogCallback

// LogCallback returns a callback that logs an error to logger with msg at Warn
func LogCallback(msg string, l *log.Logger) ErrCallback {
	return func(err error) {
		l.WithField("err", err.Error()).Warn(msg)
	}
}
开发者ID:signalfx,项目名称:cadvisor-integration,代码行数:6,代码来源:ratelimitlogger.go


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