Documentation ¶
Index ¶
- Constants
- Variables
- func Debugf(format string, args ...any)
- func Err(err error) slog.Attr
- func Errorf(format string, args ...any)
- func Fatal(msg string, args ...any)
- func Infof(format string, args ...any)
- func InitLogger(debug, disable bool)
- func Prefix(prefix string) slog.Attr
- func Warnf(format string, args ...any)
- func WithContextAttrs(ctx context.Context, attrs ...slog.Attr) context.Context
- func WithContextPrefix(ctx context.Context, prefix string) context.Context
- type ColorHandler
- func (h *ColorHandler) Enabled(_ context.Context, level slog.Level) bool
- func (h *ColorHandler) Err(r slog.Record) error
- func (h *ColorHandler) Handle(ctx context.Context, r slog.Record) error
- func (h *ColorHandler) Prefix(ctx context.Context, r slog.Record) string
- func (h *ColorHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (h *ColorHandler) WithGroup(name string) slog.Handler
- type Logger
- type Options
- type WriteLogger
Constants ¶
View Source
const ( LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError LevelFatal = slog.Level(12) )
Variables ¶
View Source
var ( String = slog.String Int64 = slog.Int64 Int = slog.Int Bool = slog.Bool Time = slog.Time Duration = slog.Duration Group = slog.Group Any = slog.Any )
View Source
var ( // With calls [Logger.With] on the default logger. With = slog.With SetDefault = slog.SetDefault Debug = slog.Debug DebugContext = slog.DebugContext Info = slog.Info InfoContext = slog.InfoContext Warn = slog.Warn WarnContext = slog.WarnContext Error = slog.Error ErrorContext = slog.ErrorContext )
Functions ¶
func WithContextAttrs ¶ added in v0.51.0
WithContextAttrs returns a new context with the given attrs.
Types ¶
type ColorHandler ¶ added in v0.51.0
type ColorHandler struct {
// contains filtered or unexported fields
}
func NewHandler ¶ added in v0.51.0
func NewHandler(out io.Writer, opts *Options) *ColorHandler
func (*ColorHandler) Err ¶ added in v0.51.0
func (h *ColorHandler) Err(r slog.Record) error
Err returns the error from the attrs, if any.
type Logger ¶
Logger is an alias of slog.Logger
func WithPrefix ¶ added in v0.51.0
WithPrefix calls [Logger.With] with the prefix on the default logger.
Note: If WithPrefix is called within init() or during global variable initialization, it will use the default logger of log/slog package before Trivy's logger is set up. In such cases, it's recommended to pass the prefix via WithContextPrefix to ensure the correct logger is used.
type WriteLogger ¶ added in v0.51.0
type WriteLogger struct {
// contains filtered or unexported fields
}
WriteLogger is a wrapper around Logger to implement io.Writer
func NewWriteLogger ¶ added in v0.51.0
func NewWriteLogger(logger *Logger) *WriteLogger
NewWriteLogger creates a new WriteLogger
Click to show internal directories.
Click to hide internal directories.