log

package
v0.0.0-...-796898b Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package log 日志操作工具

Index

Constants

View Source
const (
	// ReadFileForCACertFail 根据指定路径读取 CA 证书文件失败
	ReadFileForCACertFail = iota
)

Variables

View Source
var (
	// Log 日志全局对象
	Log Logger
	// Common 通用包日志对象
	Common, _ = zap.NewDevelopment()
	// Discovery 发现服务包日志对象
	Discovery, _ = zap.NewDevelopment()
	// Examples 案例日志对象
	Examples, _ = zap.NewDevelopment()
	// Rivet 框架日志对象
	Rivet, _ = zap.NewDevelopment()
	// Server 关联接口服务日志对象
	Server, _ = zap.NewDevelopment()
	// Bow 网关日志对象
	Bow, _ = zap.NewDevelopment()
	// Shunt 负载均衡日志对象
	Shunt, _ = zap.NewDevelopment()
	// Trans 请求处理日志对象
	Trans, _ = zap.NewDevelopment()
	// Scheduled 定时任务日志对象
	Scheduled, _ = zap.NewDevelopment()
	// Self 当前使用该框架服务日志对象
	Self, _ = zap.NewDevelopment()
)

Functions

func Binary

func Binary(key string, val []byte) zapcore.Field

Binary constructs a field that carries an opaque binary blob.

Binary data is serialized in an encoding-appropriate format. For example, zap's JSON encoder base64-encodes binary blobs. To log UTF-8 encoded text, use ByteString.

func Bool

func Bool(key string, val bool) zapcore.Field

Bool constructs a field that carries a bool.

func ByteString

func ByteString(key string, val []byte) zapcore.Field

ByteString constructs a field that carries UTF-8 encoded text as a []byte. To log opaque binary blobs (which aren't necessarily valid UTF-8), use Binary.

func Complex128

func Complex128(key string, val complex128) zapcore.Field

Complex128 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex128 to interface{}).

func Complex64

func Complex64(key string, val complex64) zapcore.Field

Complex64 constructs a field that carries a complex number. Unlike most numeric fields, this costs an allocation (to convert the complex64 to interface{}).

func Duration

func Duration(key string, val time.Duration) zapcore.Field

Duration constructs a field with the given key and value. The encoder controls how the duration is serialized.

func Error

func Error(err error) zapcore.Field

Error is shorthand for the common idiom NamedError("error", err).

func Float32

func Float32(key string, val float32) zapcore.Field

Float32 constructs a field that carries a float32. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.

func Float64

func Float64(key string, val float64) zapcore.Field

Float64 constructs a field that carries a float64. The way the floating-point value is represented is encoder-dependent, so marshaling is necessarily lazy.

func Int

func Int(key string, val int) zapcore.Field

Int constructs a field with the given key and value.

func Int16

func Int16(key string, val int16) zapcore.Field

Int16 constructs a field with the given key and value.

func Int32

func Int32(key string, val int32) zapcore.Field

Int32 constructs a field with the given key and value.

func Int64

func Int64(key string, val int64) zapcore.Field

Int64 constructs a field with the given key and value.

func Int8

func Int8(key string, val int8) zapcore.Field

Int8 constructs a field with the given key and value.

func NamedError

func NamedError(key string, err error) zapcore.Field

NamedError constructs a field that lazily stores err.Error() under the provided key. Errors which also implement fmt.Formatter (like those produced by github.com/pkg/errors) will also have their verbose representation stored under key+"Verbose". If passed a nil error, the field is a no-op.

For the common case in which the key is simply "error", the Error function is shorter and less repetitive.

func Namespace

func Namespace(key string) zapcore.Field

Namespace creates a named, isolated scope within the logger's context. All subsequent fields will be added to the new namespace.

This helps prevent key collisions when injecting loggers into sub-components or third-party libraries.

func Object

func Object(key string, val zapcore.ObjectMarshaler) zapcore.Field

Object constructs a field with the given key and ObjectMarshaler. It provides a flexible, but still type-safe and efficient, way to add map- or struct-like user-defined types to the logging context. The struct's MarshalLogObject method is called lazily.

func Reflect

func Reflect(key string, val interface{}) zapcore.Field

Reflect constructs a field with the given key and an arbitrary object. It uses an encoding-appropriate, reflection-based function to lazily serialize nearly any object into the logging context, but it's relatively slow and allocation-heavy. Outside tests, Any is always a better choice.

If encoding fails (e.g., trying to serialize a map[int]string to JSON), Reflect includes the error message in the final log output.

func Skip

func Skip() zapcore.Field

Skip constructs a no-op field, which is often useful when handling invalid inputs in other zapcore.Field constructors.

func String

func String(key string, val string) zapcore.Field

String constructs a field with the given key and value.

func Stringer

func Stringer(key string, val fmt.Stringer) zapcore.Field

Stringer constructs a field with the given key and the output of the value's String method. The Stringer's String method is called lazily.

func Time

func Time(key string, val time.Time) zapcore.Field

Time constructs a zapcore.Field with the given key and value. The encoder controls how the time is serialized.

func Uint

func Uint(key string, val uint) zapcore.Field

Uint constructs a field with the given key and value.

func Uint16

func Uint16(key string, val uint16) zapcore.Field

Uint16 constructs a field with the given key and value.

func Uint32

func Uint32(key string, val uint32) zapcore.Field

Uint32 constructs a field with the given key and value.

func Uint64

func Uint64(key string, val uint64) zapcore.Field

Uint64 constructs a field with the given key and value.

func Uint8

func Uint8(key string, val uint8) zapcore.Field

Uint8 constructs a field with the given key and value.

func Uintptr

func Uintptr(key string, val uintptr) zapcore.Field

Uintptr constructs a field with the given key and value.

Types

type Config

type Config struct {
	Level      Level // 日志输出级别
	MaxSize    int   // 每个日志文件保存的最大尺寸 单位:M
	MaxBackups int   // 日志文件最多保存多少个备份
	MaxAge     int   // 文件最多保存多少天
	Compress   bool  // 是否压缩
}

Config 日志配置对象

type Level

type Level int8

A Level is a logging priority. Higher levels are more important.

const (
	// DebugLevel logs are typically voluminous, and are usually disabled in
	// production.
	DebugLevel Level = iota - 1
	// InfoLevel is the default logging priority.
	InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel
	// DPanicLevel logs are particularly important errors. In development the
	// logger panics after writing the message.
	DPanicLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
)

type Logger

type Logger struct {
	Config *Config
}

Logger 日志入口对象

func GetLogInstance

func GetLogInstance() *Logger

GetLogInstance 获取日志管理对象 Log 单例

func (*Logger) Conf

func (log *Logger) Conf(config *Config)

Conf 配置日志基本信息

func (*Logger) Init

func (log *Logger) Init(logPath, serviceName string, config *Config, dev bool)

Init 日志初始化操作

func (*Logger) New

func (log *Logger) New(filePath string, serviceName string) *zap.Logger

New 新建日志对象

func (*Logger) New1

func (log *Logger) New1(name string, serviceName string) *zap.Logger

New 新建日志对象

func (*Logger) NewCustom

func (log *Logger) NewCustom(filePath string, level Level, maxSize int, maxBackups int, maxAge int, compress bool, serviceName string) *zap.Logger

NewCustom 新建自定义日志对象

func (*Logger) Self

func (log *Logger) Self(serviceName string)

Jump to

Keyboard shortcuts

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