Documentation ¶
Index ¶
- Variables
- type Format
- type Item
- type Level
- type Logger
- func (r *Logger) Debug(v ...any)
- func (r *Logger) Debugf(format string, v ...any)
- func (r *Logger) Error(v ...any)
- func (r *Logger) Errorf(format string, v ...any)
- func (r *Logger) Fatal(v ...any)
- func (r *Logger) Fatalf(format string, v ...any)
- func (r *Logger) Info(v ...any)
- func (r *Logger) Infof(format string, v ...any)
- func (r *Logger) Output(level Level, calldepth int, format *string, v ...any)
- func (r *Logger) SetFormat(format Format) error
- func (r *Logger) SetLevel(level Level) error
- func (r *Logger) SetOutput(filename string) error
- func (r *Logger) Warning(v ...any)
- func (r *Logger) Warningf(format string, v ...any)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // LevelToString is a map that converts a Level to its string representation. LevelToString = map[Level]string{DebugLevel: "debug", InfoLevel: "info", WarningLevel: "warning", ErrorLevel: "error", FatalLevel: "fatal"} // StringToLevel is a map that converts a string to its Level equivalent. StringToLevel = map[string]Level{"debug": DebugLevel, "info": InfoLevel, "warning": WarningLevel, "error": ErrorLevel, "fatal": FatalLevel} )
View Source
var ( ErrInvalidFormat = errors.New("format is invalid") ErrInvalidLevel = errors.New("level is invalid") )
View Source
var ( SetFormat = std.SetFormat SetLevel = std.SetLevel SetOutput = std.SetOutput Output = std.Output Debug = std.Debug Debugf = std.Debugf Info = std.Info Infof = std.Infof Warning = std.Warning Warningf = std.Warningf Warn = std.Warn Warnf = std.Warnf Error = std.Error Errorf = std.Errorf Fatal = std.Fatal Fatalf = std.Fatalf )
Aliases of logger functions.
Functions ¶
This section is empty.
Types ¶
type Item ¶
type Item struct { // Date is the timestamp of the log. Date time.Time `json:"date"` // File represents the source code file where the log was created. File string `json:"file"` // Level is a string representation of the logging level (e.g., "info", "warning"). Level string `json:"level"` // Message contains the log entry. // It could be a string or a fmt.Stringer interface with json annotations. Message any `json:"message"` // Line contains the corresponding line number where the log was created. Line int `json:"line"` // contains filtered or unexported fields }
Item represents a log item with date, file name, line number, level, and Message.
type Level ¶
type Level int
const ( // DebugLevel is the lowest level and usually only enabled during development. // It provides detailed information useful for debugging purposes, // such as tracking variable values or understanding the flow of execution through a program. // In production environments, this level should be disabled to reduce log size and improve performance. DebugLevel Level = 0 + iota // InfoLevel messages are typically used when you want to provide contextual details // about normal operations in your application. // For example, "Starting server on port 8080" or "Connected to database". // These logs can help with monitoring the health of an application and understanding its behavior over time. InfoLevel // WarningLevel messages are used when something unexpected happened but did not cause the program to fail. // For example, "Failed to connect to database", "Invalid configuration value". // It's important to monitor these logs as they often indicate a problem that may need attention soon. WarningLevel // ErrorLevel messages are for reporting failures in a way that allows the application to continue running. // For instance, "Could not find file", "Failed to parse JSON". // These types of errors should be fixed immediately but do not necessarily mean the program is failing. ErrorLevel // FatalLevel logs indicate that an unrecoverable error has occurred and the application cannot proceed // with its current operation. The application will typically exit after logging a fatal message, // possibly with a non-zero status code to indicate failure. // For example, "Failed to start server", "Database connection lost". // These types of errors are usually indicative of serious problems that require immediate attention. FatalLevel // WarnLevel is an alias of WarningLevel. WarnLevel = WarningLevel )
type Logger ¶
type Logger struct { Warn func(...any) Warnf func(string, ...any) // contains filtered or unexported fields }
Logger allows messages with different levels/priorities to be sent to stderr/stdout
func (*Logger) Fatalf ¶
Fatalf writes fatal level messages using formatted string and terminates the application
Click to show internal directories.
Click to hide internal directories.