rotzap

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: MIT Imports: 12 Imported by: 0

README

RotZap

Provider an easy way to initialize zap with file-rotatelogs.

Installation

go get github.com/ddzizz/rotzap

Dependencies

Usage

Init form yaml or json configuration file

zapLog, err := rotzap.InitRotZapFromCfgFile("sample.yml")
if err != nil {
    fmt.Println(err.Error())
    return
}
defer zapLog.Sync()

zapLog.Info("RotZap provide an easy way to initialize zap with file-rotatelogs")

Init from yaml configuration string

zapLog, err := rotzap.InitRotZapFromYaml(yamlStr)
if err != nil {
    t.Fatal(err)
}
defer zapLog.Sync()

zapLog.Info("RotZap provide an easy way to initialize zap with file-rotatelogs")

Init from json configuration string

zapLog, err := rotzap.InitRotZapFromJSON(jsonStr)
if err != nil {
    t.Fatal(err)
}
defer zapLog.Sync()

zapLog.Info("RotZap provide an easy way to initialize zap with file-rotatelogs")

Configurations

Configurations for file-rotatelogs

For details, please check options.go in github.com/lestrrat-go/file-rotatelogs.

Field name Value type Description
path string log filename pattern.
rotTime int64 sets the time between rotation.
rotSize int64 sets the log file size between rotation.
rotCount uint sets the number of files should be kept before it gets purged from the file system.
maxAge int64 sets the max age of a log file before it gets purged from the file system.
forceNewFile bool ensures a new file is created every time New() is called. If the base file name already exists, an implicit rotation is performed

Configurations for zap

For details, please check config.go in github.com/uber-go/zap.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitRot

func InitRot(cfg *RotConfig) (*rotatelogs.RotateLogs, error)

InitRot init file-rotatelogs from config

func InitRotZap

func InitRotZap(rotCfg RotConfig, zapCfg zap.Config) (*zap.Logger, error)

InitRotZap init file-rotatelogs and zap by config.

func InitRotZapFromCfgFile

func InitRotZapFromCfgFile(cfgName string) (*zap.Logger, error)

InitRotZapFromCfgFile Init file-rotatelogs and zap from a config file. Only support 'yaml' and 'json' format.

func InitRotZapFromJSON

func InitRotZapFromJSON(jsonStr string) (*zap.Logger, error)

InitRotZapFromJSON init file-rotatelogs and zap from a json configuration string.

func InitRotZapFromYaml

func InitRotZapFromYaml(yamlStr string) (*zap.Logger, error)

InitRotZapFromYaml init file-rotatelogs and zap from a yaml configuration string.

func InitZap

func InitZap(cfg zap.Config, writer io.Writer) (*zap.Logger, error)

InitZap Init zap by config and file-rotatelogs

Types

type Config

type Config struct {
	Rot RotConfig  `yaml:"rot" json:"rot"`
	Zap zap.Config `yaml:"zap" json:"zap"`
}

Config is configuration for rotzap

type RotConfig

type RotConfig struct {
	Path         string `json:"path" yaml:"path"`
	RotTime      int64  `json:"rotTime" yaml:"rotTime"`
	RotSize      int64  `json:"rotSize" yaml:"rotSize"`
	RotCount     uint   `json:"rotCount" yaml:"rotCount"`
	MaxAge       int64  `json:"maxAge" yaml:"maxAge"`
	ForceNewFile bool   `json:"forceNewFile" yaml:"forceNewFile"`
}

RotConfig is configuration for file-rotatelogs

Jump to

Keyboard shortcuts

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