Documentation
¶
Overview ¶
Package hlog is experimental logging packages which provides Custom handlerer for golang.org/x/exp/slog used within Happy.
Index ¶
- func ColorLevel(lvlArg slog.Attr) slog.Attr
- func Colorize(s string, fg, bg Color, format uint) (str string)
- func Debug(msg string, args ...any)
- func Deprecated(msg string, args ...any)
- func Error(msg string, err error, args ...any)
- func Info(msg string, args ...any)
- func Issue(msg string, args ...any)
- func Log(level Level, msg string, args ...any)
- func LogAttrs(level Level, msg string, attrs ...slog.Attr)
- func NewContext(ctx context.Context, l *Logger) context.Context
- func NewHandler(w io.Writer) slog.Handler
- func NotImplemented(msg string, args ...any)
- func Notice(msg string, args ...any)
- func Ok(msg string, args ...any)
- func Println(msg string, args ...any)
- func SetDefault(l *Logger, stdlog bool)
- func SystemDebug(msg string, args ...any)
- func Task(name string, args ...slog.Attr) sarg.Task
- func Warn(msg string, args ...any)
- type Color
- type Config
- type Handler
- type Level
- type Logger
- func (l *Logger) Context() context.Context
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) Deprecated(msg string, args ...any)
- func (l *Logger) Enabled(level Level) bool
- func (l *Logger) Error(msg string, err error, args ...any)
- func (l *Logger) Handler() slog.Handler
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) Issue(msg string, args ...any)
- func (l *Logger) Log(level Level, msg string, args ...any)
- func (l *Logger) LogAttrs(level Level, msg string, attrs ...slog.Attr)
- func (l *Logger) LogAttrsDepth(calldepth int, level Level, msg string, attrs ...slog.Attr)
- func (l *Logger) LogDepth(calldepth int, level Level, msg string, args ...any)
- func (l *Logger) NotImplemented(msg string, args ...any)
- func (l *Logger) Notice(msg string, args ...any)
- func (l *Logger) Ok(msg string, args ...any)
- func (l *Logger) Println(msg string, args ...any)
- func (l *Logger) SystemDebug(msg string, args ...any)
- func (l *Logger) Task(name string, args ...slog.Attr) sarg.Task
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) With(args ...any) *Logger
- func (l *Logger) WithContext(ctx context.Context) *Logger
- func (l *Logger) WithGroup(name string) *Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deprecated ¶
func NewContext ¶
NewContext returns a context that contains the given Logger. Use FromContext to retrieve the Logger.
func NotImplemented ¶
func SetDefault ¶
SetDefault makes l the default Logger. After this call, output from the log package's default Logger (as with log.Print, etc.) will be logged at LevelInfo using l's Handler.
func SystemDebug ¶
Debug calls Logger.Debug on the default logger.
Types ¶
type Color ¶
type Color uint
type Config ¶
type Config struct { Options slog.HandlerOptions JSON bool Colors bool Secrets []string }
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
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 formats its argument Record as a JSON object on a single line.
If the Record's time is zero, the time is omitted. Otherwise, the key is "time" and the value is output as with json.Marshal.
If the Record's level is zero, the level is omitted. Otherwise, the key is "level" and the value of Level.String is output.
If the AddSource option is set and source information is available, the key is "source" and the value is output as "FILE:LINE".
The message's key is "msg".
To modify these or other attributes, or remove them from the output, use [HandlerOptions.ReplaceAttr].
Values are formatted as with encoding/json.Marshal, with the following exceptions:
- Floating-point NaNs and infinities are formatted as one of the strings "NaN", "+Inf" or "-Inf".
- Levels are formatted as with Level.String.
Each call to Handle results in a single serialized call to io.Writer.Write.
type Level ¶
const ( // Levels LevelSystemDebug Level = Level(levelSystemDebug) LevelDebug Level = Level(slog.LevelDebug) LevelInfo Level = Level(levelInfo) LevelTask Level = Level(levelTask) LevelOk Level = Level(levelOk) LevelNotice Level = Level(levelNotice) LevelWarn Level = Level(levelWarn) LevelNotImplemented Level = Level(levelNotImplemented) LevelDeprecated Level = Level(levelDeprecated) LevelIssue Level = Level(levelIssue) LevelError Level = Level(levelError) LevelOut Level = Level(levelOut) )
func (Level) ColorLabel ¶
func (Level) MarshalJSON ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func Ctx ¶
Ctx retrieves a Logger from the given context using FromContext. Then it adds the given context to the Logger using WithContext and returns the result.
func FromContext ¶
FromContext returns the Logger stored in ctx by NewContext, or the default Logger if there is none.
func (*Logger) Deprecated ¶
Warn logs at LevelWarn.
func (*Logger) Error ¶
Error logs at LevelError. If err is non-nil, Error appends Any(ErrorKey, err) to the list of attributes.
func (*Logger) Log ¶
Log emits a log record with the current time and the given level and message. The Record's Attrs consist of the Logger's attributes followed by the Attrs specified by args.
The attribute arguments are processed as follows:
- If an argument is an Attr, it is used as is.
- If an argument is a string and this is not the last argument, the following argument is treated as the value and the two are combined into an Attr.
- Otherwise, the argument is treated as a value with key "!BADKEY".
func (*Logger) LogAttrs ¶
LogAttrs is a more efficient version of Logger.Log that accepts only Attrs.
func (*Logger) LogAttrsDepth ¶
LogAttrsDepth is like Logger.LogAttrs, but accepts a call depth argument which it interprets like Logger.LogDepth.
func (*Logger) LogDepth ¶
LogDepth is like Logger.Log, but accepts a call depth to adjust the file and line number in the log record. 0 refers to the caller of LogDepth; 1 refers to the caller's caller; and so on.
func (*Logger) NotImplemented ¶
Debug logs at LevelDebug.
func (*Logger) SystemDebug ¶
Debug logs at LevelDebug.
func (*Logger) With ¶
With returns a new Logger that includes the given arguments, converted to Attrs as in Logger.Log. The Attrs will be added to each output from the Logger.
The new Logger's handler is the result of calling WithAttrs on the receiver's handler.
func (*Logger) WithContext ¶
WithContext returns a new Logger with the same handler as the receiver and the given context.