logger

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 10 Imported by: 0

README

Logger (Internal use)

The project is intended to provide a global logger interface for all software that is developed using Go. This package uses rs/zerolog under the hood to provide a great API and best performance possible.

The project uses make to make your life easier. If you're not familiar with Makefiles you can take a look at this quickstart guide.

Whenever you need help regarding the available actions, just use the following command.

make help

Setup

To get your setup up and running the only thing you have to do is

make all

This will initialize a git repo, download the dependencies in the latest versions and install all needed tools. If needed code generation will be triggered in this target as well.

Test & lint

Run linting

make lint

Run tests

make test

Todo

  • Add performance tests based on rs/zerolog suite.

Documentation

Index

Constants

View Source
const DebugLevel = zerolog.DebugLevel
View Source
const DefaultLevel = zerolog.WarnLevel
View Source
const FileNameTimeFormat = "2006-01-02_15_04_05.log"

Variables

View Source
var CallerMarshalFunc = func(_ uintptr, file string, line int) string {
	file = file[countParentDirectories(file, MaxPathNumber):]
	return file + ":" + strconv.Itoa(line)
}
View Source
var MaxPathNumber = 0

Functions

func Ctx added in v0.2.0

func Ctx(ctx context.Context) *zerolog.Logger

Ctx returns the zerolog.Logger associated with the ctx. If no logger is associated, a disabled logger is returned.

func Debug

func Debug() *zerolog.Event

Debug starts a new message with debug level.

You must call Msg on the returned event in order to send the event.

func Err added in v0.2.0

func Err(err error) *zerolog.Event

Err starts a new message with error level with err as a field if not nil or with info level if err is nil.

You must call Msg on the returned event in order to send the event.

func Error

func Error() *zerolog.Event

Error starts a new message with error level.

You must call Msg on the returned event in order to send the event.

func Fatal

func Fatal() *zerolog.Event

Fatal starts a new message with fatal level. The os.Exit(1) function is called by the Msg method.

You must call Msg on the returned event in order to send the event.

func GetLevel added in v1.5.0

func GetLevel() zerolog.Level

GetLevel is a function that returns the current logging level of the logger. The logging level is of type zerolog.Level, which is an integer type where higher values represent lower severity levels.

This function is useful when you want to check the current logging level programmatically, for example to only execute certain code if the logging level is set to a certain severity.

func GlobalLevel added in v1.5.2

func GlobalLevel() zerolog.Level

GlobalLevel is a function that returns the current global logging level. The logging level is of type zerolog.Level, which is an integer type where higher values represent lower severity levels.

This function is useful when you want to check the current global logging level programmatically, for example to only execute certain code if the global logging level is set to a certain severity.

func Hook

func Hook(h zerolog.Hook) zerolog.Logger

Hook returns a logger with the h Hook.

func Info

func Info() *zerolog.Event

Info starts a new message with info level.

You must call Msg on the returned event in order to send the event.

func Level added in v0.2.0

func Level(level zerolog.Level) zerolog.Logger

Level creates a child logger with the minimum accepted level set to level.

func Log

func Log() *zerolog.Event

Log starts a new message with no level. Setting zerolog.GlobalLevel to zerolog.Disabled will still disable events produced by this method.

You must call Msg on the returned event in order to send the event.

func MultiLevelWriter added in v1.6.0

func MultiLevelWriter(writers ...io.Writer) io.Writer

func Output added in v0.2.0

func Output(w io.Writer) zerolog.Logger

Output duplicates the global logger and sets w as its output.

func Panic

func Panic() *zerolog.Event

Panic starts a new message with panic level. The message is also sent to the panic function.

You must call Msg on the returned event in order to send the event.

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 Sample added in v0.2.0

func Sample(s zerolog.Sampler) zerolog.Logger

Sample returns a logger with the s sampler.

func SetGlobalLevel added in v1.5.2

func SetGlobalLevel(l zerolog.Level)

SetGlobalLevel is a function that sets the global logging level. The logging level is of type zerolog.Level, which is an integer type where higher values represent lower severity levels. The levels are as follows: 0=panic, 1=fatal, 2=error, 3=warn, 4=info, 5=debug, 6=trace.

This function is useful when you want to set the global logging level programmatically, for example to control the overall verbosity of your application.

Parameters:

l (zerolog.Level): The logging level to set as the global level.

func Trace

func Trace() *zerolog.Event

Trace starts a new message with trace level.

You must call Msg on the returned event in order to send the event.

func UpdateContext added in v1.3.0

func UpdateContext(update func(c zerolog.Context) zerolog.Context)

UpdateContext updates the internal logger's context.

Caution: This method is not concurrency safe. Use the With method to create a child logger before modifying the context from concurrent goroutines.

func Warn

func Warn() *zerolog.Event

Warn starts a new message with warn level.

You must call Msg on the returned event in order to send the event.

func With

func With() zerolog.Context

With creates a child logger with the field added to its context.

func WithConsoleWriter added in v0.2.0

func WithConsoleWriter() io.Writer

func WithContext added in v1.3.0

func WithContext(ctx context.Context) context.Context

WithContext returns a copy of ctx with the receiver attached. The Logger attached to the provided Context (if any) will not be effected. If the receiver's log level is Disabled it will only be attached to the returned Context if the provided Context has a previously attached Logger. If the provided Context has no attached Logger, a Disabled Logger will not be attached.

func WithFileWriter added in v0.2.0

func WithFileWriter(path string) io.Writer

func WithLevel

func WithLevel(level zerolog.Level) *zerolog.Event

WithLevel starts a new message with level.

You must call Msg on the returned event in order to send the event.

func WithOptions added in v0.2.0

func WithOptions(opts ...Option)

Types

type Option added in v0.2.0

type Option func(logger *zerolog.Logger)

Option is a function that takes a pointer to a Logger and sets its options. This is used to apply different configurations to the logger.

func WithMaxPathParents added in v1.5.2

func WithMaxPathParents(max int) Option

WithMaxPathParents is a function that takes an integer value and returns an Option. This option sets the maximum number of parent directories that will be included in the log's path.

This function is useful when you want to limit the verbosity of the file paths in your logs. For example, if you set max to 2, only the last two directories in the path will be included.

func WithSentry added in v0.2.0

func WithSentry() Option

WithSentry is a function that returns an option. This option adds a Sentry hook to the logger. The Sentry hook is used to send logs to a Sentry server for error tracking and monitoring.

func WithVerbosity added in v0.2.0

func WithVerbosity(verbosity int) Option

WithVerbosity is a function that takes an integer value and returns an option. This option sets the logger's level based on the provided verbosity. The verbosity is subtracted from the Panic level to determine the log level.

func WithWriter added in v1.1.0

func WithWriter(w io.Writer) Option

WithWriter is a function that takes an io.Writer and returns an option. This option sets the logger's output destination to the provided io.Writer. This is similar to WithOutput, but can be used when you want to specify a different writer.

type SentryHook added in v0.2.0

type SentryHook struct{}

func (SentryHook) Run added in v0.2.0

func (h SentryHook) Run(_ *zerolog.Event, level zerolog.Level, message string)

Jump to

Keyboard shortcuts

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