log

package
v0.0.0-...-58b1d68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DPanic

func DPanic(args ...interface{})

DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)

func DPanicf

func DPanicf(template string, args ...interface{})

DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)

func Debug

func Debug(args ...interface{})

Debug uses fmt.Sprint to construct and log a message.

func Debugf

func Debugf(template string, args ...interface{})

Debugf uses fmt.Sprintf to log a templated message.

func Error

func Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message.

func Errorf

func Errorf(template string, args ...interface{})

Errorf uses fmt.Sprintf to log a templated message.

func Fatal

func Fatal(args ...interface{})

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.

func Fatalf

func Fatalf(template string, args ...interface{})

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func Info

func Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message.

func Infof

func Infof(template string, args ...interface{})

Infof uses fmt.Sprintf to log a templated message.

func Named

func Named(name string)

Named adds a sub-scope to the logger's name. See Logger.Named for details. Set it to the service name to find the logs related to service easily.

func Panic

func Panic(args ...interface{})

Panic uses fmt.Sprint to construct and log a message, then panics.

func Panicf

func Panicf(template string, args ...interface{})

Panicf uses fmt.Sprintf to log a templated message, then panics.

func SetEncoding

func SetEncoding(encodingFormat LogEncodingFormat)

SetEncoding sets encoding for the log, valid formats are json and console.

func SetLogLevel

func SetLogLevel(logLevel string)

SetLogLevel creates new logger with new log level. If logLevel is not valid, then default log level will be set to 'debug'.

func Warn

func Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message.

func Warnf

func Warnf(template string, args ...interface{})

Warnf uses fmt.Sprintf to log a templated message.

Types

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

func With

func With(args ...interface{}) *Entry

With adds a variadic number of fields to the logging context. It accepts a mix of strongly-typed Field objects and loosely-typed key-value pairs. When processing pairs, the first element of the pair is used as the field key and the second as the field value.

For example,

 sugaredLogger.With(
   "hello", "world",
   "failure", errors.New("oh no"),
   Stack(),
   "count", 42,
   "user", User{Name: "alice"},
)

is the equivalent of

unsugared.With(
  String("hello", "world"),
  String("failure", "oh no"),
  Stack(),
  Int("count", 42),
  Object("user", User{Name: "alice"}),
)

Note that the keys in key-value pairs should be strings. In development, passing a non-string key panics. In production, the logger is more forgiving: a separate error is logged, but the key-value pair is skipped and execution continues. Passing an orphaned key triggers similar behavior: panics in development and errors in production.

func WithContext

func WithContext(c context.Context) *Entry

WithContext add context tag with context value to the log.

func WithError

func WithError(err error) *Entry

WithError add error tag with error value to the log.

func WithTime

func WithTime(t time.Time) *Entry

WithTime add time tag with time value to the log.

func (*Entry) DPanic

func (e *Entry) DPanic(args ...interface{})

DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)

func (*Entry) DPanicf

func (e *Entry) DPanicf(template string, args ...interface{})

DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)

func (*Entry) DPanicw

func (e *Entry) DPanicw(msg string, keysAndValues ...interface{})

DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.

func (*Entry) Debug

func (e *Entry) Debug(args ...interface{})

Debug uses fmt.Sprint to construct and log a message.

func (*Entry) Debugf

func (e *Entry) Debugf(template string, args ...interface{})

Debugf uses fmt.Sprintf to log a templated message.

func (*Entry) Debugw

func (e *Entry) Debugw(msg string, keysAndValues ...interface{})

Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

When debug-level logging is disabled, this is much faster than

s.With(keysAndValues).Debug(msg)

func (*Entry) Error

func (e *Entry) Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message.

func (*Entry) Errorf

func (e *Entry) Errorf(template string, args ...interface{})

Errorf uses fmt.Sprintf to log a templated message.

func (*Entry) Errorw

func (e *Entry) Errorw(msg string, keysAndValues ...interface{})

Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*Entry) Fatal

func (e *Entry) Fatal(args ...interface{})

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.

func (*Entry) Fatalf

func (e *Entry) Fatalf(template string, args ...interface{})

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func (*Entry) Fatalw

func (e *Entry) Fatalw(msg string, keysAndValues ...interface{})

Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.

func (*Entry) Info

func (e *Entry) Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message.

func (*Entry) Infof

func (e *Entry) Infof(template string, args ...interface{})

Infof uses fmt.Sprintf to log a templated message.

func (*Entry) Infow

func (e *Entry) Infow(msg string, keysAndValues ...interface{})

Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*Entry) Panic

func (e *Entry) Panic(args ...interface{})

Panic uses fmt.Sprint to construct and log a message, then panics.

func (*Entry) Panicf

func (e *Entry) Panicf(template string, args ...interface{})

Panicf uses fmt.Sprintf to log a templated message, then panics.

func (*Entry) Panicw

func (e *Entry) Panicw(msg string, keysAndValues ...interface{})

Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.

func (*Entry) Warn

func (e *Entry) Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message.

func (*Entry) Warnf

func (e *Entry) Warnf(template string, args ...interface{})

Warnf uses fmt.Sprintf to log a templated message.

func (*Entry) Warnw

func (e *Entry) Warnw(msg string, keysAndValues ...interface{})

Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*Entry) With

func (e *Entry) With(args ...interface{}) *Entry

With adds a variadic number of fields to the logging context. It accepts a mix of strongly-typed Field objects and loosely-typed key-value pairs. When processing pairs, the first element of the pair is used as the field key and the second as the field value.

For example,

 sugaredLogger.With(
   "hello", "world",
   "failure", errors.New("oh no"),
   Stack(),
   "count", 42,
   "user", User{Name: "alice"},
)

is the equivalent of

unsugared.With(
  String("hello", "world"),
  String("failure", "oh no"),
  Stack(),
  Int("count", 42),
  Object("user", User{Name: "alice"}),
)

Note that the keys in key-value pairs should be strings. In development, passing a non-string key panics. In production, the logger is more forgiving: a separate error is logged, but the key-value pair is skipped and execution continues. Passing an orphaned key triggers similar behavior: panics in development and errors in production.

func (*Entry) WithContext

func (e *Entry) WithContext(c context.Context) *Entry

WithContext add context tag with context value to the log.

func (*Entry) WithError

func (e *Entry) WithError(err error) *Entry

WithError add error tag with error value to the log.

func (*Entry) WithTime

func (e *Entry) WithTime(t time.Time) *Entry

WithTime add time tag with time value to the log.

type LogEncodingFormat

type LogEncodingFormat string
const (
	EncodingConsoleFormat LogEncodingFormat = "console"
	EncodingJsonFormat    LogEncodingFormat = "json"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL