2014-02-24 04:50:42 +04:00
|
|
|
package logrus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2019-03-11 13:47:03 +03:00
|
|
|
"context"
|
2014-02-24 04:50:42 +04:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2018-09-30 23:51:02 +03:00
|
|
|
"reflect"
|
2016-11-26 06:02:56 +03:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
2016-06-18 16:47:44 +03:00
|
|
|
"sync"
|
2014-02-24 04:50:42 +04:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2018-10-27 16:21:30 +03:00
|
|
|
var (
|
|
|
|
bufferPool *sync.Pool
|
2016-06-18 16:47:44 +03:00
|
|
|
|
2018-10-27 16:21:30 +03:00
|
|
|
// qualified package name, cached at first use
|
|
|
|
logrusPackage string
|
2016-12-01 21:23:00 +03:00
|
|
|
|
2018-10-27 16:21:30 +03:00
|
|
|
// Positions in the call stack when tracing to report the calling method
|
|
|
|
minimumCallerDepth int
|
2016-12-01 21:23:00 +03:00
|
|
|
|
2018-10-27 16:21:30 +03:00
|
|
|
// Used for caller information initialisation
|
|
|
|
callerInitOnce sync.Once
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
maximumCallerDepth int = 25
|
|
|
|
knownLogrusFrames int = 4
|
|
|
|
)
|
2016-11-29 03:22:33 +03:00
|
|
|
|
2016-06-18 16:47:44 +03:00
|
|
|
func init() {
|
|
|
|
bufferPool = &sync.Pool{
|
|
|
|
New: func() interface{} {
|
|
|
|
return new(bytes.Buffer)
|
|
|
|
},
|
|
|
|
}
|
2016-11-29 03:22:33 +03:00
|
|
|
|
2016-12-01 21:23:00 +03:00
|
|
|
// start at the bottom of the stack before the package-name cache is primed
|
|
|
|
minimumCallerDepth = 1
|
2016-06-18 16:47:44 +03:00
|
|
|
}
|
|
|
|
|
2015-05-19 20:50:55 +03:00
|
|
|
// Defines the key when adding errors using WithError.
|
2015-05-13 14:35:03 +03:00
|
|
|
var ErrorKey = "error"
|
|
|
|
|
2014-10-16 16:39:13 +04:00
|
|
|
// An entry is the final or intermediate Logrus logging entry. It contains all
|
2018-08-28 18:13:29 +03:00
|
|
|
// the fields passed with WithField{,s}. It's finally logged when Trace, Debug,
|
|
|
|
// Info, Warn, Error, Fatal or Panic is called on it. These objects can be
|
|
|
|
// reused and passed around as much as you wish to avoid field duplication.
|
2014-02-24 04:50:42 +04:00
|
|
|
type Entry struct {
|
2014-04-23 20:54:53 +04:00
|
|
|
Logger *Logger
|
2014-07-27 05:37:06 +04:00
|
|
|
|
|
|
|
// Contains all the fields set by the user.
|
|
|
|
Data Fields
|
2014-07-27 05:26:04 +04:00
|
|
|
|
|
|
|
// Time at which the log entry was created
|
|
|
|
Time time.Time
|
|
|
|
|
2018-08-28 18:13:29 +03:00
|
|
|
// Level the log entry was logged at: Trace, Debug, Info, Warn, Error, Fatal or Panic
|
2017-07-14 14:59:01 +03:00
|
|
|
// This field will be set on entry firing and the value will be equal to the one in Logger struct field.
|
2014-07-27 05:26:04 +04:00
|
|
|
Level Level
|
|
|
|
|
2016-11-26 06:02:56 +03:00
|
|
|
// Calling method, with package name
|
2018-10-28 12:12:11 +03:00
|
|
|
Caller *runtime.Frame
|
2016-11-26 06:02:56 +03:00
|
|
|
|
2018-08-28 18:13:29 +03:00
|
|
|
// Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic
|
2014-07-27 05:26:04 +04:00
|
|
|
Message string
|
2016-06-18 16:47:44 +03:00
|
|
|
|
2018-09-07 05:11:16 +03:00
|
|
|
// When formatter is called in entry.log(), a Buffer may be set to entry
|
2016-06-18 16:47:44 +03:00
|
|
|
Buffer *bytes.Buffer
|
2018-09-30 23:51:02 +03:00
|
|
|
|
2019-03-11 13:47:03 +03:00
|
|
|
// Contains the context set by the user. Useful for hook processing etc.
|
|
|
|
Context context.Context
|
|
|
|
|
2018-09-30 23:51:02 +03:00
|
|
|
// err may contain a field formatting error
|
|
|
|
err string
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewEntry(logger *Logger) *Entry {
|
2016-11-30 22:36:48 +03:00
|
|
|
return &Entry{
|
2014-04-23 20:54:53 +04:00
|
|
|
Logger: logger,
|
2016-11-26 06:02:56 +03:00
|
|
|
// Default is three fields, plus one optional. Give a little extra room.
|
|
|
|
Data: make(Fields, 6),
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 17:07:31 +03:00
|
|
|
// Returns the bytes representation of this entry from the formatter.
|
|
|
|
func (entry *Entry) Bytes() ([]byte, error) {
|
|
|
|
return entry.Logger.Formatter.Format(entry)
|
|
|
|
}
|
|
|
|
|
2014-07-27 05:37:06 +04:00
|
|
|
// Returns the string representation from the reader and ultimately the
|
|
|
|
// formatter.
|
2014-03-11 03:22:08 +04:00
|
|
|
func (entry *Entry) String() (string, error) {
|
2019-03-18 17:07:31 +03:00
|
|
|
serialized, err := entry.Bytes()
|
2014-03-11 03:22:08 +04:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2014-03-04 02:33:35 +04:00
|
|
|
}
|
2016-06-18 16:47:44 +03:00
|
|
|
str := string(serialized)
|
|
|
|
return str, nil
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2015-05-19 20:50:55 +03:00
|
|
|
// Add an error as single field (using the key defined in ErrorKey) to the Entry.
|
2015-05-13 14:35:03 +03:00
|
|
|
func (entry *Entry) WithError(err error) *Entry {
|
|
|
|
return entry.WithField(ErrorKey, err)
|
|
|
|
}
|
|
|
|
|
2019-03-11 13:47:03 +03:00
|
|
|
// Add a context to the Entry.
|
|
|
|
func (entry *Entry) WithContext(ctx context.Context) *Entry {
|
2019-11-28 07:03:38 +03:00
|
|
|
dataCopy := make(Fields, len(entry.Data))
|
|
|
|
for k, v := range entry.Data {
|
|
|
|
dataCopy[k] = v
|
|
|
|
}
|
|
|
|
return &Entry{Logger: entry.Logger, Data: dataCopy, Time: entry.Time, err: entry.err, Context: ctx}
|
2019-03-11 13:47:03 +03:00
|
|
|
}
|
|
|
|
|
2014-07-27 05:37:06 +04:00
|
|
|
// Add a single field to the Entry.
|
2014-02-24 04:50:42 +04:00
|
|
|
func (entry *Entry) WithField(key string, value interface{}) *Entry {
|
2014-06-09 19:53:23 +04:00
|
|
|
return entry.WithFields(Fields{key: value})
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2014-07-27 05:37:06 +04:00
|
|
|
// Add a map of fields to the Entry.
|
2014-02-24 04:50:42 +04:00
|
|
|
func (entry *Entry) WithFields(fields Fields) *Entry {
|
2019-10-23 20:43:07 +03:00
|
|
|
entry.Logger.mu.Lock()
|
|
|
|
defer entry.Logger.mu.Unlock()
|
2016-03-15 10:39:40 +03:00
|
|
|
data := make(Fields, len(entry.Data)+len(fields))
|
2014-06-09 19:31:46 +04:00
|
|
|
for k, v := range entry.Data {
|
|
|
|
data[k] = v
|
|
|
|
}
|
2018-12-14 19:01:34 +03:00
|
|
|
fieldErr := entry.err
|
2014-06-09 19:31:46 +04:00
|
|
|
for k, v := range fields {
|
2018-12-05 21:14:19 +03:00
|
|
|
isErrField := false
|
|
|
|
if t := reflect.TypeOf(v); t != nil {
|
|
|
|
switch t.Kind() {
|
|
|
|
case reflect.Func:
|
|
|
|
isErrField = true
|
|
|
|
case reflect.Ptr:
|
|
|
|
isErrField = t.Elem().Kind() == reflect.Func
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isErrField {
|
2018-12-14 19:01:34 +03:00
|
|
|
tmp := fmt.Sprintf("can not add field %q", k)
|
|
|
|
if fieldErr != "" {
|
|
|
|
fieldErr = entry.err + ", " + tmp
|
|
|
|
} else {
|
|
|
|
fieldErr = tmp
|
2018-09-30 23:51:02 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data[k] = v
|
|
|
|
}
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
2019-03-11 13:47:03 +03:00
|
|
|
return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, err: fieldErr, Context: entry.Context}
|
2018-06-29 17:53:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Overrides the time of the Entry.
|
|
|
|
func (entry *Entry) WithTime(t time.Time) *Entry {
|
2019-11-28 07:03:38 +03:00
|
|
|
dataCopy := make(Fields, len(entry.Data))
|
|
|
|
for k, v := range entry.Data {
|
|
|
|
dataCopy[k] = v
|
|
|
|
}
|
|
|
|
return &Entry{Logger: entry.Logger, Data: dataCopy, Time: t, err: entry.err, Context: entry.Context}
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2016-12-01 21:23:00 +03:00
|
|
|
// getPackageName reduces a fully qualified function name to the package name
|
|
|
|
// There really ought to be to be a better way...
|
|
|
|
func getPackageName(f string) string {
|
|
|
|
for {
|
|
|
|
lastPeriod := strings.LastIndex(f, ".")
|
|
|
|
lastSlash := strings.LastIndex(f, "/")
|
|
|
|
if lastPeriod > lastSlash {
|
|
|
|
f = f[:lastPeriod]
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
2016-11-26 06:02:56 +03:00
|
|
|
// getCaller retrieves the name of the first non-logrus calling function
|
2018-10-28 12:12:11 +03:00
|
|
|
func getCaller() *runtime.Frame {
|
2016-12-01 21:23:00 +03:00
|
|
|
|
|
|
|
// cache this package's fully-qualified name
|
2018-10-27 16:21:30 +03:00
|
|
|
callerInitOnce.Do(func() {
|
2019-03-06 16:08:02 +03:00
|
|
|
pcs := make([]uintptr, 2)
|
|
|
|
_ = runtime.Callers(0, pcs)
|
2020-02-27 06:04:36 +03:00
|
|
|
logrusPackage = getPackageName(funcName(pcs))
|
2016-12-01 21:23:00 +03:00
|
|
|
|
|
|
|
// now that we have the cache, we can skip a minimum count of known-logrus functions
|
2019-03-06 16:08:02 +03:00
|
|
|
// XXX this is dubious, the number of frames may vary
|
2016-12-01 21:23:00 +03:00
|
|
|
minimumCallerDepth = knownLogrusFrames
|
2018-10-27 16:21:30 +03:00
|
|
|
})
|
2016-11-26 06:02:56 +03:00
|
|
|
|
2019-03-06 16:08:02 +03:00
|
|
|
// Restrict the lookback frames to avoid runaway lookups
|
|
|
|
pcs := make([]uintptr, maximumCallerDepth)
|
|
|
|
depth := runtime.Callers(minimumCallerDepth, pcs)
|
|
|
|
frames := runtime.CallersFrames(pcs[:depth])
|
|
|
|
|
2018-10-28 12:12:11 +03:00
|
|
|
for f, again := frames.Next(); again; f, again = frames.Next() {
|
|
|
|
pkg := getPackageName(f.Function)
|
2016-11-26 06:02:56 +03:00
|
|
|
|
2016-12-01 21:23:00 +03:00
|
|
|
// If the caller isn't part of this package, we're done
|
2018-10-27 16:21:30 +03:00
|
|
|
if pkg != logrusPackage {
|
2019-10-25 15:49:48 +03:00
|
|
|
return &f //nolint:scopelint
|
2016-11-26 06:02:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got here, we failed to find the caller's context
|
2018-10-28 12:12:11 +03:00
|
|
|
return nil
|
2016-11-26 06:02:56 +03:00
|
|
|
}
|
|
|
|
|
2016-12-01 02:15:38 +03:00
|
|
|
func (entry Entry) HasCaller() (has bool) {
|
|
|
|
return entry.Logger != nil &&
|
|
|
|
entry.Logger.ReportCaller &&
|
2018-10-28 12:12:11 +03:00
|
|
|
entry.Caller != nil
|
2016-12-01 02:15:38 +03:00
|
|
|
}
|
|
|
|
|
2015-08-08 00:29:20 +03:00
|
|
|
// This function is not declared with a pointer value because otherwise
|
|
|
|
// race conditions will occur when using multiple goroutines
|
2015-08-07 03:00:57 +03:00
|
|
|
func (entry Entry) log(level Level, msg string) {
|
2020-03-19 12:32:08 +03:00
|
|
|
entry.Logger.mu.Lock()
|
|
|
|
defer entry.Logger.mu.Unlock()
|
2016-06-18 16:47:44 +03:00
|
|
|
var buffer *bytes.Buffer
|
2018-06-28 23:33:52 +03:00
|
|
|
|
|
|
|
// Default to now, but allow users to override if they want.
|
|
|
|
//
|
|
|
|
// We don't have to worry about polluting future calls to Entry#log()
|
|
|
|
// with this assignment because this function is declared with a
|
|
|
|
// non-pointer receiver.
|
|
|
|
if entry.Time.IsZero() {
|
|
|
|
entry.Time = time.Now()
|
|
|
|
}
|
|
|
|
|
2014-07-27 05:26:04 +04:00
|
|
|
entry.Level = level
|
|
|
|
entry.Message = msg
|
2016-12-01 01:07:10 +03:00
|
|
|
if entry.Logger.ReportCaller {
|
2016-11-29 20:35:34 +03:00
|
|
|
entry.Caller = getCaller()
|
2016-11-26 06:02:56 +03:00
|
|
|
}
|
2014-02-24 04:50:42 +04:00
|
|
|
|
2018-01-22 18:35:26 +03:00
|
|
|
entry.fireHooks()
|
|
|
|
|
2016-06-18 16:47:44 +03:00
|
|
|
buffer = bufferPool.Get().(*bytes.Buffer)
|
|
|
|
buffer.Reset()
|
|
|
|
defer bufferPool.Put(buffer)
|
|
|
|
entry.Buffer = buffer
|
2018-01-22 18:35:26 +03:00
|
|
|
|
|
|
|
entry.write()
|
|
|
|
|
2016-06-18 16:47:44 +03:00
|
|
|
entry.Buffer = nil
|
2018-01-22 18:35:26 +03:00
|
|
|
|
|
|
|
// To avoid Entry#log() returning a value that only would make sense for
|
|
|
|
// panic() to use in Entry#Panic(), we avoid the allocation by checking
|
|
|
|
// directly here.
|
|
|
|
if level <= PanicLevel {
|
|
|
|
panic(&entry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-30 12:50:59 +03:00
|
|
|
func (entry *Entry) fireHooks() {
|
2018-01-22 18:35:26 +03:00
|
|
|
entry.Logger.mu.Lock()
|
|
|
|
defer entry.Logger.mu.Unlock()
|
2018-05-30 12:50:59 +03:00
|
|
|
err := entry.Logger.Hooks.Fire(entry.Level, entry)
|
2018-01-22 18:35:26 +03:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) write() {
|
|
|
|
entry.Logger.mu.Lock()
|
|
|
|
defer entry.Logger.mu.Unlock()
|
2018-02-05 22:44:11 +03:00
|
|
|
serialized, err := entry.Logger.Formatter.Format(entry)
|
2014-02-24 04:50:42 +04:00
|
|
|
if err != nil {
|
2014-09-17 04:19:42 +04:00
|
|
|
fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err)
|
2019-09-06 02:09:16 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if _, err = entry.Logger.Out.Write(serialized); err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err)
|
2014-09-24 04:05:07 +04:00
|
|
|
}
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2018-11-15 22:34:22 +03:00
|
|
|
func (entry *Entry) Log(level Level, args ...interface{}) {
|
|
|
|
if entry.Logger.IsLevelEnabled(level) {
|
|
|
|
entry.log(level, fmt.Sprint(args...))
|
2017-10-20 15:40:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 22:34:22 +03:00
|
|
|
func (entry *Entry) Trace(args ...interface{}) {
|
|
|
|
entry.Log(TraceLevel, args...)
|
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Debug(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Log(DebugLevel, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Print(args ...interface{}) {
|
|
|
|
entry.Info(args...)
|
2014-03-11 03:59:18 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Info(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Log(InfoLevel, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Warn(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Log(WarnLevel, args...)
|
2014-03-11 03:22:08 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Warning(args ...interface{}) {
|
|
|
|
entry.Warn(args...)
|
2015-01-13 01:20:11 +03:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Error(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Log(ErrorLevel, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Fatal(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Log(FatalLevel, args...)
|
2018-10-06 13:08:19 +03:00
|
|
|
entry.Logger.Exit(1)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Panic(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Log(PanicLevel, args...)
|
2014-02-24 15:34:12 +04:00
|
|
|
panic(fmt.Sprint(args...))
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry Printf family functions
|
|
|
|
|
2018-11-15 22:34:22 +03:00
|
|
|
func (entry *Entry) Logf(level Level, format string, args ...interface{}) {
|
2019-02-06 22:51:07 +03:00
|
|
|
if entry.Logger.IsLevelEnabled(level) {
|
|
|
|
entry.Log(level, fmt.Sprintf(format, args...))
|
|
|
|
}
|
2018-11-15 22:34:22 +03:00
|
|
|
}
|
|
|
|
|
2017-10-20 15:40:54 +03:00
|
|
|
func (entry *Entry) Tracef(format string, args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logf(TraceLevel, format, args...)
|
2017-10-20 15:40:54 +03:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Debugf(format string, args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logf(DebugLevel, format, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Infof(format string, args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logf(InfoLevel, format, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Printf(format string, args ...interface{}) {
|
|
|
|
entry.Infof(format, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Warnf(format string, args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logf(WarnLevel, format, args...)
|
2014-03-11 03:22:08 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Warningf(format string, args ...interface{}) {
|
|
|
|
entry.Warnf(format, args...)
|
2014-03-11 03:22:08 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Errorf(format string, args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logf(ErrorLevel, format, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Fatalf(format string, args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logf(FatalLevel, format, args...)
|
2018-10-06 13:08:19 +03:00
|
|
|
entry.Logger.Exit(1)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Panicf(format string, args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logf(PanicLevel, format, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry Println family functions
|
|
|
|
|
2018-11-15 22:34:22 +03:00
|
|
|
func (entry *Entry) Logln(level Level, args ...interface{}) {
|
|
|
|
if entry.Logger.IsLevelEnabled(level) {
|
|
|
|
entry.Log(level, entry.sprintlnn(args...))
|
2017-10-20 15:40:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 22:34:22 +03:00
|
|
|
func (entry *Entry) Traceln(args ...interface{}) {
|
|
|
|
entry.Logln(TraceLevel, args...)
|
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Debugln(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logln(DebugLevel, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Infoln(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logln(InfoLevel, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Println(args ...interface{}) {
|
|
|
|
entry.Infoln(args...)
|
2014-03-11 03:22:08 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Warnln(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logln(WarnLevel, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Warningln(args ...interface{}) {
|
|
|
|
entry.Warnln(args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2015-09-08 03:47:46 +03:00
|
|
|
func (entry *Entry) Errorln(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logln(ErrorLevel, args...)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2014-03-11 03:22:08 +04:00
|
|
|
func (entry *Entry) Fatalln(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logln(FatalLevel, args...)
|
2018-10-06 13:08:19 +03:00
|
|
|
entry.Logger.Exit(1)
|
2014-02-24 04:50:42 +04:00
|
|
|
}
|
|
|
|
|
2014-03-11 03:22:08 +04:00
|
|
|
func (entry *Entry) Panicln(args ...interface{}) {
|
2018-11-15 22:34:22 +03:00
|
|
|
entry.Logln(PanicLevel, args...)
|
2014-05-04 03:51:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sprintlnn => Sprint no newline. This is to get the behavior of how
|
|
|
|
// fmt.Sprintln where spaces are always added between operands, regardless of
|
|
|
|
// their type. Instead of vendoring the Sprintln implementation to spare a
|
|
|
|
// string allocation, we do the simplest thing.
|
|
|
|
func (entry *Entry) sprintlnn(args ...interface{}) string {
|
|
|
|
msg := fmt.Sprintln(args...)
|
|
|
|
return msg[:len(msg)-1]
|
2019-02-27 15:02:20 +03:00
|
|
|
}
|