2017-04-17 18:08:24 -04:00
|
|
|
package logrus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2019-04-04 11:46:51 -04:00
|
|
|
"context"
|
2017-04-17 18:08:24 -04:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2019-04-03 15:06:12 -04:00
|
|
|
"reflect"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
2017-04-17 18:08:24 -04:00
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
var (
|
|
|
|
|
|
|
|
// qualified package name, cached at first use
|
|
|
|
logrusPackage string
|
|
|
|
|
|
|
|
// Positions in the call stack when tracing to report the calling method
|
|
|
|
minimumCallerDepth int
|
|
|
|
|
|
|
|
// Used for caller information initialisation
|
|
|
|
callerInitOnce sync.Once
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
maximumCallerDepth int = 25
|
|
|
|
knownLogrusFrames int = 4
|
|
|
|
)
|
2017-04-17 18:08:24 -04:00
|
|
|
|
|
|
|
func init() {
|
2019-04-03 15:06:12 -04:00
|
|
|
// start at the bottom of the stack before the package-name cache is primed
|
|
|
|
minimumCallerDepth = 1
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Defines the key when adding errors using WithError.
|
|
|
|
var ErrorKey = "error"
|
|
|
|
|
|
|
|
// An entry is the final or intermediate Logrus logging entry. It contains all
|
2019-04-03 15:06:12 -04: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.
|
2017-04-17 18:08:24 -04:00
|
|
|
type Entry struct {
|
|
|
|
Logger *Logger
|
|
|
|
|
|
|
|
// Contains all the fields set by the user.
|
|
|
|
Data Fields
|
|
|
|
|
|
|
|
// Time at which the log entry was created
|
|
|
|
Time time.Time
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
// Level the log entry was logged at: Trace, Debug, Info, Warn, Error, Fatal or Panic
|
2017-09-29 09:29:30 -04:00
|
|
|
// This field will be set on entry firing and the value will be equal to the one in Logger struct field.
|
2017-04-17 18:08:24 -04:00
|
|
|
Level Level
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
// Calling method, with package name
|
|
|
|
Caller *runtime.Frame
|
|
|
|
|
|
|
|
// Message passed to Trace, Debug, Info, Warn, Error, Fatal or Panic
|
2017-04-17 18:08:24 -04:00
|
|
|
Message string
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
// When formatter is called in entry.log(), a Buffer may be set to entry
|
2017-04-17 18:08:24 -04:00
|
|
|
Buffer *bytes.Buffer
|
2019-04-03 15:06:12 -04:00
|
|
|
|
2019-04-04 11:46:51 -04:00
|
|
|
// Contains the context set by the user. Useful for hook processing etc.
|
|
|
|
Context context.Context
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
// err may contain a field formatting error
|
|
|
|
err string
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewEntry(logger *Logger) *Entry {
|
|
|
|
return &Entry{
|
|
|
|
Logger: logger,
|
2019-04-03 15:06:12 -04:00
|
|
|
// Default is three fields, plus one optional. Give a little extra room.
|
|
|
|
Data: make(Fields, 6),
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-09 13:44:50 -04:00
|
|
|
func (entry *Entry) Dup() *Entry {
|
|
|
|
data := make(Fields, len(entry.Data))
|
|
|
|
for k, v := range entry.Data {
|
|
|
|
data[k] = v
|
|
|
|
}
|
|
|
|
return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, Context: entry.Context, err: entry.err}
|
|
|
|
}
|
|
|
|
|
2020-04-29 06:29:57 -04:00
|
|
|
// Returns the bytes representation of this entry from the formatter.
|
|
|
|
func (entry *Entry) Bytes() ([]byte, error) {
|
|
|
|
return entry.Logger.Formatter.Format(entry)
|
|
|
|
}
|
|
|
|
|
2017-04-17 18:08:24 -04:00
|
|
|
// Returns the string representation from the reader and ultimately the
|
|
|
|
// formatter.
|
|
|
|
func (entry *Entry) String() (string, error) {
|
2020-04-29 06:29:57 -04:00
|
|
|
serialized, err := entry.Bytes()
|
2017-04-17 18:08:24 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
str := string(serialized)
|
|
|
|
return str, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add an error as single field (using the key defined in ErrorKey) to the Entry.
|
|
|
|
func (entry *Entry) WithError(err error) *Entry {
|
|
|
|
return entry.WithField(ErrorKey, err)
|
|
|
|
}
|
|
|
|
|
2019-04-04 11:46:51 -04:00
|
|
|
// Add a context to the Entry.
|
|
|
|
func (entry *Entry) WithContext(ctx context.Context) *Entry {
|
2020-04-29 06:29:57 -04: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-04-04 11:46:51 -04:00
|
|
|
}
|
|
|
|
|
2017-04-17 18:08:24 -04:00
|
|
|
// Add a single field to the Entry.
|
|
|
|
func (entry *Entry) WithField(key string, value interface{}) *Entry {
|
|
|
|
return entry.WithFields(Fields{key: value})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a map of fields to the Entry.
|
|
|
|
func (entry *Entry) WithFields(fields Fields) *Entry {
|
|
|
|
data := make(Fields, len(entry.Data)+len(fields))
|
|
|
|
for k, v := range entry.Data {
|
|
|
|
data[k] = v
|
|
|
|
}
|
2019-04-03 15:06:12 -04:00
|
|
|
fieldErr := entry.err
|
2017-04-17 18:08:24 -04:00
|
|
|
for k, v := range fields {
|
2019-04-03 15:06:12 -04:00
|
|
|
isErrField := false
|
|
|
|
if t := reflect.TypeOf(v); t != nil {
|
2021-08-09 13:44:50 -04:00
|
|
|
switch {
|
|
|
|
case t.Kind() == reflect.Func, t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Func:
|
2019-04-03 15:06:12 -04:00
|
|
|
isErrField = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if isErrField {
|
|
|
|
tmp := fmt.Sprintf("can not add field %q", k)
|
|
|
|
if fieldErr != "" {
|
|
|
|
fieldErr = entry.err + ", " + tmp
|
|
|
|
} else {
|
|
|
|
fieldErr = tmp
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
data[k] = v
|
|
|
|
}
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
2019-04-04 11:46:51 -04:00
|
|
|
return &Entry{Logger: entry.Logger, Data: data, Time: entry.Time, err: fieldErr, Context: entry.Context}
|
2018-07-25 08:16:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Overrides the time of the Entry.
|
|
|
|
func (entry *Entry) WithTime(t time.Time) *Entry {
|
2020-04-29 06:29:57 -04: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}
|
2019-04-03 15:06:12 -04: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
|
|
|
|
}
|
|
|
|
|
|
|
|
// getCaller retrieves the name of the first non-logrus calling function
|
|
|
|
func getCaller() *runtime.Frame {
|
|
|
|
// cache this package's fully-qualified name
|
|
|
|
callerInitOnce.Do(func() {
|
2020-04-29 06:29:57 -04:00
|
|
|
pcs := make([]uintptr, maximumCallerDepth)
|
2019-04-04 11:46:51 -04:00
|
|
|
_ = runtime.Callers(0, pcs)
|
2019-04-03 15:06:12 -04:00
|
|
|
|
2020-04-29 06:29:57 -04:00
|
|
|
// dynamic get the package name and the minimum caller depth
|
|
|
|
for i := 0; i < maximumCallerDepth; i++ {
|
|
|
|
funcName := runtime.FuncForPC(pcs[i]).Name()
|
|
|
|
if strings.Contains(funcName, "getCaller") {
|
|
|
|
logrusPackage = getPackageName(funcName)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
minimumCallerDepth = knownLogrusFrames
|
|
|
|
})
|
|
|
|
|
2019-04-04 11:46:51 -04:00
|
|
|
// Restrict the lookback frames to avoid runaway lookups
|
|
|
|
pcs := make([]uintptr, maximumCallerDepth)
|
|
|
|
depth := runtime.Callers(minimumCallerDepth, pcs)
|
|
|
|
frames := runtime.CallersFrames(pcs[:depth])
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
for f, again := frames.Next(); again; f, again = frames.Next() {
|
|
|
|
pkg := getPackageName(f.Function)
|
|
|
|
|
|
|
|
// If the caller isn't part of this package, we're done
|
|
|
|
if pkg != logrusPackage {
|
2020-04-29 06:29:57 -04:00
|
|
|
return &f //nolint:scopelint
|
2019-04-03 15:06:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we got here, we failed to find the caller's context
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry Entry) HasCaller() (has bool) {
|
|
|
|
return entry.Logger != nil &&
|
|
|
|
entry.Logger.ReportCaller &&
|
|
|
|
entry.Caller != nil
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 13:44:50 -04:00
|
|
|
func (entry *Entry) log(level Level, msg string) {
|
2017-04-17 18:08:24 -04:00
|
|
|
var buffer *bytes.Buffer
|
2018-07-25 08:16:41 -04:00
|
|
|
|
2021-08-09 13:44:50 -04:00
|
|
|
newEntry := entry.Dup()
|
|
|
|
|
|
|
|
if newEntry.Time.IsZero() {
|
|
|
|
newEntry.Time = time.Now()
|
2018-07-25 08:16:41 -04:00
|
|
|
}
|
|
|
|
|
2021-08-09 13:44:50 -04:00
|
|
|
newEntry.Level = level
|
|
|
|
newEntry.Message = msg
|
|
|
|
|
|
|
|
newEntry.Logger.mu.Lock()
|
|
|
|
reportCaller := newEntry.Logger.ReportCaller
|
2022-11-17 04:59:56 -05:00
|
|
|
bufPool := newEntry.getBufferPool()
|
2021-08-09 13:44:50 -04:00
|
|
|
newEntry.Logger.mu.Unlock()
|
|
|
|
|
|
|
|
if reportCaller {
|
|
|
|
newEntry.Caller = getCaller()
|
2019-04-03 15:06:12 -04:00
|
|
|
}
|
2017-04-17 18:08:24 -04:00
|
|
|
|
2021-08-09 13:44:50 -04:00
|
|
|
newEntry.fireHooks()
|
2022-11-17 04:59:56 -05:00
|
|
|
buffer = bufPool.Get()
|
2020-09-30 07:42:17 -04:00
|
|
|
defer func() {
|
2021-08-09 13:44:50 -04:00
|
|
|
newEntry.Buffer = nil
|
2022-11-17 04:59:56 -05:00
|
|
|
buffer.Reset()
|
|
|
|
bufPool.Put(buffer)
|
2020-09-30 07:42:17 -04:00
|
|
|
}()
|
2017-04-17 18:08:24 -04:00
|
|
|
buffer.Reset()
|
2021-08-09 13:44:50 -04:00
|
|
|
newEntry.Buffer = buffer
|
2018-07-25 08:16:41 -04:00
|
|
|
|
2021-08-09 13:44:50 -04:00
|
|
|
newEntry.write()
|
2018-07-25 08:16:41 -04:00
|
|
|
|
2021-08-09 13:44:50 -04:00
|
|
|
newEntry.Buffer = nil
|
2018-07-25 08:16:41 -04: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 {
|
2021-08-09 13:44:50 -04:00
|
|
|
panic(newEntry)
|
2018-07-25 08:16:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 04:59:56 -05:00
|
|
|
func (entry *Entry) getBufferPool() (pool BufferPool) {
|
|
|
|
if entry.Logger.BufferPool != nil {
|
|
|
|
return entry.Logger.BufferPool
|
|
|
|
}
|
|
|
|
return bufferPool
|
|
|
|
}
|
|
|
|
|
2018-07-25 08:16:41 -04:00
|
|
|
func (entry *Entry) fireHooks() {
|
2021-08-09 13:44:50 -04:00
|
|
|
var tmpHooks LevelHooks
|
2018-07-25 08:16:41 -04:00
|
|
|
entry.Logger.mu.Lock()
|
2021-08-09 13:44:50 -04:00
|
|
|
tmpHooks = make(LevelHooks, len(entry.Logger.Hooks))
|
|
|
|
for k, v := range entry.Logger.Hooks {
|
|
|
|
tmpHooks[k] = v
|
|
|
|
}
|
|
|
|
entry.Logger.mu.Unlock()
|
|
|
|
|
|
|
|
err := tmpHooks.Fire(entry.Level, entry)
|
2018-07-25 08:16:41 -04:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) write() {
|
2022-11-17 04:59:56 -05:00
|
|
|
entry.Logger.mu.Lock()
|
|
|
|
defer entry.Logger.mu.Unlock()
|
2019-04-03 15:06:12 -04:00
|
|
|
serialized, err := entry.Logger.Formatter.Format(entry)
|
2017-04-17 18:08:24 -04:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err)
|
2020-04-29 06:29:57 -04:00
|
|
|
return
|
|
|
|
}
|
2021-08-09 13:44:50 -04:00
|
|
|
if _, err := entry.Logger.Out.Write(serialized); err != nil {
|
2020-04-29 06:29:57 -04:00
|
|
|
fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 04:59:56 -05:00
|
|
|
// Log will log a message at the level given as parameter.
|
|
|
|
// Warning: using Log at Panic or Fatal level will not respectively Panic nor Exit.
|
|
|
|
// For this behaviour Entry.Panic or Entry.Fatal should be used instead.
|
2019-04-03 15:06:12 -04:00
|
|
|
func (entry *Entry) Log(level Level, args ...interface{}) {
|
|
|
|
if entry.Logger.IsLevelEnabled(level) {
|
|
|
|
entry.log(level, fmt.Sprint(args...))
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
func (entry *Entry) Trace(args ...interface{}) {
|
|
|
|
entry.Log(TraceLevel, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Debug(args ...interface{}) {
|
|
|
|
entry.Log(DebugLevel, args...)
|
|
|
|
}
|
|
|
|
|
2017-04-17 18:08:24 -04:00
|
|
|
func (entry *Entry) Print(args ...interface{}) {
|
|
|
|
entry.Info(args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Info(args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Log(InfoLevel, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Warn(args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Log(WarnLevel, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Warning(args ...interface{}) {
|
|
|
|
entry.Warn(args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Error(args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Log(ErrorLevel, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Fatal(args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Log(FatalLevel, args...)
|
|
|
|
entry.Logger.Exit(1)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Panic(args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Log(PanicLevel, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry Printf family functions
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
func (entry *Entry) Logf(level Level, format string, args ...interface{}) {
|
2019-04-04 11:46:51 -04:00
|
|
|
if entry.Logger.IsLevelEnabled(level) {
|
|
|
|
entry.Log(level, fmt.Sprintf(format, args...))
|
|
|
|
}
|
2019-04-03 15:06:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Tracef(format string, args ...interface{}) {
|
|
|
|
entry.Logf(TraceLevel, format, args...)
|
|
|
|
}
|
|
|
|
|
2017-04-17 18:08:24 -04:00
|
|
|
func (entry *Entry) Debugf(format string, args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logf(DebugLevel, format, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Infof(format string, args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logf(InfoLevel, format, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Printf(format string, args ...interface{}) {
|
|
|
|
entry.Infof(format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Warnf(format string, args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logf(WarnLevel, format, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Warningf(format string, args ...interface{}) {
|
|
|
|
entry.Warnf(format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Errorf(format string, args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logf(ErrorLevel, format, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Fatalf(format string, args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logf(FatalLevel, format, args...)
|
|
|
|
entry.Logger.Exit(1)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Panicf(format string, args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logf(PanicLevel, format, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry Println family functions
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
func (entry *Entry) Logln(level Level, args ...interface{}) {
|
|
|
|
if entry.Logger.IsLevelEnabled(level) {
|
|
|
|
entry.Log(level, entry.sprintlnn(args...))
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-03 15:06:12 -04:00
|
|
|
func (entry *Entry) Traceln(args ...interface{}) {
|
|
|
|
entry.Logln(TraceLevel, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Debugln(args ...interface{}) {
|
|
|
|
entry.Logln(DebugLevel, args...)
|
|
|
|
}
|
|
|
|
|
2017-04-17 18:08:24 -04:00
|
|
|
func (entry *Entry) Infoln(args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logln(InfoLevel, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Println(args ...interface{}) {
|
|
|
|
entry.Infoln(args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Warnln(args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logln(WarnLevel, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Warningln(args ...interface{}) {
|
|
|
|
entry.Warnln(args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Errorln(args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logln(ErrorLevel, args...)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Fatalln(args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logln(FatalLevel, args...)
|
|
|
|
entry.Logger.Exit(1)
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (entry *Entry) Panicln(args ...interface{}) {
|
2019-04-03 15:06:12 -04:00
|
|
|
entry.Logln(PanicLevel, args...)
|
2017-04-17 18:08:24 -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]
|
|
|
|
}
|