Documentation ¶
Index ¶
- Constants
- Variables
- func Alert(v string)
- func Close() error
- func CollectSysLog()
- func Disable()
- func DisableStat()
- func Error(v ...interface{})
- func ErrorCaller(callDepth int, v ...interface{})
- func ErrorCallerf(callDepth int, format string, v ...interface{})
- func ErrorStack(v ...interface{})
- func ErrorStackf(format string, v ...interface{})
- func Errorf(format string, v ...interface{})
- func Errorv(v interface{})
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func Infov(v interface{})
- func Must(err error)
- func MustSetup(c LogConf)
- func SetLevel(level uint32)
- func SetUp(c LogConf) error
- func Severe(v ...interface{})
- func Severef(format string, v ...interface{})
- func Slow(v ...interface{})
- func Slowf(format string, v ...interface{})
- func Slowv(v interface{})
- func Stat(v ...interface{})
- func Statf(format string, v ...interface{})
- type DailyRotateRule
- type LessLogger
- type LogConf
- type LogOption
- type Logger
- type RotateLogger
- type RotateRule
Constants ¶
const ( // InfoLevel logs everything InfoLevel = iota // ErrorLevel includes errors, slows, stacks ErrorLevel // SevereLevel only log severe messages SevereLevel )
Variables ¶
var ( // ErrLogPathNotSet is an error that indicates the log path is not set. ErrLogPathNotSet = errors.New("log path must be set") // ErrLogNotInitialized is an error that log is not initialized. ErrLogNotInitialized = errors.New("log not initialized") // ErrLogServiceNameNotSet is an error that indicates that the service name is not set. ErrLogServiceNameNotSet = errors.New("log service name must be set") )
var ErrLogFileClosed = errors.New("error: log file closed")
ErrLogFileClosed is an error that indicates the log file is already closed.
Functions ¶
func Alert ¶ added in v1.0.21
func Alert(v string)
Alert alerts v in alert level, and the message is written to error log.
func ErrorCaller ¶
func ErrorCaller(callDepth int, v ...interface{})
ErrorCaller writes v with context into error log.
func ErrorCallerf ¶
ErrorCallerf writes v with context in format into error log.
func ErrorStack ¶
func ErrorStack(v ...interface{})
ErrorStack writes v along with call stack into error log.
func ErrorStackf ¶
func ErrorStackf(format string, v ...interface{})
ErrorStackf writes v along with call stack in format into error log.
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf writes v with format into error log.
func Errorv ¶ added in v1.2.0
func Errorv(v interface{})
Errorv writes v into error log with json content. No call stack attached, because not elegant to pack the messages.
func Infof ¶
func Infof(format string, v ...interface{})
Infof writes v with format into access log.
func Infov ¶ added in v1.2.0
func Infov(v interface{})
Infov writes v into access log with json content.
func Must ¶ added in v1.0.3
func Must(err error)
Must checks if err is nil, otherwise logs the err and exits.
func MustSetup ¶
func MustSetup(c LogConf)
MustSetup sets up logging with given config c. It exits on error.
func SetLevel ¶
func SetLevel(level uint32)
SetLevel sets the logging level. It can be used to suppress some logs.
func SetUp ¶
SetUp sets up the logx. If already set up, just return nil. we allow SetUp to be called multiple times, because for example we need to allow different service frameworks to initialize logx respectively. the same logic for SetUp
func Severef ¶
func Severef(format string, v ...interface{})
Severef writes v with format into severe log.
Types ¶
type DailyRotateRule ¶
type DailyRotateRule struct {
// contains filtered or unexported fields
}
A DailyRotateRule is a rule to daily rotate the log files.
func (*DailyRotateRule) BackupFileName ¶
func (r *DailyRotateRule) BackupFileName() string
BackupFileName returns the backup filename on rotating.
func (*DailyRotateRule) MarkRotated ¶
func (r *DailyRotateRule) MarkRotated()
MarkRotated marks the rotated time of r to be the current time.
func (*DailyRotateRule) OutdatedFiles ¶
func (r *DailyRotateRule) OutdatedFiles() []string
OutdatedFiles returns the files that exceeded the keeping days.
func (*DailyRotateRule) ShallRotate ¶
func (r *DailyRotateRule) ShallRotate() bool
ShallRotate checks if the file should be rotated.
type LessLogger ¶
type LessLogger struct {
// contains filtered or unexported fields
}
A LessLogger is a logger that control to log once during the given duration.
func NewLessLogger ¶
func NewLessLogger(milliseconds int) *LessLogger
NewLessLogger returns a LessLogger.
func (*LessLogger) Error ¶
func (logger *LessLogger) Error(v ...interface{})
Error logs v into error log or discard it if more than once in the given duration.
func (*LessLogger) Errorf ¶
func (logger *LessLogger) Errorf(format string, v ...interface{})
Errorf logs v with format into error log or discard it if more than once in the given duration.
type LogConf ¶
type LogConf struct { ServiceName string `json:",optional"` Mode string `json:",default=console,options=console|file|volume"` TimeFormat string `json:",optional"` Path string `json:",default=logs"` Level string `json:",default=info,options=info|error|severe"` Compress bool `json:",optional"` KeepDays int `json:",optional"` StackCooldownMillis int `json:",default=100"` }
A LogConf is a logging config.
type LogOption ¶
type LogOption func(options *logOptions)
LogOption defines the method to customize the logging.
func WithCooldownMillis ¶
WithCooldownMillis customizes logging on writing call stack interval.
func WithGzip ¶
func WithGzip() LogOption
WithGzip customizes logging to automatically gzip the log files.
func WithKeepDays ¶
WithKeepDays customizes logging to keep logs with days.
type Logger ¶
type Logger interface { Error(...interface{}) Errorf(string, ...interface{}) Errorv(interface{}) Info(...interface{}) Infof(string, ...interface{}) Infov(interface{}) Slow(...interface{}) Slowf(string, ...interface{}) Slowv(interface{}) WithDuration(time.Duration) Logger }
A Logger represents a logger.
func WithContext ¶
WithContext sets ctx to log, for keeping tracing information.
func WithDuration ¶
WithDuration returns a Logger which logs the given duration.
type RotateLogger ¶
type RotateLogger struct {
// contains filtered or unexported fields
}
A RotateLogger is a Logger that can rotate log files with given rules.
func NewLogger ¶
func NewLogger(filename string, rule RotateRule, compress bool) (*RotateLogger, error)
NewLogger returns a RotateLogger with given filename and rule, etc.
type RotateRule ¶
type RotateRule interface { BackupFileName() string MarkRotated() OutdatedFiles() []string ShallRotate() bool }
A RotateRule interface is used to define the log rotating rules.
func DefaultRotateRule ¶
func DefaultRotateRule(filename, delimiter string, days int, gzip bool) RotateRule
DefaultRotateRule is a default log rotating rule, currently DailyRotateRule.