hwlog

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package hwlog provides the capability of processing Huawei log rules.

Package hwlog provides the capability of processing Huawei log rules.

Package hwlog provides the capability of processing Huawei log rules.

Package hwlog provides the capability of processing Huawei log rules.

Package hwlog provides the capability of processing Huawei log rules.

Package hwlog provides the capability of processing Huawei log rules.

Package hwlog provides the capability of processing Huawei log rules.

Index

Constants

View Source
const (
	// MaxCacheSize indicates the maximum log cache size
	MaxCacheSize = 100 * 1024
	// MaxExpiredTime indicates the maximum log cache expired time
	MaxExpiredTime = 60 * 60
	// DefaultCacheSize indicates the default log cache size
	DefaultCacheSize = 10 * 1024
	// DefaultExpiredTime indicates the default log cache expired time
	DefaultExpiredTime = 1
)
View Source
const (
	// DefaultFileMaxSize  the default maximum size of a single log file is 20 MB
	DefaultFileMaxSize = 20
	// DefaultMinSaveAge the minimum storage duration of backup logs is 7 days
	DefaultMinSaveAge = 7
	// DefaultMaxSaveAge the maximum storage duration of backup logs is 700 days
	DefaultMaxSaveAge = 700
	// DefaultMaxBackups the default number of backup log
	DefaultMaxBackups = 30
	// LogFileMode log file mode
	LogFileMode os.FileMode = 0640
	// BackupLogFileMode backup log file mode
	BackupLogFileMode os.FileMode = 0400
	// LogDirMode log dir mode
	LogDirMode = 0750
)

Variables

View Source
var DebugLog *logger

DebugLog debug logger

View Source
var OpLog *logger

OpLog operate logger

View Source
var RunLog *logger

RunLog run logger

View Source
var SecLog *logger

SecLog security logger

View Source
var UserLog *logger

UserLog user logger

Functions

func InitDebugLogger

func InitDebugLogger(config *LogConfig, ctx context.Context) error

InitDebugLogger initialize debug logger

func InitOperateLogger

func InitOperateLogger(config *LogConfig, ctx context.Context) error

InitOperateLogger initialize operate logger

func InitRunLogger

func InitRunLogger(config *LogConfig, ctx context.Context) error

InitRunLogger initialize run logger

func InitSecurityLogger

func InitSecurityLogger(config *LogConfig, ctx context.Context) error

InitSecurityLogger initialize security logger

func InitUserLogger

func InitUserLogger(config *LogConfig, ctx context.Context) error

InitUserLogger initialize user logger

Types

type ContextKey

type ContextKey string

ContextKey especially for context value to solve problem of "should not use basic type untyped string as key in context.WithValue"

const (
	// UserID used for context value key of "ID"
	UserID ContextKey = "UserID"
	// ReqID used for context value key of "requestID"
	ReqID ContextKey = "RequestID"
)

func (ContextKey) String

func (c ContextKey) String() string

String the implement of String method

type LogConfig

type LogConfig struct {
	// log file path
	LogFileName string
	// only write to std out, default value: false
	OnlyToStdout bool
	// only write to file, default value: false
	OnlyToFile bool
	// log level, -1-debug, 0-info, 1-warning, 2-error 3-critical default value: 0
	LogLevel int
	// size of a single log file (MB), default value: 20MB
	FileMaxSize int
	// MaxLineLength Max length of each log line, default value: 256
	MaxLineLength int
	// maximum number of backup log files, default value: 30
	MaxBackups int
	// maximum number of days for backup log files, default value: 7
	MaxAge int
	// whether backup files need to be compressed, default value: false
	IsCompress bool
	// expiration time for log cache, default value: 1s
	ExpiredTime int
	// Size of log cache space, default: 10240
	CacheSize int
}

LogConfig log module config

type LogLimiter

type LogLimiter struct {
	// Logs is a log rotate instance
	Logs *Logs

	// CacheSize indicates the size of log cache
	CacheSize int
	// ExpiredTime indicates the expired time of log cache
	ExpiredTime int
	// contains filtered or unexported fields
}

LogLimiter encapsulates Logs and provides the log traffic limiting capability to prevent too many duplicate logs.

func (*LogLimiter) Close

func (l *LogLimiter) Close() error

Close implements io.Closer. It encapsulates the Close method of Logs.

func (*LogLimiter) Flush

func (l *LogLimiter) Flush() error

Flush encapsulates the Flush method of Logs.

func (*LogLimiter) Write

func (l *LogLimiter) Write(d []byte) (int, error)

Write implements io.Writer. It encapsulates the Write method of Los and uses the lru cache to prevent duplicate log writing.

type Logs

type Logs struct {

	// FileName is the file where logs are written.
	FileName string `json:"filename" yaml:"filename"`

	// Capacity is the maximum number of bytes before the log file
	// is rotated, and the default value is 128 megabytes.
	Capacity int `json:"capacity" yaml:"capacity"`

	// SaveTime is the maximum number of days for retaining old log
	// files. It calculates the retention time based on the timestamp
	// of the old log file name and the current time.
	SaveTime int `json:"savetime" yaml:"savetime"`

	// SaveVolume is the maximum number of old log files that can be
	// retained. It saves all old files by default.
	SaveVolume int `json:"savevolume" yaml:"savevolume"`

	// UTC determines whether to use the local time of the computer
	// or the UTC time as the timestamp in the formatted backup file.
	LocalOrUTC bool `json:"localorutc" yaml:"localorutc"`
	// contains filtered or unexported fields
}

Logs is an io.WriteCloser.

func (*Logs) Close

func (l *Logs) Close() error

Close implements io.Closer. It closses the current log file.

func (*Logs) Flush

func (l *Logs) Flush() error

Flush persist the contents of the current memory.

func (*Logs) Roll

func (l *Logs) Roll() error

Roll causes Logs to close the existing log file and create a new log file immediately. The purpose of this function is to provide rotation outside the normal rotation rule, e.g. in response to SIGHUP. After rotation, the deletion of the old log files is initiated.

func (*Logs) Write

func (l *Logs) Write(d []byte) (int, error)

Write implements io.Writer. If a write would not cause the size of the log file to exceed Capacity, the log file is written normally. If a write would cause the size of the log file to exceed Capacity, but the write length is less than Capacity, the log file is closed, renamed to include a timestamp of the current time, and a new log is created using the original log file name. If the length of a write is greater than the Capacity, an error is returned.

type SelfLogWriter

type SelfLogWriter struct {
}

SelfLogWriter used this to replace some opensource log

func (*SelfLogWriter) Write

func (l *SelfLogWriter) Write(p []byte) (int, error)

Write implement the interface of io.writer

Jump to

Keyboard shortcuts

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