本文整理汇总了Golang中github.com/Sirupsen/logrus.Fields函数的典型用法代码示例。如果您正苦于以下问题:Golang Fields函数的具体用法?Golang Fields怎么用?Golang Fields使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Fields函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: WithFields
func (l barkLogrusLogger) WithFields(logFields LogFields) Logger {
if logFields == nil {
return l
}
return newBarkLogrusLogger(l.logrusLoggerOrEntry.WithFields(logrus.Fields(logFields.Fields())))
}
开发者ID:dansimau,项目名称:ringpop-go,代码行数:7,代码来源:logrus_logger.go
示例2: calculateStats
func (c *Cache) calculateStats(reportingDuration time.Duration) {
c.lock.Lock()
defer c.lock.Unlock()
ratio := 100
if c.hits+c.misses != 0 {
ratio = 100 * c.hits / (c.hits + c.misses)
}
c.stats = map[string]interface{}{
"type": "metric",
"metric_name": "cachestatus",
"cache_entries": c.lruBackend.Len(),
"cache_size_bytes": c.currentSizeBytes,
"cache_reporting_duration": reportingDuration,
"cache_hits": c.hits,
"cache_misses": c.misses,
"cache_hit_ratio": ratio,
}
c.hits = 0
c.misses = 0
logging.Logger.
WithFields(logrus.Fields(c.stats)).
Infof("cache status #%v, %vbytes, %v%% hits", c.lruBackend.Len(), c.currentSizeBytes, ratio)
}
开发者ID:tarent,项目名称:lib-compose,代码行数:26,代码来源:cache.go
示例3: Debug
func (logger *Logger) Debug(message interface{}, fields ...Fields) {
var log logrus.FieldLogger = logger.Logger
if len(fields) > 0 {
log = log.WithFields(logrus.Fields(fields[0]))
}
log.Debug(message)
}
开发者ID:crob1140,项目名称:CodeWiz,代码行数:8,代码来源:log.go
示例4: ParamsWithFields
func (l *LogrusLogger) ParamsWithFields(params interface{}, f map[string]interface{}) {
var pstr string
pb, err := json.Marshal(params)
if err != nil {
pstr = "json marshal error"
} else {
pstr = string(pb)
}
f["params"] = pstr
l.Logger.WithFields(logrus.Fields(f)).Info("params_log")
}
开发者ID:kazukgw,项目名称:goji-active-context,代码行数:12,代码来源:logger.go
示例5: WithFields
func (l Logger) WithFields(fields map[string]interface{}) Entry {
if fields == nil {
fields = make(map[string]interface{})
}
_, file, line, _ := runtime.Caller(2)
fields["*TIME"] = getTime()
fields[".FILE"] = trimFile(file)
fields[".LINE"] = line
return Entry{
l.logger.WithFields(logrus.Fields(fields)),
}
}
开发者ID:grokking-vietnam,项目名称:grokking-blog,代码行数:13,代码来源:logs.go
示例6: WithFields
// WithFields returns an advanced logger with pre-set fields.
func (l *Logger) WithFields(fields ...interface{}) loggers.Advanced {
f := make(map[string]interface{}, len(fields)/2)
var key, value interface{}
for i := 0; i+1 < len(fields); i = i + 2 {
key = fields[i]
value = fields[i+1]
if s, ok := key.(string); ok {
f[s] = value
} else if s, ok := key.(fmt.Stringer); ok {
f[s.String()] = value
}
}
return l.Logger.WithFields(logrus.Fields(f))
}
开发者ID:birkirb,项目名称:loggers-mapper-logrus,代码行数:16,代码来源:logrus.go
示例7: TestGetUserFromString
func TestGetUserFromString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
data map[string]interface{}
expected bool
description string
}{
{map[string]interface{}{
"user_name": "name",
"user_email": "[email protected]",
"user_id": "A0001",
"user_ip": "0.0.0.0",
}, true, "valid user"},
{map[string]interface{}{"user_name": "name"}, true, "valid user"},
{map[string]interface{}{"user_email": "[email protected]"}, true, "valid user"},
{map[string]interface{}{"user_id": "A0001"}, true, "valid user"},
{map[string]interface{}{"user_ip": "0.0.0.0"}, true, "valid user"},
{map[string]interface{}{"user_name": ""}, false, "invalid user: empty user_name"},
{map[string]interface{}{"user_email": ""}, false, "invalid user: empty user_email"},
{map[string]interface{}{"user_id": ""}, false, "invalid user: empty user_id"},
{map[string]interface{}{"user_ip": ""}, false, "invalid user: empty user_ip"},
{map[string]interface{}{
"user_name": 1,
"user_email": true,
"user_id": errors.New("user_id"),
"user_ip": "",
}, false, "invalid types"},
}
for _, tt := range tests {
target := fmt.Sprintf("%+v", tt)
fields := logrus.Fields(tt.data)
df := newDataField(fields)
user, ok := df.getUser()
assert.Equal(tt.expected, ok, target)
if ok {
assert.IsType(&raven.User{}, user, target)
}
}
}
开发者ID:evalphobia,项目名称:logrus_sentry,代码行数:43,代码来源:data_field_test.go
示例8: RespondWithError
// RespondWithError will return an error response with the appropriate message,
// and status codes set.
func RespondWithError(w http.ResponseWriter, r *http.Request, err error) {
isPublicError := false
errorResponse := APIError{
Error: err.Error(),
}
code := http.StatusInternalServerError
if statusErr, ok := err.(StatusError); ok {
// If we get a status code, this error can be considered a public error.
isPublicError = true
code = statusErr.StatusCode()
}
if descriptiveErr, ok := err.(DescriptiveError); ok {
errorResponse.Description = descriptiveErr.ErrorDescription()
}
if annotatedErr, ok := err.(AnnotatedError); ok {
errorResponse.Fields = annotatedErr.ErrorFields()
}
w.WriteHeader(code)
// Now log some information about the failure.
logData := map[string]interface{}{}
if structuredLogErr, ok := err.(StructuredLogsError); ok {
for key, value := range structuredLogErr.LogFields() {
logData[key] = value
}
}
logData["status"] = code
if !isPublicError {
logData["original_error"] = err.Error()
err = fail.NewPrivate(err)
errorResponse.Error = err.Error()
}
body := DefaultRenderer.RenderError(errorResponse)
w.Write(body)
log.WithError(err).WithFields(logrus.Fields(logData)).Error("Returning error response")
}
开发者ID:snikch,项目名称:api,代码行数:45,代码来源:error.go
示例9: PurgeEntries
// Purge Entries with a specific hash
func (c *Cache) PurgeEntries(keys []string) {
purged := 0
purgedKeys := []string{}
for _, key := range keys {
c.lock.RLock()
_, found := c.lruBackend.Peek(key)
c.lock.RUnlock()
if found {
c.lock.Lock()
c.lruBackend.Remove(key)
c.lock.Unlock()
purged++
purgedKeys = append(purgedKeys, key)
}
}
logging.Logger.
WithFields(logrus.Fields(c.stats)).
Infof("Following cache entries become purged: %v", c.PurgedKeysAsString(keys))
}
开发者ID:tarent,项目名称:lib-compose,代码行数:21,代码来源:cache.go
示例10: TrackEvent
func TrackEvent(event string, params map[string]interface{}) {
log := logrus.WithFields(logrus.Fields{"ns": "api.helpers", "at": "TrackEvent"})
if params == nil {
params = map[string]interface{}{}
}
params["client_id"] = os.Getenv("CLIENT_ID")
params["rack"] = os.Getenv("RACK")
params["release"] = os.Getenv("RELEASE")
userId := RackId()
log.WithFields(logrus.Fields{"event": event, "user_id": userId}).WithFields(logrus.Fields(params)).Info()
segment.Track(&analytics.Track{
Event: event,
UserId: userId,
Properties: params,
})
}
开发者ID:cleblanc87,项目名称:rack,代码行数:21,代码来源:helpers.go
示例11: newLog
func (log *Logger) newLog(level logrus.Level, data map[string]interface{}) {
log.rotate()
data["_ts_"] = utils.GetNowMillisecond()
fields := logrus.Fields(data)
switch level {
case LOG_LEVEL_DEBUG:
log.WithFields(fields).Debug("")
case LOG_LEVEL_INFO:
log.WithFields(fields).Info("")
case LOG_LEVEL_WARN:
log.WithFields(fields).Warn("")
case LOG_LEVEL_ERROR:
log.WithFields(fields).Error("")
case LOG_LEVEL_FATAL:
log.WithFields(fields).Fatal("")
case LOG_LEVEL_PANIC:
log.WithFields(fields).Panic("")
default:
log.WithFields(fields).Info("")
}
}
开发者ID:Instafig,项目名称:Instafig,代码行数:23,代码来源:logger.go
示例12: PurgeOldEntries
// PurgeOldEntries removes all entries which are out of their ttl
func (c *Cache) PurgeOldEntries() {
c.lock.RLock()
keys := c.lruBackend.Keys()
c.lock.RUnlock()
purged := 0
for _, key := range keys {
c.lock.RLock()
e, found := c.lruBackend.Peek(key)
c.lock.RUnlock()
if found {
entry := e.(*CacheEntry)
if time.Since(entry.fetchTime) > c.maxAge {
c.lock.Lock()
c.lruBackend.Remove(key)
c.lock.Unlock()
purged++
}
}
}
logging.Logger.
WithFields(logrus.Fields(c.stats)).
Infof("purged %v out of %v cache entries", purged, len(keys))
}
开发者ID:tarent,项目名称:lib-compose,代码行数:25,代码来源:cache.go
示例13: ErrorWithFields
func (l *LogrusLogger) ErrorWithFields(e error, f map[string]interface{}) {
f["msg"] = e.Error()
logrusF := logrus.Fields(f)
l.Logger.WithFields(logrusF).Error("error")
}
开发者ID:kazukgw,项目名称:goji-active-context,代码行数:5,代码来源:logger.go
示例14: InfoWithFields
func (l *LogrusLogger) InfoWithFields(msg string, f map[string]interface{}) {
logrusF := logrus.Fields(f)
l.Logger.WithFields(logrusF).Info(msg)
}
开发者ID:kazukgw,项目名称:goji-active-context,代码行数:4,代码来源:logger.go
示例15: GetLoggerWithFields
// GetLoggerWithFields returns a logger instance with the specified fields
// without affecting the context. Extra specified keys will be resolved from
// the context.
func GetLoggerWithFields(ctx Context, fields map[string]interface{}, keys ...interface{}) Logger {
return getLogrusLogger(ctx, keys...).WithFields(logrus.Fields(fields))
}
开发者ID:useidel,项目名称:notary,代码行数:6,代码来源:logger.go
示例16: Fields
func (f Fields) Fields() logrus.Fields {
return logrus.Fields(f)
}
开发者ID:owulveryck,项目名称:gorchestrator,代码行数:3,代码来源:logger.go
示例17: WithFields
// WithFields wraps logrus
func (e *LogEntry) WithFields(fields LogFields) *LogEntry {
return &LogEntry{e.Entry.WithFields(logrus.Fields(fields))}
}
开发者ID:wercker,项目名称:wercker,代码行数:4,代码来源:logging.go
示例18: WithFields
// WithFields creates a child logger annotated with the provided key value
// pairs.
func (e *Entry) WithFields(fields F) *Entry {
return &Entry{*e.Entry.WithFields(logrus.Fields(fields))}
}
开发者ID:stellar,项目名称:bridge-server,代码行数:5,代码来源:entry.go
示例19: WithFields
// WithFields creates an entry from the standard logger and adds multiple
// fields to it. This is simply a helper for `WithField`, invoking it
// once for each field.
//
// Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal
// or Panic on the Entry it returns.
func WithFields(fields Fields) *logrus.Entry {
return Logger.WithFields(logrus.Fields(fields))
}
开发者ID:palaiyacw,项目名称:imgry,代码行数:9,代码来源:lg.go
注:本文中的github.com/Sirupsen/logrus.Fields函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论