Documentation ¶
Index ¶
- Constants
- Variables
- func AccessLog(args ...interface{})
- func AccessLogf(format string, args ...interface{})
- func BalanceLog(args ...interface{})
- func BalanceLogf(format string, args ...interface{})
- func CrashLog(args ...interface{})
- func CrashLogf(format string, args ...interface{})
- func Debug(args ...interface{})
- func Debugf(format string, args ...interface{})
- func Debugw(msg string, keysAndValues ...interface{})
- func Error(args ...interface{})
- func Errorf(format string, args ...interface{})
- func Errorw(msg string, keysAndValues ...interface{})
- func Fatal(args ...interface{})
- func Fatalf(format string, args ...interface{})
- func Fatalw(msg string, keysAndValues ...interface{})
- func GenLog(args ...interface{})
- func GenLogf(format string, args ...interface{})
- func Info(args ...interface{})
- func Infof(format string, args ...interface{})
- func Infow(msg string, keysAndValues ...interface{})
- func InfraLog(args ...interface{})
- func InfraLogf(format string, args ...interface{})
- func MilliSecondTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
- func NewKit(access *Logger, balance *Logger, slow *Logger, gen *Logger, crash *Logger, ...) *kit
- func NewTimeEncoder(timeFormat string) func(time.Time, zapcore.PrimitiveArrayEncoder)
- func SlowLog(args ...interface{})
- func SlowLogf(format string, args ...interface{})
- func Sync() error
- func Warn(args ...interface{})
- func Warnf(format string, args ...interface{})
- func Warnw(msg string, keysAndValues ...interface{})
- type IOWriter
- type Level
- type Logger
- func (l *Logger) For(ctx context.Context, args ...interface{}) *Logger
- func (l *Logger) Init() error
- func (l *Logger) Level() Level
- func (l *Logger) Logger() *log.Logger
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) SetLogPrefix(prefix string)
- func (l *Logger) SetOutput() error
- func (l *Logger) SetPrintLevel(printLevel bool)
- func (l *Logger) SetTimeFmt(fmt string) error
- func (l *Logger) String() string
- func (l *Logger) With(args ...interface{}) *Logger
- type Options
- type RollingFile
- type RollingFormat
Constants ¶
const ( MonthlyRolling RollingFormat = "200601" DailyRolling = "20060102" HourlyRolling = "2006010215" MinutelyRolling = "200601021504" SecondlyRolling = "20060102150405" )
RollingFormats
const ( FrequencyHourly = 0 FrequencyDaily = 1 FrequencyMonthly = 2 )
Rotate frequencies
Variables ¶
var ( ErrClosedRollingFile = errors.New("rolling file is closed") ErrBuffer = errors.New("buffer exceeds the limit") )
Errors
var (
DefaultKit *kit
)
Functions ¶
func AccessLogf ¶
func AccessLogf(format string, args ...interface{})
func BalanceLog ¶
func BalanceLog(args ...interface{})
func BalanceLogf ¶
func BalanceLogf(format string, args ...interface{})
func Debugf ¶
func Debugf(format string, args ...interface{})
Debugf uses fmt.Sprintf to log a templated message.
func Debugw ¶
func Debugw(msg string, keysAndValues ...interface{})
Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
When debug-level logging is disabled, this is much faster than
s.With(keysAndValues).Debug(msg)
func Errorf ¶
func Errorf(format string, args ...interface{})
Errorf uses fmt.Sprintf to log a templated message.
func Errorw ¶
func Errorw(msg string, keysAndValues ...interface{})
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func Fatal ¶
func Fatal(args ...interface{})
Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.
func Fatalf ¶
func Fatalf(format string, args ...interface{})
Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
func Fatalw ¶
func Fatalw(msg string, keysAndValues ...interface{})
Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.
func Infof ¶
func Infof(format string, args ...interface{})
Infof uses fmt.Sprintf to log a templated message.
func Infow ¶
func Infow(msg string, keysAndValues ...interface{})
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func MilliSecondTimeEncoder ¶
func MilliSecondTimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)
func NewTimeEncoder ¶
func NewTimeEncoder(timeFormat string) func(time.Time, zapcore.PrimitiveArrayEncoder)
Types ¶
type IOWriter ¶
type IOWriter struct {
// contains filtered or unexported fields
}
IOWriter : On-disk writer with rotator
type Level ¶
type Level string
const ( DebugLevel Level = "DEBUG" // InfoLevel is the default logging priority. // General operational entries about what's going on inside the application. InfoLevel Level = "INFO" // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel Level = "WARN" // ErrorLevel level. Logs. Used for errors that should definitely be noted. ErrorLevel Level = "ERROR" // FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity. FatalLevel Level = "FATAL" )
type Logger ¶
type Logger struct { *zap.SugaredLogger // contains filtered or unexported fields }
var ( // DefaultLogger implementated Logger, can override by any instance DefaultLogger *Logger )
func With ¶
func With(args ...interface{}) *Logger
With adds a variadic number of fields to the logging context. It accepts a mix of strongly-typed Field objects and loosely-typed key-value pairs. When processing pairs, the first element of the pair is used as the field key and the second as the field value.
For example,
sugaredLogger.With( "hello", "world", "failure", errors.New("oh no"), Stack(), "count", 42, "user", User{Name: "alice"}, )
is the equivalent of
unsugared.With( String("hello", "world"), String("failure", "oh no"), Stack(), Int("count", 42), Object("user", User{Name: "alice"}), )
Note that the keys in key-value pairs should be strings. In development, passing a non-string key panics. In production, the logger is more forgiving: a separate error is logged, but the key-value pair is skipped and execution continues. Passing an orphaned key triggers similar behavior: panics in development and errors in production.
func (*Logger) SetLogPrefix ¶
func (*Logger) SetPrintLevel ¶
func (*Logger) SetTimeFmt ¶
type Options ¶
type Options struct { // The logging level the logger should log at. default is `InfoLevel` Level Level // Alternative options Context context.Context // EnableConsole display logs to standard output EnableConsole bool // DisableOnDisk disable rolling file DisableOnDisk bool // BasePath defines base path of log file BasePath string // logger file name FileName string CallerSkip int }
Options : Logger options
type RollingFile ¶
type RollingFile struct {
// contains filtered or unexported fields
}
RollingFile : Defination of rolling
func NewRollingFile ¶
func NewRollingFile(basePath string, rolling RollingFormat) (*RollingFile, error)
NewRollingFile create new rolling
func (*RollingFile) SetRolling ¶
func (r *RollingFile) SetRolling(fmt RollingFormat)
SetRolling : Set rolling format