Exemplo n.º 1
0
func (formatter) Format(e *logrus.Entry) ([]byte, error) {
	var t logrus.Formatter

	frame := stack.Caller(7)
	frame.File = stack.StripGOPATH(frame.File)
	e.Data["function"] = frame.Name
	e.Data["file"] = fmt.Sprintf("%s:%d", frame.File, frame.Line)

	if os.Getenv("LOG_FORMAT") == "json" {
		t = &logrus.JSONFormatter{}
	} else {
		t = &logrus.TextFormatter{
			FullTimestamp:   true,
			TimestampFormat: time.Stamp,
		}
	}

	return t.Format(e)
}
Exemplo n.º 2
0
func (formatter) Format(e *logrus.Entry) ([]byte, error) {
	var f logrus.Formatter

	frame := stack.Caller(7)

	if os.Getenv("LOG_FORMAT") == "json" {
		e.Data["func"] = frame.Name
		e.Data["line"] = frame.Line
		e.Data["file"] = frame.File

		f = json
	} else {
		e.Data["func"] = fmt.Sprintf("%s:%d", frame.Name, frame.Line)

		f = text
	}

	return f.Format(e)
}