Documentation
¶
Overview ¶
Example ¶
package main import ( "context" "github.com/protolambda/ask" "github.com/protolambda/asklog" ) type MainCmd struct { LogConfig asklog.Config `ask:"."` Foobar string `ask:"--foobar" help:"Some other flag"` } func (m *MainCmd) Default() { m.LogConfig.Default() } func (m *MainCmd) Run(ctx context.Context, args ...string) error { logger := m.LogConfig.New() logger.Info("Hello world!", "foobar", m.Foobar) // ... return nil } func main() { ask.Run(&MainCmd{}) }
Output:
Index ¶
- type Config
- type DynamicLogHandler
- func (d *DynamicLogHandler) Enabled(ctx context.Context, lvl slog.Level) bool
- func (d *DynamicLogHandler) Handle(ctx context.Context, r slog.Record) error
- func (d *DynamicLogHandler) SetLogLevel(lvl slog.Level)
- func (d *DynamicLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (d *DynamicLogHandler) WithGroup(name string) slog.Handler
- type Format
- type Level
- type LvlSetter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Out to write log data to. If nil, os.Stdout will be used. Out io.Writer `ask:"-"` Level Level `ask:"--log.level" help:"Log level: 'trace', 'debug', 'info', 'warn', 'error', 'crit'. Aliases and mixed-case are excepted."` Format Format `ask:"--log.format" help:"Log format: 'text', 'terminal', 'logfmt', 'json'."` Color bool `ask:"--log.color" help:"Enable log coloring (terminal format only)"` }
type DynamicLogHandler ¶
type DynamicLogHandler struct {
// contains filtered or unexported fields
}
DynamicLogHandler allow runtime-configuration of the log handler.
func NewDynamicLogHandler ¶
func NewDynamicLogHandler(lvl slog.Level, h slog.Handler) *DynamicLogHandler
func (*DynamicLogHandler) SetLogLevel ¶
func (d *DynamicLogHandler) SetLogLevel(lvl slog.Level)
Click to show internal directories.
Click to hide internal directories.