Documentation
¶
Index ¶
- func Is(e error, args ...string) bool
- type Config
- type Error
- type Log
- type Logger
- func (l *Logger) ErrorF(format string, args ...any) *Error
- func (l *Logger) Fatal(format string, args ...any)
- func (l *Logger) InfiniteLoop(f func() error, exception ...string)
- func (l *Logger) InfiniteRetry(f func() error, exception ...string) error
- func (l *Logger) Info(format string, args ...any) *Log
- func (l *Logger) LogF(statusCode int, format string, args ...any) *Log
- func (l *Logger) Retry(f func() error, exception ...string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 defines the configuration options for logging, including format, level, output, retries, and wait duration.
type Error ¶
type Error struct {
UUID string `json:"uuid"`
Status int `json:"status"`
Message string `json:"message"`
}
Error represents an error with a unique identifier, status code, and a message.
func ToError ¶ added in v1.2.0
ToError tries to cast an error to a SdkError. If the error is not an SdkError, it returns nil.
func (*Error) Error ¶ added in v1.1.13
Error serializes the Error struct into a JSON-formatted string and returns it as an error message.
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 structured log entry containing timestamp, severity, file path, line number, and error details.
func (*Log) ToCsv ¶ added in v1.0.6
ToCsv converts a Log instance into a CSV-formatted single-line string and returns it. Returns an empty string on failure.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger provides logging functionalities with configurable format, level, output, retries, and wait time.
func NewLogger ¶ added in v1.0.3
NewLogger initializes and returns a new Logger instance configured with the provided Config or default values.
func (*Logger) ErrorF ¶
ErrorF logs an error message with a formatted string and arguments and determines the corresponding status code. Returns an error instance containing a UUID, status code, and message.
func (*Logger) Fatal ¶ added in v1.0.6
Fatal logs a message with a status code of 500 and terminates the application with os.Exit(1).
func (*Logger) InfiniteLoop ¶ added in v1.1.8
InfiniteLoop continuously executes a provided function until it produces a matching error or a specified exception.
func (*Logger) InfiniteRetry ¶ added in v1.1.7
InfiniteRetry executes a function repeatedly until it succeeds or returns an error containing specified substrings. If a matching error occurs, it is returned immediately. Otherwise, it waits for a configured duration before retrying.
func (*Logger) Info ¶ added in v1.0.4
Info logs an informational message with a status code of 200, using formatted strings and optional arguments.