Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a slog.Handler that writes human-readable log entries. Because it is for human consumption, changes to the format are not considered breaking changes. Entries may be multi-line. The current format looks like this:
<message> <attributes>
No escaping is done on the message. Attributes are in YAML format with the top level indented to make it visually distinct from the message.
Example ¶
package main import ( "fmt" "golang.org/x/exp/slog" "os" "github.com/willabides/actionslog/human" ) func main() { logger := slog.New(human.New(&human.Options{ Output: os.Stdout, })) logger = logger.With(slog.String("func", "Example")) logger.Info("hello", slog.String("object", "world")) logger.Warn("This is a stern warning") logger.Error("got an error", slog.Any("err", fmt.Errorf("omg"))) logger.Debug("this is a debug message") logger.Info("this is a\nmultiline\nmessage") logger.Info("multiline value", slog.String("value", "this is a\nmultiline\nvalue")) }
Output: hello func: Example object: world This is a stern warning func: Example got an error func: Example err: omg this is a multiline message func: Example multiline value func: Example value: |- this is a multiline value
Click to show internal directories.
Click to hide internal directories.