cobrazerolog

package
v2.0.0-...-9f8a4f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 12 Imported by: 2

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 New

func New(opts ...Option) *Builder

New creates a Cobra RunFunc Builder for ZeroLog.

func (*Builder) RegisterFlags

func (b *Builder) RegisterFlags(flags *pflag.FlagSet)

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:

func (*Builder) RunE

func (b *Builder) RunE() cobrautil.CobraRunFunc

RunE returns a Cobra RunFunc that configures Zerolog.

The required flags can be added to a command by using RegisterFlags().

type Option

type Option func(*Builder)

Option is function used to configure Zerolog within a Cobra RunFunc.

func WithAsync

func WithAsync(size int, pollInterval time.Duration) Option

WithAsync enables non-blocking logging.

Size of the buffer and polling interval can be configured. Disabled by default.

func WithFlagPrefix

func WithFlagPrefix(flagPrefix string) Option

WithFlagPrefix defines prefix used with the generated flags. Defaults to "log".

func WithPreRunLevel

func WithPreRunLevel(preRunLevel zerolog.Level) Option

WithPreRunLevel defines the logging level used for pre-run log messages. Defaults to "debug".

func WithTarget

func WithTarget(fn func(zerolog.Logger)) Option

WithTarget callback that forwards the configured logger. Useful when we want to keep it in a global variable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL