logging

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogConsolePretty string = "consolepretty"
	LogJSON          string = "json"
	LogDiscard       string = "discard"
	LogJournald      string = "journald"
)

Different types of logging

Variables

View Source
var LogFormatsCommandLine = []string{LogJSON, LogConsolePretty, LogDiscard}
View Source
var LogLevels = []string{"trace", "debug", "info", "warn", "error", "fatal", "panic"}
View Source
var LogRoutes = [2]Route{
	{"GET", "/loglevel", LogLevelGet},
	{"POST", "/loglevel", LogLevelSet},
}

Functions

func GetLogLevel

func GetLogLevel() string

GetLogLevel returns the current global log level.

func GetRequestID

func GetRequestID(r *http.Request) string

GetRequestID returns the request ID.

func LogLevelGet

func LogLevelGet(w http.ResponseWriter, r *http.Request)

LogLevelGet - Handle loglevel GET request

func LogLevelSet

func LogLevelSet(w http.ResponseWriter, r *http.Request)

LogLevelSet - Handle loglevel POST request

func LoggerWithTopic

func LoggerWithTopic(topic string) *zerolog.Logger

LoggerWithTopic creates a top-level logger with topic field.

func SetLogFile

func SetLogFile(filename string) (*os.File, error)

SetLogFile creates a new global logger that writes to a file.

func SetLogLevel

func SetLogLevel(level string) error

SetLogLevel sets the global log level.

func SubLoggerWithRequestID

func SubLoggerWithRequestID(r *http.Request) *zerolog.Logger

SubLoggerWithRequestID creates a new sub-logger with request_id field.

func SubLoggerWithRequestIDAndTopic

func SubLoggerWithRequestIDAndTopic(r *http.Request, topic string) *zerolog.Logger

SubLoggerWithRequestIDAndTopic creates a new sub-logger with request_id and topic fields.

func SubLoggerWithSpecificLevel

func SubLoggerWithSpecificLevel(lg *zerolog.Logger, level string) *zerolog.Logger

SubLogger creates a new sub-logger with a specific log level.

func SubLoggerWithString

func SubLoggerWithString(key string, val string) *zerolog.Logger

SubLogger create a new sub-logger with a specific key, value field.

func SubLoggerWithTopic

func SubLoggerWithTopic(lg *zerolog.Logger, topic string) *zerolog.Logger

SubLoggerWithTopic creates sub-logger with topic field.

func ZerologMiddleware

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

ZerologMiddleware logs access and converts panic to stack traces.

Types

type Logger

type Logger = zerolog.Logger

func GetGlobalLogger

func GetGlobalLogger() *Logger

GetGlobalLogger returns the global logger instance.

func InitZerolog

func InitZerolog(level string, logFormat string) (*Logger, error)

InitZerolog initializes the global zerolog logger.

level and logLevel determine where the logs go and what format is used.

type Route

type Route struct {
	Method  string
	Path    string
	Handler http.HandlerFunc
}

Jump to

Keyboard shortcuts

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