logger

package module
v1.1.12 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 12 Imported by: 48

README

logger

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Is

func Is(e error, kargs ...string) bool

Is checks if the given error contains any of the specified substrings. It returns true if any of the substrings are found, otherwise false.

Types

type Config

type Config struct {
	Format    string           // json, text, csv
	Level     int              // 100: DEBUG, 200: INFO, 300: NOTICE, 400: WARNING, 500: ERROR, 502: CRITICAL, 509: ALERT
	Output    string           // stdout, <filepath>
	Retries   int              // number of retries
	Wait      time.Duration    // wait time between retries
	StatusMap map[int][]string // status code to message map
}

Config represents the configuration for the logger.

type Error

type Error struct {
	UUID    string `json:"uuid"`
	Status  int    `json:"status"`
	Message string `json:"message"`
}

Error represents an error with a UUID, status, and message.

func (*Error) GinError added in v1.1.4

func (e *Error) GinError(c *gin.Context)

GinError is a helper function to return an error to the client using Gin framework context. It sets the headers x-error and x-error-id with the error message and UUID respectively and sets the status code.

func (*Error) Is

func (e *Error) Is(kargs ...string) bool

Is checks if the error's message contains any of the specified substrings. It returns true if any of the substrings are found, otherwise false.

type Log

type Log struct {
	Timestamp string `json:"timestamp"`
	Severity  string `json:"severity"`
	Path      string `json:"path"`
	Line      int    `json:"line"`
	Error
}

Log represents a log entry.

func (Log) ToCsv added in v1.0.6

func (l Log) ToCsv() string

ToCsv converts the log entry to a CSV format.

func (Log) ToJSON

func (l Log) ToJSON() string

ToJSON converts the log entry to JSON formated string.

func (Log) ToString

func (l Log) ToString() string

ToString converts the log entry to a string format.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger represents a logger instance.

func NewLogger added in v1.0.3

func NewLogger(config *Config) *Logger

NewLogger creates a new logger instance with the given configuration.

func (Logger) ErrorF

func (l Logger) ErrorF(format string, args ...any) *Error

ErrorF logs an error message with the given format and arguments. It returns an error object.

func (Logger) Fatal added in v1.0.6

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

Fatal logs an error message and exits the program

func (*Logger) InfiniteLoop added in v1.1.8

func (l *Logger) InfiniteLoop(f func() error, exception ...string)

InfiniteLoop executes a function infinitely until it returns an error that contains any of the specified substrings. It waits for the configured time between each iteration.

func (*Logger) InfiniteRetry added in v1.1.7

func (l *Logger) InfiniteRetry(f func() error, exception ...string) error

InfiniteRetry executes a function and retries infinitely if any error. It stops if the error contains any of the specified substrings. It waits for the configured time between each iteration.

func (Logger) Info added in v1.0.4

func (l Logger) Info(format string, args ...any) *Log

Info logs an info message with the given arguments.

func (Logger) LogF

func (l Logger) LogF(statusCode int, format string, args ...any) *Log

LogF logs a formatted message with the given status code, format and arguments. It returns the log entry.

func (*Logger) Retry added in v1.1.7

func (l *Logger) Retry(f func() error, exception ...string) error

Retry executes a function and retries if any error. It stops after the number of retries specified in the configuration or if the error contains any of the specified substrings. It waits for the configured time between each iteration.

Jump to

Keyboard shortcuts

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