zapwriter

package module
Version: v0.0.0-...-c1161d1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2021 License: MIT Imports: 20 Imported by: 129

README

zapwriter

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyError

func AnyError(e ...error) error

func ApplyConfig

func ApplyConfig(conf []Config) error

func CheckConfig

func CheckConfig(conf []Config, allowNames []string) error

func Default

func Default() *zap.Logger

func Logger

func Logger(logger string) *zap.Logger

func NewJSONEncoder

func NewJSONEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder

NewJSONEncoder creates a fast, low-allocation JSON encoder. The encoder appropriately escapes all field keys and values.

Note that the encoder doesn't deduplicate keys, so it's possible to produce a message like

{"foo":"bar","foo":"baz"}

This is permitted by the JSON specification, but not encouraged. Many libraries will ignore duplicate key-value pairs (typically keeping the last pair) when unmarshaling, but users should attempt to avoid adding duplicate keys.

func NewMixedEncoder

func NewMixedEncoder(cfg zapcore.EncoderConfig) zapcore.Encoder

func PrepareFileForUser

func PrepareFileForUser(filename string, owner *user.User) error

func RegisterScheme

func RegisterScheme(scheme string, constructor func(path string) (Output, error))

func Test

func Test() func()

func TestCapture

func TestCapture() string

func TestString

func TestString() string

Types

type Config

type Config struct {
	Logger           string `toml:"logger" json:"logger" comment:"handler name, default empty"`
	File             string `toml:"file" json:"file" comment:"'/path/to/filename', 'stderr', 'stdout', 'empty' (=='stderr'), 'none'"`
	Level            string `toml:"level" json:"level" comment:"'debug', 'info', 'warn', 'error', 'dpanic', 'panic', and 'fatal'"`
	Encoding         string `toml:"encoding" json:"encoding" comment:"'json' or 'console'"`
	EncodingTime     string `toml:"encoding-time" json:"encoding-time" comment:"'millis', 'nanos', 'epoch', 'iso8601'"`
	EncodingDuration string `toml:"encoding-duration" json:"encoding-duration" comment:"'seconds', 'nanos', 'string'"`
	SampleTick       string `toml:"sample-tick" json:"sample-tick" comment:"passed to time.ParseDuration"`
	SampleInitial    int    `toml:"sample-initial" json:"sample-initial" comment:"first n messages logged per tick"`
	SampleThereafter int    `toml:"sample-thereafter" json:"sample-thereafter" comment:"every m-th message logged thereafter per tick"`
}

Config configures a zapwriter.

If SampleTick is defined, the Sample* parameters are passed to zapcore.NewSampler. See their documentation for details.

func NewConfig

func NewConfig() Config

func (*Config) BuildLogger

func (c *Config) BuildLogger() (*zap.Logger, error)

func (*Config) Check

func (c *Config) Check() error

func (*Config) Clone

func (c *Config) Clone() *Config

type DsnObj

type DsnObj struct {
	url.Values
}

func DSN

func DSN(values url.Values) *DsnObj

func (*DsnObj) Bool

func (dsn *DsnObj) Bool(key string, initial bool) (bool, error)

func (*DsnObj) Duration

func (dsn *DsnObj) Duration(key string, initial string) (time.Duration, error)

func (*DsnObj) Int

func (dsn *DsnObj) Int(key string, initial int) (int, error)

func (*DsnObj) SetDuration

func (dsn *DsnObj) SetDuration(p *time.Duration, key string) error

func (*DsnObj) SetInt

func (dsn *DsnObj) SetInt(p *int, key string) error

func (*DsnObj) SetString

func (dsn *DsnObj) SetString(p *string, key string) error

func (*DsnObj) String

func (dsn *DsnObj) String(key string, initial string) (string, error)

func (*DsnObj) StringRequired

func (dsn *DsnObj) StringRequired(key string) (string, error)

type FileOutput

type FileOutput struct {
	sync.Mutex
	// contains filtered or unexported fields
}

with external rotate support

func File

func File(path string) (*FileOutput, error)

func (*FileOutput) Close

func (r *FileOutput) Close() (err error)

func (*FileOutput) Sync

func (r *FileOutput) Sync() (err error)

func (*FileOutput) Write

func (r *FileOutput) Write(p []byte) (n int, err error)

type Manager

type Manager interface {
	Default() *zap.Logger
	Logger(logger string) *zap.Logger
}

func NewManager

func NewManager(conf []Config) (Manager, error)

type Output

type Output interface {
	io.Writer
	Sync() error
}

func New

func New(dsn string) (Output, error)

type WriteSyncer

type WriteSyncer interface {
	io.Writer
	Sync() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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