Documentation ¶
Overview ¶
Package cobrahttp implements a builder for registering flags and producing a Cobra RunFunc that configures Zerolog.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is used to configure Zerolog via Cobra.
func (*Builder) RegisterFlags ¶
RegisterFlags adds flags for configuring Zerolog.
The following flags are added: - "$PREFIX-level" - "$PREFIX-format"
Example ¶
package main import ( "github.com/jzelinskie/cobrautil/v2/cobrazerolog" "github.com/spf13/cobra" ) func main() { zl := cobrazerolog.New() cmd := &cobra.Command{ Use: "mycmd", PreRunE: zl.RunE(), } zl.RegisterFlags(cmd.PersistentFlags()) }
Output:
type Option ¶
type Option func(*Builder)
Option is function used to configure Zerolog within a Cobra RunFunc.
func WithAsync ¶
WithAsync enables non-blocking logging.
Size of the buffer and polling interval can be configured. Disabled by default.
func WithFlagPrefix ¶
WithFlagPrefix defines prefix used with the generated flags. Defaults to "log".
func WithPreRunLevel ¶
WithPreRunLevel defines the logging level used for pre-run log messages. Defaults to "debug".
func WithTarget ¶
WithTarget callback that forwards the configured logger. Useful when we want to keep it in a global variable.