Documentation
¶
Index ¶
- Constants
- func Debug(msg string, args ...interface{})
- func Default() *slog.Logger
- func Error(msg string, args ...interface{})
- func Fatal(msg string, args ...interface{})
- func Info(msg string, args ...interface{})
- func Init(opt *Options)
- func Log(level slog.Level, msg string, args ...interface{})
- func Warn(msg string, args ...interface{})
- func Writer() io.Writer
- type Format
- type Handler
- type Logger
- type Options
- type Output
Constants ¶
const ( FormatText = iota // Log format is TEXT. FormatJson // Log format is JSON. )
Constants for log formats
const ( OutputConsole = iota // Log output is Console. OutputFile // Log output is File. OutputBoth // Log output is Console and File. )
Constants for log output
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
func Debug(msg string, args ...interface{})
Debug logs a debug message with optional arguments.
func Error ¶
func Error(msg string, args ...interface{})
Error logs an error message with optional arguments.
func Fatal ¶
func Fatal(msg string, args ...interface{})
Fatal logs a fatal error message with optional arguments and exits the program.
func Info ¶
func Info(msg string, args ...interface{})
Info logs an informational message with optional arguments.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a wrapper for slog.Handler.
func NewHandler ¶
NewHandler creates a new handler based on the provided options and writer.
func (*Handler) Enabled ¶
Enabled reports whether the handler handles records at the given level. The handler ignores records whose level is lower.
func (*Handler) Handle ¶
Handle handles the Record. It will only be called when Enabled returns true.
func (*Handler) WithAttrs ¶
WithAttrs returns a new Handler whose attributes consist of both the receiver's attributes and the arguments.
type Options ¶
type Options struct { // Indicates whether logging is enabled. Enable bool `json:"enable" yaml:"enable"` // Log format, currently supports Text: 0 and JSON: 1, with Text as the default. Format Format `json:"format" yaml:"format"` // Log output location Console: 0 or File: 1 or Both: 2, with Console as the default. Output Output `json:"output" yaml:"output"` // Log level, with supported values LevelDebug: 4, LevelInfo: 0, LevelWarn: 4, and LevelError: 8. Level int `json:"level" yaml:"level"` // Filename is the file to write logs to. Backup log files will be retained // in the same directory. If empty, logs will not be written to a file. Filename string `json:"filename" yaml:"filename"` // MaxSize is the maximum size in megabytes of the log file before it gets // rotated. It defaults to 100 megabytes. MaxSize int `json:"maxsize" yaml:"maxsize"` // MaxAge is the maximum number of days to retain old log files based on the // timestamp encoded in their filename. Note that a day is defined as 24 // hours and may not exactly correspond to calendar days due to daylight // savings, leap seconds, etc. The default is not to remove old log files // based on age. MaxAge int `json:"maxage" yaml:"maxage"` // MaxBackups is the maximum number of old log files to retain. The default // is to retain all old log files (though MaxAge may still cause them to get // deleted.) MaxBackups int `json:"maxbackups" yaml:"maxbackups"` // Compress determines if the rotated log files should be compressed // using gzip. The default is not to perform compression. Compress bool `json:"compress" yaml:"compress"` }
Options defines configuration options for the logger.
func DefaultOptions ¶
func DefaultOptions() *Options
Options defines configuration options for the logger.