Categorygithub.com/mdouchement/logger
modulepackage
0.0.0-20240212102128-d36bb9ae9641
Repository: https://github.com/mdouchement/logger.git
Documentation: pkg.go.dev

# README

Logger

A simple prefixer logger that can wrap several backends. The formatters/handlers from this repository must be used in order to make prefix work.

Interface

type Logger interface {
	WithPrefix(prefix string) Logger
	WithPrefixf(format string, args ...interface{}) Logger
	WithField(key string, value interface{}) Logger
	WithError(error error) Logger
	WithFields(fields map[string]interface{}) Logger
	//
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	Warn(args ...interface{})
	Warnf(format string, args ...interface{})
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	//
	Print(args ...interface{})
	Printf(format string, args ...interface{})
	Println(args ...interface{})
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Fatalln(args ...interface{})
	Panic(args ...interface{})
	Panicf(format string, args ...interface{})
	Panicln(args ...interface{})
}

Backends

Helpers

  • type M map[string]interface{} used as a shorthand for a map of interfaces used by WithFields method
  • func WithLogger(ctx context.Context, l Logger) context.Context to embeds the logger inside a context
  • func LogWith(ctx context.Context) Logger to extract a logger from a context

License

MIT

Contributing

All PRs are welcome.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

# Packages

No description provided by the author

# Functions

LogWith returns the logger extracted from the context.
NewBufferGELF returns a new BufferGELF.
NewNullLogger returns null Logger.
NewSlogGELFHandler returns a new SlogGELFHandler.
NewSlogTextHandler returns a new SlogTextHandler.
ParseSlogLevel takes a string level and returns the slog.Level constant.
WithLogger returns a new context that embeds the given logger.
WrapLogrus returns Logger based on Logrus backend.
WrapSlog returns Logger based on log/slog backend.
WrapSlogHandler returns Logger based on log/slog's handler backend.

# Constants

KeyPrefix is used to tell that en given attr/field is a prefix.
LoggerKey is the storing key used for storing and retrieve the logger from a context.

# Structs

A BufferGELF is a buffer used to build GELF payload.
No description provided by the author
A LogrusGELFFormatter is GELF formatter for Logrus.
A LogrusTextFormatter is pretty printer for Logrus.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

A Logger is the interface used in this package for logging, so that any backend can be plugged in.

# Type aliases

A ContextKey is used to add data into a context.Context.
M defines a generic map of type `map[string]interface{}`.