log

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultLogger 默认logger
	DefaultLogger   = LoggerZap
	DefaultLogLevel = InfoLog
	// DefaultBaseLogLevel 默认基础日志级别
	DefaultBaseLogLevel = DefaultLogLevel
	// DefaultStatLogLevel 默认统计日志级别
	DefaultStatLogLevel = DefaultLogLevel
	// DefaultDetectLogLevel 默认探测日志级别
	DefaultDetectLogLevel = DefaultLogLevel
	// DefaultStatReportLogLevel 默认统计上报日志级别
	DefaultStatReportLogLevel = DefaultLogLevel
	// DefaultNetworkLogLevel 默认网络交互日志级别
	DefaultNetworkLogLevel = DefaultLogLevel
	// DefaultCacheLogLevel 默认缓存日志级别
	DefaultCacheLogLevel = DefaultLogLevel
)
View Source
const (
	// DefaultErrorOutputPath 默认直接错误输出路径
	DefaultErrorOutputPath = "stderr"
	// DefaultRotationMaxAge 默认滚动日志保留时间
	DefaultRotationMaxAge = 30
	// DefaultRotationMaxSize 默认单个日志最大占用空间
	DefaultRotationMaxSize = 50
	// DefaultRotationMaxBackups 默认最大滚动备份
	DefaultRotationMaxBackups = 5
	// DefaultLogRotationRootDir 默认日志根目录
	DefaultLogRotationRootDir = "./polaris/log"
	// DefaultBaseLogRotationPath 默认基础日志滚动文件
	DefaultBaseLogRotationPath = "/base/polaris.log"
	// DefaultStatLogRotationPath 默认统计日志滚动文件
	DefaultStatLogRotationPath = "/stat/polaris-stat.log"
	// DefaultStatReportLogRotationPath 默认统计上报日志滚动文件
	DefaultStatReportLogRotationPath = "/statReport/polaris-statReport.log"
	// DefaultDetectLogRotationPath 默认探测日志滚动文件
	DefaultDetectLogRotationPath = "/detect/polaris-detect.log"
	// DefaultNetworkLogRotationPath 默认网络交互日志滚动文件
	DefaultNetworkLogRotationPath = "/network/polaris-network.log"
	// DefaultCacheLogRotationPath 默认缓存更新日志滚动文件
	DefaultCacheLogRotationPath = "/cache/polaris-cache.log"
	// DefaultBaseLogRotationFile 默认基础日志滚动文件全路径
	DefaultBaseLogRotationFile = DefaultLogRotationRootDir + DefaultBaseLogRotationPath
	// DefaultStatLogRotationFile 默认统计日志滚动文件全路径
	DefaultStatLogRotationFile = DefaultLogRotationRootDir + DefaultStatLogRotationPath
	// DefaultStatReportLogRotationFile 默认统计上报日志滚动文件全路径
	DefaultStatReportLogRotationFile = DefaultLogRotationRootDir + DefaultStatReportLogRotationPath
	// DefaultDetectLogRotationFile 默认探测日志滚动文件全路径
	DefaultDetectLogRotationFile = DefaultLogRotationRootDir + DefaultDetectLogRotationPath
	// DefaultNetworkLogRotationFile 默认网络交互日志滚动文件全路径
	DefaultNetworkLogRotationFile = DefaultLogRotationRootDir + DefaultNetworkLogRotationPath
	// DefaultCacheLogRotationFile 默认缓存更新日志滚动文件全路径
	DefaultCacheLogRotationFile = DefaultLogRotationRootDir + DefaultCacheLogRotationPath
)
View Source
const (
	// TraceLog 跟踪级别
	TraceLog int = iota
	// DebugLog 调试级别
	DebugLog
	// InfoLog 一般日志级别
	InfoLog
	// WarnLog 警告日志级别
	WarnLog
	// ErrorLog 错误日志级别
	ErrorLog
	// FatalLog 致命级别
	FatalLog
	// NoneLog 当要禁止日志的时候,可以设置此级别
	NoneLog
)
View Source
const (
	// BaseLogger 基础日志对象
	BaseLogger = iota
	// StatLogger 统计日志对象
	StatLogger
	// StatReportLogger 统计日志上报对象,记录上报日志的情况
	StatReportLogger
	// DetectLogger 探测日志对象
	DetectLogger
	// NetworkLogger 与系统服务进行网络交互的相关日志
	NetworkLogger
	// CacheLogger 缓存更新日志
	CacheLogger
	// MaxLogger 日志对象总量
	MaxLogger
)

日志类型

View Source
const (
	// LoggerZap zap实现的logger
	LoggerZap = "zaplog"
)

Variables

View Source
var SeverityName = []string{
	TraceLog: "TRACE",
	DebugLog: "DEBUG",
	InfoLog:  "INFO",
	WarnLog:  "WARNING",
	ErrorLog: "ERROR",
	FatalLog: "FATAL",
}

SeverityName severity Name contains the string representation of each severity.

Functions

func ConfigBaseLogger

func ConfigBaseLogger(pluginName string, options *Options) error

ConfigBaseLogger 配置基础日志器

func ConfigCacheLogger

func ConfigCacheLogger(pluginName string, options *Options) error

ConfigCacheLogger 配置缓存日志器

func ConfigDefaultBaseLogger

func ConfigDefaultBaseLogger(pluginName string) error

ConfigDefaultBaseLogger 配置默认的基础日志器

func ConfigDefaultCacheLogger

func ConfigDefaultCacheLogger(pluginName string) error

ConfigDefaultCacheLogger 配置默认的缓存日志器

