logger

package module
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

README

logger

「仅发布」日志组件

Documentation

Overview

Copyright 2020 Go-Ceres Author https://github.com/go-ceres/go-ceres

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2020 Go-Ceres Author https://github.com/go-ceres/go-ceres

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2020 Go-Ceres Author https://github.com/go-ceres/go-ceres

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2020 Go-Ceres Author https://github.com/go-ceres/go-ceres

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2020 Go-Ceres Author https://github.com/go-ceres/go-ceres

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

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

Variables

View Source
var (
	DefaultLogger = Config{
		Stdout:     true,
		AddCaller:  true,
		CallerSkip: 2,
		Rotate:     NewDefaultRotateConfig(),
	}.Build()
	FrameLogger = Config{
		Debug:      true,
		Stdout:     true,
		AddCaller:  true,
		CallerSkip: 2,
	}.Build()
)
View Source
var (
	// String ...
	String = zap.String
	// Any ...
	Any = zap.Any
	// Int64 ...
	Int64 = zap.Int64
	// Int ...
	Int = zap.Int
	// Int32 ...
	Int32 = zap.Int32
	// Uint ...
	Uint = zap.Uint
	// Duration ...
	Duration = zap.Duration
	// Durationp ...
	Durationp = zap.Durationp
	// Object ...
	Object = zap.Object
	// Namespace ...
	Namespace = zap.Namespace
	// Reflect ...
	Reflect = zap.Reflect
	// Skip ...
	Skip = zap.Skip()
	// ByteString ...
	ByteString = zap.ByteString
)

Functions

func DPanic

func DPanic(args ...interface{})

func DPanicd

func DPanicd(msg string, fields ...Field)

func DPanicf

func DPanicf(template string, args ...interface{})

func DPanicw

func DPanicw(msg string, keysAndValues ...interface{})

func Debug

func Debug(args ...interface{})

Sugar

func Debugd

func Debugd(msg string, fields ...Field)

DeSugar

func Debugf

func Debugf(template string, args ...interface{})

Sugar f

func Debugw

func Debugw(msg string, keysAndValues ...interface{})

Sugar w

func Error

func Error(args ...interface{})

func Errord

func Errord(msg string, fields ...Field)

func Errorf

func Errorf(template string, args ...interface{})

func Errorw

func Errorw(msg string, keysAndValues ...interface{})

func Info

func Info(args ...interface{})

func Infod

func Infod(msg string, fields ...Field)

func Infof

func Infof(template string, args ...interface{})

func Infow

func Infow(msg string, keysAndValues ...interface{})

func Panic

func Panic(args ...interface{})

func Panicd

func Panicd(msg string, fields ...Field)

func Panicf

func Panicf(template string, args ...interface{})

func Panicw

func Panicw(msg string, keysAndValues ...interface{})

func Warn

func Warn(args ...interface{})

func Warnd

func Warnd(msg string, fields ...Field)

func Warnf

func Warnf(template string, args ...interface{})

func Warnw

func Warnw(msg string, keysAndValues ...interface{})

Types

type Config

type Config struct {
	Debug      bool          // 是否开启debug模式,默认false
	Level      string        // 日志等级
	Stdout     bool          // 是否在控制台打印,默认,true
	Rotate     *RotateConfig // 是否文件日志输出
	Fields     []zap.Field   // 初始化字段
	AddCaller  bool          // 是否打印调用者信息,默认,true
	CallerSkip int           // 表示输出当前栈帧,默认,1

	Core zapcore.Core
	// contains filtered or unexported fields
}

func DefaultConfig

func DefaultConfig() Config

获取一个默认的配置

func RawConfig

func RawConfig(key string) *Config

RawConfig 根据当前组件key获取配置信息创建logger

func ScanConfig

func ScanConfig(name string) *Config

ScanConfig 根据配置名获取配置信息

func (Config) Build

func (c Config) Build() Logger

创建logger

type Field

type Field = zap.Field

type Func

type Func func(string, ...zap.Field)

type Level

type Level = zapcore.Level

type Logger

type Logger interface {
	AutoLevel(key string)
	SetLevel(level Level)
	AddCallerSkip(i int) Logger
	With(...Field) Logger
	// Sugar
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	DPanic(args ...interface{})
	Panic(args ...interface{})
	// Sugar f
	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errorf(template string, args ...interface{})
	DPanicf(template string, args ...interface{})
	Panicf(template string, args ...interface{})
	// Sugar w
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	DPanicw(msg string, keysAndValues ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	// DeSugar
	Debugd(msg string, fields ...Field)
	Infod(msg string, fields ...Field)
	Warnd(msg string, fields ...Field)
	Errord(msg string, fields ...Field)
	DPanicd(msg string, fields ...Field)
	Panicd(msg string, fields ...Field)
}

type Rotate

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

func (*Rotate) Close

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

Close 实现io.WriterClose的close方法

func (*Rotate) Rotate

func (r *Rotate) Rotate() error

Rotate 启动日志切割,

func (*Rotate) Write

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

Write 写入日志方法,上层调用

type RotateConfig

type RotateConfig struct {
	Name       string        // Name 		日志文件路径。默认为空,表示关闭,仅输出到终端
	MaxSize    int           // MaxSize 		按照日志文件大小对文件进行滚动切分。默认为0,表示关闭滚动切分特性
	MaxAge     int           // MaxAge		按照切分的文件有效期清理切分文件,当滚动切分特性开启时有效。默认为0,表示不备份,切分则删除
	MaxBackups int           // MaxBackups	文件保存的最大数量,默认值为10
	Interval   time.Duration // Interval		日志轮转的时间,默认当前条件无效
	LocalTime  bool          // LocalTime	LocalTime确定用于格式化中的时间戳的时间,备份文件是计算机的本地时间
	Compress   bool          // Compress		是否使用gzip压缩日志文件,默认不压缩
}

日志分割配置信息

func NewDefaultRotateConfig

func NewDefaultRotateConfig() *RotateConfig

func (*RotateConfig) Build

func (rc *RotateConfig) Build() *Rotate

根据配置文件构建实例

Jump to

Keyboard shortcuts

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