Пример #1
0
Файл: logger.go Проект: shkw/gae
// TODO(riannucci): prefix with caller's code location.
func (gl *loggerImpl) LogCall(l logging.Level, calldepth int, format string, args []interface{}) {
	if gl.aeCtx == nil || !logging.IsLogging(gl.ic, l) {
		return
	}

	var logf func(context.Context, string, ...interface{})
	switch l {
	case logging.Debug:
		logf = log.Debugf
	case logging.Info:
		logf = log.Infof
	case logging.Warning:
		logf = log.Warningf

	case logging.Error:
		fallthrough
	default:
		logf = log.Errorf
	}

	fields := logging.GetFields(gl.ic)
	if len(fields) > 0 {
		logf(gl.aeCtx, "%s :: %s", fmt.Sprintf(format, args...), fields.String())
	} else {
		logf(gl.aeCtx, format, args...)
	}
}
Пример #2
0
// Use adds a memory backed Logger to Context, with concrete type
// *MemLogger. Casting to the concrete type can be used to inspect the
// log output after running a test case, for example.
func Use(c context.Context) context.Context {
	lock := sync.Mutex{}
	data := []LogEntry{}
	return logging.SetFactory(c, func(ic context.Context) logging.Logger {
		return &MemLogger{&lock, &data, logging.GetFields(ic)}
	})
}
Пример #3
0
func (li *loggerImpl) LogCall(l logging.Level, calldepth int, format string, args []interface{}) {
	// Append the fields to the format string.
	if li.c != nil {
		if !logging.IsLogging(li.c, l) {
			return
		}

		if fields := logging.GetFields(li.c); len(fields) > 0 {
			format = formatWithFields(format, fields, args)
			args = nil
		}
	}

	li.Lock()
	defer li.Unlock()

	li.l.ExtraCalldepth = (calldepth + 1)
	switch l {
	case logging.Debug:
		li.l.Debug(format, args...)
	case logging.Info:
		li.l.Info(format, args...)
	case logging.Warning:
		li.l.Warning(format, args...)
	case logging.Error:
		li.l.Error(format, args...)
	}
}
Пример #4
0
func (l *boundCloudLogger) LogCall(level log.Level, calldepth int, f string, args []interface{}) {
	if len(f) == 0 || !log.IsLogging(l.ctx, level) {
		return
	}

	l.logger.logC <- &logEntry{
		timestamp: clock.Now(l.ctx),
		level:     level,
		fmt:       f,
		args:      args,
		fields:    log.GetFields(l.ctx),
	}
}
Пример #5
0
func (g *gaeLoggerImpl) og(l logging.Level, logf func(string, ...interface{}),
	format string, args []interface{}) {
	if g.c != nil {
		if !logging.IsLogging(g.c, l) {
			return
		}
	}

	fields := logging.GetFields(g.c)
	if len(fields) > 0 {
		logf("%s ctx%s", fmt.Sprintf(format, args...), fields.FieldString(true))
	} else {
		logf(format, args...)
	}
}
Пример #6
0
func (l *boundCloudLogger) LogCall(level logging.Level, calldepth int, f string, args []interface{}) {
	if len(f) == 0 {
		return
	}

	text := fmt.Sprintf(f, args...)
	fields := logging.GetFields(l.ctx)
	if len(fields) > 0 {
		text = text + " " + fields.FieldString(true)
	}

	// Add logging fields to labels.
	entry := cloudlogging.Entry{
		Timestamp:   clock.Now(l.ctx),
		Severity:    l.getSeverity(level),
		Labels:      make(map[string]string, len(fields)),
		TextPayload: text,
	}

	// Populate Labels.
	for k, v := range fields {
		val := ""
		if l.FieldConverter != nil {
			val = l.FieldConverter(v)
		} else {
			val = fmt.Sprintf("%v", v)
		}
		entry.Labels[k] = val
	}

	// Generate an InsertID, if we're configured with a base.
	if l.InsertIDBase != "" {
		entry.InsertID = l.generateInsertID()
	}

	l.client.PushEntries([]*cloudlogging.Entry{&entry})
}