logger

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: MIT Imports: 6 Imported by: 0

README

Logger

GitHub go.mod Go version GitHub branch checks state GitHub issues GitHub all releases GitHub contributors GitHub top language GitHub

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 (
	VerbosityDefault = iota
	VerbosityInfo
	VerbosityDebug
	VerbosityTrace
)
View Source
const TimeFormat = "2006-01-02 15:04:05.000 -0700"

Variables

This section is empty.

Functions

func BuildConsoleWriter added in v0.0.4

func BuildConsoleWriter(out io.Writer) io.Writer

BuildConsoleWriter returns a new zerolog.ConsoleWriter with the given output writer and a custom time format

func BuildFileWriter added in v0.0.4

func BuildFileWriter(config *WriterConfig) io.Writer

BuildFileWriter creates a directory if it doesn't exist, then returns a lumberjack.Logger that writes to a file in that directory

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 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 GetWriter added in v0.0.4

func GetWriter(config *WriterConfig) io.Writer

GetWriter takes a string and returns an io.Writer

func GroupID

func GroupID(id string) *zerolog.Logger

GroupID returns a pointer to a zerolog logger with the `groupId` field set to the value of the `id` parameter

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 Init

func Init()

Init creates a new logger with the default configuration, and sets it as the default logger

func InitWithConfig added in v0.0.2

func InitWithConfig(config *Config)

InitWithConfig creates a new logger with the given configuration, and sets it as the default logger

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 New

func New() *zerolog.Logger

New is a function that creates a new logger with the default configuration

func NewWithConfig added in v0.0.2

func NewWithConfig(config *Config) *zerolog.Logger

NewWithConfig is a function that creates a new logger with the given configuration

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 ParseLevel

func ParseLevel(levelStr string) zerolog.Level

ParseLevel converts a level string into a zerolog Level value. returns an error if the input string does not match known values.

func ParseVerboseLevel added in v0.0.4

func ParseVerboseLevel(verbose int) zerolog.Level

ParseVerboseLevel takes an integer defining the verbosity level and returns a zerolog.Level

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 Trace added in v0.0.4

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 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 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.

Types

type Config

type Config struct {
	Debug        bool
	Verbosity    int
	WriterConfig *WriterConfig
}

Config is a struct that contains a boolean, a `zerolog.Level` and an `io.Writer`. @property {bool} Debug - This is a boolean value that determines whether the application is running in debug mode or not. @property LogLevel - The level of logging you want to use. @property Writer - The writer to which the logs will be written.

type LevelWriter added in v0.0.4

type LevelWriter struct {
	Level zerolog.Level
	io.Writer
}

func (*LevelWriter) WriteLevel added in v0.0.4

func (lw *LevelWriter) WriteLevel(l zerolog.Level, p []byte) (n int, err error)

WriteLevel is a custom writer that allows us to write to a file only if the log level is greater than or equal to the level we set.

type Writer added in v0.0.4

type Writer int8
const (
	DiscardWriter Writer = iota
	StdoutWriter
	StderrWriter
	FileWriter
	DefaultWriter // Default is a combination of File and Stdout with a global level of zerolog.TraceLevel
)

type WriterConfig

type WriterConfig struct {
	Writer     Writer
	Directory  string
	FileName   string
	MaxSize    int
	MaxBackups int
	MaxAge     int
}

WriterConfig is a struct with 6 fields. @property {string} Writer - The writer to use. This can be either "file" or "console". @property {string} Directory - The directory where the log files will be written. @property {string} FileName - The name of the file to write logs to. @property {int} MaxSize - The maximum size in megabytes of the log file before it gets rotated. It defaults to 100 megabytes. @property {int} MaxBackups - The maximum number of old log files to retain. @property {int} MaxAge - The maximum age of a log file in days

Jump to

Keyboard shortcuts

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