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
- Variables
- func InitDebugLogger(config *LogConfig, ctx context.Context) error
- func InitOperateLogger(config *LogConfig, ctx context.Context) error
- func InitRunLogger(config *LogConfig, ctx context.Context) error
- func InitSecurityLogger(config *LogConfig, ctx context.Context) error
- func InitUserLogger(config *LogConfig, ctx context.Context) error
- type ContextKey
- type LogConfig
- type LogLimiter
- type Logs
- type SelfLogWriter
Constants ¶
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 )
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 ¶
var DebugLog *logger
DebugLog debug logger
var OpLog *logger
OpLog operate logger
var RunLog *logger
RunLog run logger
var SecLog *logger
SecLog security logger
var UserLog *logger
UserLog user logger
Functions ¶
func InitDebugLogger ¶
InitDebugLogger initialize debug logger
func InitOperateLogger ¶
InitOperateLogger initialize operate logger
func InitRunLogger ¶
InitRunLogger initialize run logger
func InitSecurityLogger ¶
InitSecurityLogger initialize security 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.
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) Roll ¶
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 ¶
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