log

package module
v0.0.0-...-551f8c2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MIT Imports: 6 Imported by: 2

README

log

This Go module provides wrapper functions for logging and initializing zerolog, a fast and flexible logging library for Go.

How to use
  • Import the module into your Go project
    get -u github.com/camelhr/log
    
  • Call the Init(appName) function inside main.go to initialize the logger

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(format string, args ...any)

Debug takes formatted message string and logs at Debug level

func Error

func Error(format string, args ...any)

Error takes formatted message string and logs at Error level

func Fatal

func Fatal(format string, args ...any)

Fatal takes formatted message string, logs at Fatal level and then calls os.Exit(1)

func Info

func Info(format string, args ...any)

Info takes formatted message string and logs at Info level

func InitGlobalLogger

func InitGlobalLogger(appName string, level string)

InitGlobalLogger creates a new logger with specified appName and log level It also sets the new logger as built in logger This should be called prior to calling any of the log methods

func Panic

func Panic(format string, args ...any)

Panic takes formatted message string, logs at Panic level and calls panic()

func SetOutput

func SetOutput(w io.Writer)

SetOutput updates the current logger's output to specified io.Writer

func Warn

func Warn(format string, args ...any)

Warn takes formatted message string and logs at Warn level

Types

type Logger

type Logger interface {
	// BaseLogger returns the underlying logger implementation
	BaseLogger() *zerolog.Logger

	// SetOutput updates the current logger's output to specified io.Writer
	// It also overrides the built-in logger with the updated logger
	SetOutput(w io.Writer)

	// Debug takes formatted message string and logs at Debug level
	Debug(format string, args ...any)

	// Info takes formatted message string and logs at Info level
	Info(format string, args ...any)

	// Warn takes formatted message string and logs at Warn level
	Warn(format string, args ...any)

	// Error takes formatted message string and logs at Error level
	Error(format string, args ...any)

	// Panic takes formatted message string and logs at Panic level. It then calls panic()
	Panic(format string, args ...any)

	// Fatal takes formatted message string and logs at Fatal level. It then calls os.Exit(1)
	Fatal(format string, args ...any)

	// With returns a new wrapped logger with additional context provided by a set
	With(keyValues ...any) Logger
}

Logger provides common logging functionalities

func With

func With(keyValues ...any) Logger

With returns a new logger with additional context provided by a set of key/value tuples

Jump to

Keyboard shortcuts

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