Documentation ¶
Index ¶
- Constants
- Variables
- func Debug(format string, a ...interface{})
- func Debugf(format string, a ...interface{})
- func Debugln(a ...interface{})
- func Error(format string, a ...interface{})
- func Errorf(format string, a ...interface{})
- func Errorln(a ...interface{})
- func Fatal(format string, a ...interface{})
- func Fatalf(format string, a ...interface{})
- func Fatalln(a ...interface{})
- func Info(format string, a ...interface{})
- func Infof(format string, a ...interface{})
- func Infoln(a ...interface{})
- func NewHandler(w io.Writer, opts *HandlerOptions) slog.Handler
- func SetAsDefault(w io.Writer, opts *HandlerOptions)
- func SetColor(colorOn bool)
- func SetErrorWriter(w io.Writer)
- func SetOutputWriter(w io.Writer)
- func SetPrintLevel(level int)
- func Warn(format string, a ...interface{})
- func Warnf(format string, a ...interface{})
- func Warnln(a ...interface{})
- type Handler
- func (h *Handler) Enabled(ctx context.Context, level slog.Level) bool
- func (h *Handler) Handle(ctx context.Context, r slog.Record) error
- func (h *Handler) SetLogLoggerLevel(level slog.Level)
- func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *Handler) WithGroup(name string) slog.Handler
- type HandlerOptions
Constants ¶
const ( LevelDebug = iota LevelInfo LevelWarn LevelError LevelFatal )
Print levels go in order: Debug, Info, Warn, Error, Fatal
Variables ¶
var Blue = SprintfBlue
Blue creates a blue string
var Green = SprintfGreen
Green creates a green string
var Red = SprintfRed
Red creates a red string
var SprintfBlue = color.New(color.FgHiBlue).SprintfFunc()
SprintfBlue creates a blue formatted string
var SprintfGreen = color.New(color.FgHiGreen).SprintfFunc()
SprintfGreen creates a green formatted string
var SprintfRed = color.New(color.FgHiRed).SprintfFunc()
SprintfRed creates a red formatted string
var SprintfYellow = color.New(color.FgHiYellow).SprintfFunc()
SprintfYellow creates a yellow formatted string
var Yellow = SprintfYellow
Yellow creates a yellow string
Functions ¶
func Debug ¶
func Debug(format string, a ...interface{})
Debug prints a formatted debug level message with a newline appended
func Debugf ¶
func Debugf(format string, a ...interface{})
Debugf prints a formatted debug level message
func Debugln ¶
func Debugln(a ...interface{})
Debugln prints a debug level message with a newline appended
func Error ¶
func Error(format string, a ...interface{})
Error prints a formatted error level message with a newline appended
func Errorf ¶
func Errorf(format string, a ...interface{})
Errorf prints a formatted error level message
func Errorln ¶
func Errorln(a ...interface{})
Errorln prints an error level message with a newline appended
func Fatal ¶
func Fatal(format string, a ...interface{})
Fatal prints a formatted fatal level message with a newline appended and calls os.Exit(1)
func Fatalf ¶
func Fatalf(format string, a ...interface{})
Fatalf prints a formatted fatal level message and calls os.Exit(1)
func Fatalln ¶
func Fatalln(a ...interface{})
Fatalln prints a fatal level message with a newline appended and calls os.Exit(1)
func Info ¶
func Info(format string, a ...interface{})
Info prints a formatted info level message with a newline appended
func Infof ¶
func Infof(format string, a ...interface{})
Infof prints a formatted info level message
func Infoln ¶
func Infoln(a ...interface{})
Infoln prints an info level message with a newline appended
func NewHandler ¶ added in v0.3.0
func NewHandler(w io.Writer, opts *HandlerOptions) slog.Handler
func SetAsDefault ¶ added in v0.3.0
func SetAsDefault(w io.Writer, opts *HandlerOptions)
func SetColor ¶ added in v0.1.1
func SetColor(colorOn bool)
SetColor sets the color status. True for color, False for no color
func SetErrorWriter ¶
SetErrorWriter allows you to set the output writer for error and fatal messages
func SetOutputWriter ¶
SetOutputWriter allows you to set the output file for debug, info, and warn messges
func SetPrintLevel ¶ added in v0.2.0
func SetPrintLevel(level int)
SetPrintLevel allows you to set the level to print, by default LevelInfo is set
func Warn ¶
func Warn(format string, a ...interface{})
Warn prints a formatted warning level message with a newline appended
Types ¶
type Handler ¶ added in v0.3.0
type Handler struct {
// contains filtered or unexported fields
}
func (*Handler) SetLogLoggerLevel ¶ added in v0.3.0
type HandlerOptions ¶ added in v0.3.0
type HandlerOptions struct { // AddSource causes the handler to compute the source code position // of the log statement and add a SourceKey attribute to the output. AddSource bool // Level reports the minimum record level that will be logged. // The handler discards records with lower levels. // If Level is nil, the handler assumes LevelInfo. // The handler calls Level.Level for each record processed; // to adjust the minimum level dynamically, use a LevelVar. Level slog.Leveler // ReplaceAttr is called to rewrite each non-group attribute before it is logged. // The attribute's value has been resolved (see [Value.Resolve]). // If ReplaceAttr returns a zero Attr, the attribute is discarded. // // The built-in attributes with keys "time", "level", "source", and "msg" // are passed to this function, except that time is omitted // if zero, and source is omitted if AddSource is false. // // The first argument is a list of currently open groups that contain the // Attr. It must not be retained or modified. ReplaceAttr is never called // for Group attributes, only their contents. For example, the attribute // list // // Int("a", 1), Group("g", Int("b", 2)), Int("c", 3) // // results in consecutive calls to ReplaceAttr with the following arguments: // // nil, Int("a", 1) // []string{"g"}, Int("b", 2) // nil, Int("c", 3) // // ReplaceAttr can be used to change the default keys of the built-in // attributes, convert types (for example, to replace a `time.Time` with the // integer seconds since the Unix epoch), sanitize personal information, or // remove attributes from the output. ReplaceAttr func(groups []string, a slog.Attr) slog.Attr // Time format (Default: time.DateTime) TimeFormat string // Disable color (Default: false) NoColor bool }
HandlerOptions is a drop in replacement for slog.HandlerOptions