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 FilePath(filePath string) slog.Attr
- 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 DeferredHandler
- func (*DeferredHandler) Enabled(context.Context, slog.Level) bool
- func (d *DeferredHandler) Flush(h slog.Handler)
- func (d *DeferredHandler) Handle(ctx context.Context, record slog.Record) error
- func (d *DeferredHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (*DeferredHandler) WithGroup(_ string) slog.Handler
- type Logger
- type Options
Constants ¶
const ( LevelDebug = slog.LevelDebug LevelInfo = slog.LevelInfo LevelWarn = slog.LevelWarn LevelError = slog.LevelError LevelFatal = slog.Level(12) PrefixContainerImage = "image" PrefixPackage = "pkg" PrefixVulnerability = "vuln" PrefixMisconfiguration = "misconfig" PrefixSecret = "secret" PrefixLicense = "license" PrefixVulnerabilityDB = "vulndb" PrefixJavaDB = "javadb" )
Variables ¶
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 )
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 InitLogger ¶
func InitLogger(debug, disable bool)
InitLogger initializes the logger variable and flushes the buffered logs if needed.
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 DeferredHandler ¶ added in v0.55.0
type DeferredHandler struct {
// contains filtered or unexported fields
}
DeferredHandler is needed to save logs and print them after calling `PrintLogs()` command. For example, this may be necessary when the logger is not yet initialized, but messages need to be transmitted. In this case, the messages are saved and printed when the logger is initialized.
func (*DeferredHandler) Flush ¶ added in v0.55.0
func (d *DeferredHandler) Flush(h slog.Handler)
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.