log

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 6 Imported by: 5

Documentation

Index

Constants

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

日志类型

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

Variables

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

severityName contains the string representation of each severity.

Functions

func ConfigBaseLogger

func ConfigBaseLogger(pluginName string, options *Options) error

配置基础日志器

func ConfigDefaultBaseLogger

func ConfigDefaultBaseLogger(pluginName string) error

配置默认的基础日志器

func ConfigDefaultDetectLogger

func ConfigDefaultDetectLogger(pluginName string) error

配置默认的探测日志器

func ConfigDefaultNetworkLogger

func ConfigDefaultNetworkLogger(pluginName string) error

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

func ConfigDefaultStatLogger

func ConfigDefaultStatLogger(pluginName string) error

配置默认的统计日志器

func ConfigDefaultStatReportLogger

func ConfigDefaultStatReportLogger(pluginName string) error

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

func ConfigDetectLogger

func ConfigDetectLogger(pluginName string, options *Options) error

配置探测日志器

func ConfigNetworkLogger

func ConfigNetworkLogger(pluginName string, options *Options) error

配置网络交互日志器

func ConfigStatLogger

func ConfigStatLogger(pluginName string, options *Options) error

配置统计日志器

func ConfigStatReportLogger

func ConfigStatReportLogger(pluginName string, options *Options) error

func RegisterLoggerCreator

func RegisterLoggerCreator(name string, creator loggerCreator)

注册Logger插件

func SetBaseLogger

func SetBaseLogger(logger Logger)

全局设置基础日志对象

func SetDetectLogger

func SetDetectLogger(logger Logger)

全局设置探测日志对象

func SetNetworkLogger

func SetNetworkLogger(logger Logger)

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

func SetStatLogger

func SetStatLogger(logger Logger)

全局设置统计日志对象

func SetStatReportLogger

func SetStatReportLogger(logger Logger)

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

func VerifyLogLevel

func VerifyLogLevel(level int) error

校验日志级别

Types

type DirLogger

type DirLogger interface {
	Logger
	GetLogDir() string
}

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

type Logger

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

*

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

func GetBaseLogger

func GetBaseLogger() Logger

获取全局基础日志对象

func GetDetectLogger

func GetDetectLogger() Logger

获取全局探测日志对象

func GetNetworkLogger

func GetNetworkLogger() Logger

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

func GetStatLogger

func GetStatLogger() Logger

获取全局统计日志对象

func GetStatReportLogger

func GetStatReportLogger() Logger

获取统计上报日志对象

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

配置默认的日志插件

func (Options) Verify

func (o Options) Verify() error

校验日志配置项

Jump to

Keyboard shortcuts

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