Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBufferFull = errors.New("buffer full")
Functions ¶
func Buffer ¶
Buffer returns a new handler that buffers records and sends them to the given handler. If block is true, the buffer will block when it is full. If block is false, the buffer will discard the record if it is full.
func NewNopHandler ¶
NewNopHandler creates a slog handler that discards all log messages.
func NewNopLogger ¶
NewNopLogger creates a slog logger that discards all log messages.
Types ¶
type LevelHandler ¶
type LevelHandler struct {
// contains filtered or unexported fields
}
LevelHandler is a handler that logs records with levels greater than or equal to a given level using the given handler.
Example ¶
infoFile, err := os.OpenFile("testdata/info.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
panic(err)
}
defer infoFile.Close()
warnFile, err := os.OpenFile("testdata/warn.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
panic(err)
}
defer warnFile.Close()
errorFile, err := os.OpenFile("testdata/error.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
panic(err)
}
defer errorFile.Close()
infoHandler := slog.NewTextHandler(infoFile, &slog.HandlerOptions{Level: slog.LevelInfo})
warnHandler := slog.NewTextHandler(warnFile, &slog.HandlerOptions{Level: slog.LevelWarn})
errorHandler := slog.NewTextHandler(errorFile, &slog.HandlerOptions{Level: slog.LevelError})
handler := NewLevelHandler(map[slog.Level]slog.Handler{
slog.LevelInfo: infoHandler,
slog.LevelWarn: warnHandler,
slog.LevelError: errorHandler,
})
logger := slog.New(handler)
logger.Info("info text")
logger.Warn("warn text")
logger.Error("error text")
func NewLevelHandler ¶
func NewLevelHandler(levelHandlers map[slog.Level]slog.Handler) *LevelHandler
NewLevelHandler returns a new handler that logs records with levels greater than or equal to the given level using the given handler.
func (*LevelHandler) Handle ¶
Handle logs the record if the level is greater than or equal to the handler's level.
type ReplaceAttrFunc ¶
ReplaceAttrFunc is a function that replaces an attribute.
func ReplaceSourceAttr ¶
func ReplaceSourceAttr() ReplaceAttrFunc
func ReplaceTimeAttr ¶
func ReplaceTimeAttr(timeFormat string) ReplaceAttrFunc
ReplaceAttrFuncs is a list of ReplaceAttrFuncs.
func WrapReplaceAttrFunc ¶
func WrapReplaceAttrFunc(fns ...ReplaceAttrFunc) ReplaceAttrFunc
WrapReplaceAttrFunc wraps a ReplaceAttrFunc.
Directories
¶
| Path | Synopsis |
|---|---|
|
package rotate is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify.
|
package rotate is a port of File-RotateLogs from Perl (https://metacpan.org/release/File-RotateLogs), and it allows you to automatically rotate output files when you write to them according to the filename pattern that you can specify. |
