logging

package
v0.0.0-...-9cf5c93 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DEBUG logs are typically voluminous, and are usually disabled in production.
	DEBUG zapcore.Level = zap.DebugLevel
	// INFO is the default logging priority.
	INFO zapcore.Level = zap.InfoLevel
	// WARN logs are more important than Info, but don't need individual human
	// review.
	WARN zapcore.Level = zap.WarnLevel
	// ERROR logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ERROR zapcore.Level = zap.ErrorLevel
	// PANIC logs are particularly important errors. In development, the logger
	// panics after writing the message. In production, it logs message then
	// panics. The only difference is that it enables the possibility to output
	// more useful messages in development.
	PANIC zapcore.Level = zap.DPanicLevel
	// FATAL logs a message, then calls os.Exit(1).
	FATAL zapcore.Level = zap.FatalLevel
)

Variables

This section is empty.

Functions

func NewDualLogger

func NewDualLogger(outpath, errpath string, level zapcore.Level, factory ...*LoggerFactory) (*zap.Logger, error)

NewDualLogger generates a dual logger with given path, and returns any encountered error. A level can be given to specify the lowest level that should be filed. Stdout and Stderr are splited into two log file (default as ERROR). If you want to use custom mechanism, then use LoggerFactory directly. Besides, additional factories can be merged into the logger.

func NewSingleLogger

func NewSingleLogger(path string, level zapcore.Level, factory ...*LoggerFactory) (*zap.Logger, error)

NewSingleLogger generates a single logger with given path, and returns any encountered error. A level can be given to specify the lowest level that should be filed. Besides, additional factories can be merged into the logger.

func SimpleDualLogger

func SimpleDualLogger(outpath, errpath string, level zapcore.Level) (*zap.Logger, error)

SimpleDualLogger is a shorthand of NewDualLogger to create a logger that has been combined with the default console logger.

func SimpleSingleLogger

func SimpleSingleLogger(path string, level zapcore.Level) (*zap.Logger, error)

SimpleSingleLogger is a shorthand of NewSingleLogger to create a logger that has been combined with the default console logger.

Types

type FactoryConfig

type FactoryConfig struct {
	OutPath []string
	ErrPath []string
}

FactoryConfig indicates the path bundle used for generating LoggerFactory

func NewFactoryConfig

func NewFactoryConfig(outpath, errpath []string) *FactoryConfig

NewFactoryConfig generates a new FactoryConfig set with given path bundle

func (*FactoryConfig) Apply

func (in *FactoryConfig) Apply(level zapcore.Level, jsoned bool, highPriority ...zapcore.Level) (*LoggerFactory, error)

Apply applys FactoryConfig to generate a new LoggerFactory. The `level` specifys the lowest level that will be filed into log, `highPriority` is optional which specifies the lowest level that should be filed into ErrPath, its default value is ERROR, which is meaningless if one of outpath or errpath is empty.

type LoggerFactory

type LoggerFactory struct {
	// contains filtered or unexported fields
}

LoggerFactory is a factory to generate loggers. It is possible to use multiple loggers at the same time. TODO: Support syslog wrapper.

var (
	// ConsoleLoggerFactory is the default LoggerFactory which only logs into
	// console. It is only used during program startup intialization.
	ConsoleLoggerFactory *LoggerFactory
)

func NewLoggerFactory

func NewLoggerFactory(cores ...zapcore.Core) *LoggerFactory

NewLoggerFactory creates a non-option specified core-combined LoggerFactory. Commonly, you should create a FactoryConfig first, and then use Apply() to generate LoggerFactory, instead of using NewLoggerFactory directly. To append additional options, use WithOptions().

func (*LoggerFactory) Merge

func (in *LoggerFactory) Merge(factories ...*LoggerFactory) *LoggerFactory

Merge combines multiple LoggerFactory into single one, with inherited cores and options. Note that options that were wrapped inside may have conflicts and it is your resonsibility to take care of it.

func (*LoggerFactory) New

func (in *LoggerFactory) New() *zap.Logger

New exports merged cores with stored options as a Logger instance. For most cases, unless you have low-latency requirement, you should prevent using the Logger directly, but using SugaredLogger instead.

func (*LoggerFactory) WithOptions

func (in *LoggerFactory) WithOptions(opts ...zap.Option) *LoggerFactory

WithOptions append options inside LoggerFactory to prepare for New()

Jump to

Keyboard shortcuts

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