當前位置: 首頁>>代碼示例>>Golang>>正文


Golang logrus.Fields函數代碼示例

本文整理匯總了Golang中github.com/Sirupsen/logrus.Fields函數的典型用法代碼示例。如果您正苦於以下問題:Golang Fields函數的具體用法?Golang Fields怎麽用?Golang Fields使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Fields函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/Sirupsen/logrus.Fields函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。