log

package module
v1.1.11 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 14 Imported by: 1

Documentation

Overview

Package log provides a global logger with zerolog.

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	LogLevel: "info",
	JSON:     false,
	Concise:  false,
	Tags:     nil,
}

Logger is the global logger.

Functions

func Configure added in v1.0.4

func Configure(opts Options)

Configure will set new global/default options for the httplog and behaviour of underlying zerolog pkg and its global logger.

func Debug

func Debug(entry string)

Debug

func Debugf

func Debugf(format string, v ...interface{})

Debugf

func Error

func Error(entry string)

Error

func Errorf

func Errorf(format string, v ...interface{})

Errorf

func Fatal

func Fatal(entry string)

Fatal

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf

func Handler added in v1.0.4

func Handler(logger zerolog.Logger) func(next http.Handler) http.Handler

func Info

func Info(entry string)

Info

func Infof

func Infof(format string, v ...interface{})

Infof

func LogEntry added in v1.0.4

func LogEntry(ctx context.Context) zerolog.Logger

func LogEntrySetField added in v1.0.4

func LogEntrySetField(ctx context.Context, key, value string)

func LogEntrySetFields added in v1.0.4

func LogEntrySetFields(ctx context.Context, fields map[string]interface{})

func NewStd

func NewStd() *stdlog.Logger

NewStd creates new standart logger with zerolog as output

func Print

func Print(v ...interface{})

Print sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Print.

func Printf

func Printf(format string, v ...interface{})

Printf sends a log event using debug level and no extra field. Arguments are handled in the manner of fmt.Printf.

func RequestLogger added in v1.0.4

func RequestLogger(logger zerolog.Logger) func(next http.Handler) http.Handler

RequestLogger is an http middleware to log http requests and responses.

NOTE: for simplicty, RequestLogger automatically makes use of the chi RequestID and Recoverer middleware.

func Warn

func Warn(entry string)

Warn

func Warnf

func Warnf(format string, v ...interface{})

Warnf

func WithCaller

func WithCaller(name string)

WithCaller adds caller name to the logs

Types

type Options added in v1.0.4

type Options struct {
	// LogLevel defines the minimum level of severity that app should log.
	//
	// Must be one of: ["trace", "debug", "info", "warn", "error", "critical"]
	LogLevel string

	// JSON enables structured logging output in json. Make sure to enable this
	// in production mode so log aggregators can receive data in parsable format.
	//
	// In local development mode, its appropriate to set this value to false to
	// receive pretty output and stacktraces to stdout.
	JSON bool

	// Concise mode includes fewer log details during the request flow. For example
	// exluding details like request content length, user-agent and other details.
	// This is useful if during development your console is too noisy.
	Concise bool

	// Tags are additional fields included at the root level of all logs.
	// These can be useful for example the commit hash of a build, or an environment
	// name like prod/stg/dev
	Tags map[string]string
}

type RequestLoggerEntry added in v1.0.4

type RequestLoggerEntry struct {
	Logger zerolog.Logger
	// contains filtered or unexported fields
}

func (*RequestLoggerEntry) Panic added in v1.0.4

func (l *RequestLoggerEntry) Panic(v interface{}, stack []byte)

func (*RequestLoggerEntry) Write added in v1.0.4

func (l *RequestLoggerEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{})

Jump to

Keyboard shortcuts

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