func ConfigDefaultDetectLogger

func ConfigDefaultDetectLogger(pluginName string) error

ConfigDefaultDetectLogger 配置默认的探测日志器

func ConfigDefaultNetworkLogger

func ConfigDefaultNetworkLogger(pluginName string) error

ConfigDefaultNetworkLogger 配置默认的网络交互日志器

func ConfigDefaultStatLogger

func ConfigDefaultStatLogger(pluginName string) error

ConfigDefaultStatLogger 配置默认的统计日志器

func ConfigDefaultStatReportLogger

func ConfigDefaultStatReportLogger(pluginName string) error

ConfigDefaultStatReportLogger 配置默认的统计上报日志器

func ConfigDetectLogger

func ConfigDetectLogger(pluginName string, options *Options) error

ConfigDetectLogger 配置探测日志器

func ConfigNetworkLogger

func ConfigNetworkLogger(pluginName string, options *Options) error

ConfigNetworkLogger 配置网络交互日志器

func ConfigStatLogger

func ConfigStatLogger(pluginName string, options *Options) error

ConfigStatLogger 配置统计日志器

func ConfigStatReportLogger

func ConfigStatReportLogger(pluginName string, options *Options) error

ConfigStatReportLogger 配置统计上报日志器

func RegisterLoggerCreator

func RegisterLoggerCreator(name string, creator loggerCreator)

RegisterLoggerCreator 注册Logger插件

func SetBaseLogger

func SetBaseLogger(logger Logger)

SetBaseLogger 全局设置基础日志对象

func SetCacheLogger

func SetCacheLogger(logger Logger)

SetCacheLogger 全局设置缓存日志对象

func SetDetectLogger

func SetDetectLogger(logger Logger)

SetDetectLogger 全局设置探测日志对象

func SetNetworkLogger

func SetNetworkLogger(logger Logger)

SetNetworkLogger 全局设置网络交互日志对象

func SetStatLogger

func SetStatLogger(logger Logger)

SetStatLogger 全局设置统计日志对象

func SetStatReportLogger

func SetStatReportLogger(logger Logger)

SetStatReportLogger 全局设置统计上报日志对象

func VerifyLogLevel

func VerifyLogLevel(level int) error

VerifyLogLevel 校验日志级别

Types

type DirLogger

type DirLogger interface {
	Logger
	GetLogDir() string
}

DirLogger 可以返回日志目录的日志对象

type Logger

type Logger interface {
	// Tracef 打印trace级别的日志
	Tracef(format string, args ...interface{})
	// Debugf 打印debug级别的日志
	Debugf(format string, args ...interface{})
	// Infof 打印info级别的日志
	Infof(format string, args ...interface{})
	// Warnf 打印warn级别的日志
	Warnf(format string, args ...interface{})
	// Errorf 打印error级别的日志
	Errorf(format string, args ...interface{})
	// Fatalf 打印fatalf级别的日志
	Fatalf(format string, args ...interface{})
	// IsLevelEnabled 判断当前级别是否满足日志打印的最低级别
	IsLevelEnabled(l int) bool
	// SetLogLevel 动态设置日志打印级别
	SetLogLevel(l int) error
}

Logger logger object @brief 日志对象,封装了日志打印的接口逻辑

func GetBaseLogger

func GetBaseLogger() Logger

GetBaseLogger 获取全局基础日志对象

func GetCacheLogger

func GetCacheLogger() Logger

GetCacheLogger 获取缓存更新日志对象

func GetDetectLogger

func GetDetectLogger() Logger

GetDetectLogger 获取全局探测日志对象

func GetNetworkLogger

func GetNetworkLogger() Logger

GetNetworkLogger 获取全局网络交互日志对象

func GetStatLogger

func GetStatLogger() Logger

GetStatLogger 获取全局统计日志对象

func GetStatReportLogger

func GetStatReportLogger() Logger

GetStatReportLogger 获取统计上报日志对象

type Options

type Options struct {
	// OutputPaths is a list of file system paths to write the log data to.
	// The special values stdout and stderr can be used to output to the
	// standard I/O streams. This defaults to stdout.
	OutputPaths []string

	// ErrorOutputPaths is a list of file system paths to write logger errors to.
	// The special values stdout and stderr can be used to output to the
	// standard I/O streams. This defaults to stderr.
	ErrorOutputPaths []string

	// RotateOutputPath is the path to a rotating log file. This file should
	// be automatically rotated over time, based on the rotation parameters such
	// as RotationMaxSize and RotationMaxAge. The default is to not rotate.
	//
	// This path is used as a foundational path. This is where log output is normally
	// saved. When a rotation needs to take place because the file got too big or too
	// old, then the file is renamed by appending a timestamp to the name. Such renamed
	// files are called backups. Once a backup has been created,
	// output resumes to this path.
	RotateOutputPath string

	// RotationMaxSize is the maximum size in megabytes of a log file before it gets
	// rotated. It defaults to 100 megabytes.
	RotationMaxSize int

	// RotationMaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename. Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is to remove log files
	// older than 30 days.
	RotationMaxAge int

	// RotationMaxBackups is the maximum number of old log files to retain.  The default
	// is to retain at most 1000 logs.
	RotationMaxBackups int

	// The min log level that actual log output
	LogLevel int
}

Options defines the set of options for component logging package.

func CreateDefaultLoggerOptions

func CreateDefaultLoggerOptions(rotationPath string, logLevel int) *Options

CreateDefaultLoggerOptions 配置默认的日志插件

func (Options) Verify

func (o Options) Verify() error

Verify 校验日志配置项

Jump to

Keyboard shortcuts

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