Documentation
¶
Index ¶
- Variables
- func NewFileWriter(path string) (*os.File, error)
- func SetDefaultLogger(l *Logger)
- func SetInternalLogger(l *Logger)
- type BufferedFileWriter
- type ByteFormatPart
- type BytesFormatPart
- type ConsoleWriter
- type DateFormatPart
- type DiscardWriter
- type FormatPart
- type Formatter
- type Handler
- type Level
- type LevelFormatPart
- type Logger
- func (l *Logger) AddHandler(h *Handler)
- func (l *Logger) Close()
- func (l *Logger) Crit(args ...interface{})
- func (l *Logger) Critf(msg string, args ...interface{})
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(msg string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(msg string, args ...interface{})
- func (l *Logger) GetMinLevel() Level
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(msg string, args ...interface{})
- func (l *Logger) IsEnabledFor(level Level) bool
- func (l *Logger) Log(lv Level, msg string, args ...interface{})
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(msg string, args ...interface{})
- type MessageFormatPart
- type Record
- type RotateDuration
- type RotatingFileWriter
- type TimeFormatPart
- type TimedRotatingFileWriter
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultFormatter is the default formatter DefaultFormatter = ParseFormat("%D %T %l %m") // TimedRotatingFormatter is a formatter for TimedRotatingFileWriter TimedRotatingFormatter = ParseFormat("[%l %T] %m") )
var Crit func(args ...interface{})
Crit logs a _critical level message. It uses fmt.Fprint() to format args.
var Critf func(msg string, args ...interface{})
Critf logs a _critical level message. It uses fmt.Fprintf() to format msg and args.
var Debug func(args ...interface{})
Debug logs a _debug level message. It uses fmt.Fprint() to format args.
var Debugf func(msg string, args ...interface{})
Debugf logs a _debug level message. It uses fmt.Fprintf() to format msg and args.
var Error func(args ...interface{})
Error logs an _error level message. It uses fmt.Fprint() to format args.
var Errorf func(msg string, args ...interface{})
Errorf logs a _error level message. It uses fmt.Fprintf() to format msg and args.
var Info func(args ...interface{})
Info logs a _info level message. It uses fmt.Fprint() to format args.
var Infof func(msg string, args ...interface{})
Infof logs a _info level message. It uses fmt.Fprintf() to format msg and args.
var (
//StampNano = "15:04:05.000000000+07:00"
StampNano = "15:04:05.000000Z0700"
)
var Warn func(args ...interface{})
Warn logs a _warning level message. It uses fmt.Fprint() to format args.
var Warnf func(msg string, args ...interface{})
Warnf logs a _warning level message. It uses fmt.Fprintf() to format msg and args.
Functions ¶
func NewFileWriter ¶
NewFileWriter creates a FileWriter by its path.
func SetDefaultLogger ¶
func SetDefaultLogger(l *Logger)
SetDefaultLogger set the logger as the defaultLogger. The logging functions in this package use it as their logger. This function should be called before using the others.
func SetInternalLogger ¶
func SetInternalLogger(l *Logger)
SetInternalLogger sets a logger as the internalLogger which is used to log internal errors. The logger and its handlers will be marked as internal, so do not reuse them. The internalLogger may discard its own errors to prevent recursive log.
Types ¶
type BufferedFileWriter ¶
type BufferedFileWriter struct {
// contains filtered or unexported fields
}
A BufferedFileWriter is a buffered file writer. The written bytes will be flushed to the log file every 0.1 second, or when reaching the buffer capacity (4 MB).
func NewBufferedFileWriter ¶
func NewBufferedFileWriter(path string) (*BufferedFileWriter, error)
NewBufferedFileWriter creates a new BufferedFileWriter.
func (*BufferedFileWriter) Close ¶
func (w *BufferedFileWriter) Close() error
Close flushes the buffer, then closes the file writer.
type ByteFormatPart ¶
type ByteFormatPart struct {
// contains filtered or unexported fields
}
ByteFormatPart is a FormatPart containing a byte.
type BytesFormatPart ¶
type BytesFormatPart struct {
// contains filtered or unexported fields
}
BytesFormatPart is a FormatPart containing a byte slice.
type ConsoleWriter ¶
A ConsoleWriter is a writer which should not be acturelly closed.
func NewConsoleWriter ¶
func NewConsoleWriter(f *os.File) *ConsoleWriter
NewConsoleWriter creates a new ConsoleWriter.
func NewStderrWriter ¶
func NewStderrWriter() *ConsoleWriter
NewStderrWriter creates a new stderr writer.
func NewStdoutWriter ¶
func NewStdoutWriter() *ConsoleWriter
NewStdoutWriter creates a new stdout writer.
type DateFormatPart ¶
type DateFormatPart struct{}
DateFormatPart is a FormatPart of the date placeholder.
type DiscardWriter ¶
DiscardWriter is a WriteCloser which write everything to devNull
func NewDiscardWriter ¶
func NewDiscardWriter() *DiscardWriter
NewDiscardWriter creates a new ConsoleWriter.
type FormatPart ¶
FormatPart is an interface containing the Format() method.
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
A Formatter containing a sequence of FormatParts.
func ParseFormat ¶
ParseFormat parses a format string into a formatter.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
A Handler is a leveled log handler with a formatter and several writers.
func NewHandler ¶
NewHandler creates a new Handler of the given level with the formatter. Records with the lower level than the handler will be ignored.
func (*Handler) AddWriter ¶
func (h *Handler) AddWriter(w io.WriteCloser)
AddWriter adds a writer to the Handler. The Write() method of the writer should be thread-safe.
func (*Handler) Close ¶
func (h *Handler) Close()
Close closes all its writers. It's safe to call this method more than once, but it's unsafe to call its writers' Close() more than once.
func (*Handler) Handle ¶
Handle formats a record using its formatter, then writes the formatted result to all of its writers. Returns true if it can handle the record. The errors during writing will be logged by the internalLogger. It's not thread-safe, concurrent record may be written in a random order through different writers. But two records won't be mixed in a single line.
type LevelFormatPart ¶
type LevelFormatPart struct{}
LevelFormatPart is a FormatPart of the level placeholder.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
A Logger is a leveled logger with several handlers.
func NewLogger ¶
NewLogger creates a new Logger of the given level. Messages with lower level than the logger will be ignored.
func NewLoggerWithWriter ¶
func NewLoggerWithWriter(w io.WriteCloser) *Logger
NewLoggerWithWriter creates an info level logger with a writer.
func NewStderrLogger ¶
func NewStderrLogger() *Logger
NewStderrLogger creates a logger with a stderr writer.
func NewStdoutLogger ¶
func NewStdoutLogger() *Logger
NewStdoutLogger creates a logger with a stdout writer.
func (*Logger) AddHandler ¶
AddHandler adds a Handler to the Logger. A handler with lower level than the logger will be ignored.
func (*Logger) Close ¶
func (l *Logger) Close()
Close closes its handlers. It's safe to call this method more than once.
func (*Logger) Crit ¶
func (l *Logger) Crit(args ...interface{})
Crit logs a critical level message. It uses fmt.Fprint() to format args.
func (*Logger) Critf ¶
Critf logs a critical level message. It uses fmt.Fprintf() to format msg and args.
func (*Logger) Debug ¶
func (l *Logger) Debug(args ...interface{})
Debug logs a debug level message. It uses fmt.Fprint() to format args.
func (*Logger) Debugf ¶
Debugf logs a debug level message. It uses fmt.Fprintf() to format msg and args.
func (*Logger) Error ¶
func (l *Logger) Error(args ...interface{})
Error logs an error level message. It uses fmt.Fprint() to format args.
func (*Logger) Errorf ¶
Errorf logs a error level message. It uses fmt.Fprintf() to format msg and args.
func (*Logger) GetMinLevel ¶
GetMinLevel returns its minLevel. Records lower than its minLevel will be ignored.
func (*Logger) Info ¶
func (l *Logger) Info(args ...interface{})
Info logs a info level message. It uses fmt.Fprint() to format args.
func (*Logger) Infof ¶
Infof logs a info level message. It uses fmt.Fprintf() to format msg and args.
func (*Logger) IsEnabledFor ¶
IsEnabledFor returns whether it's enabled for the level
func (*Logger) Log ¶
Log logs a message with context. A logger should check the message level before call its Log(). The line param should be uint32. It's not thread-safe, concurrent messages may be written in a random order through different handlers or writers. But two messages won't be mixed in a single line.
type MessageFormatPart ¶
type MessageFormatPart struct{}
MessageFormatPart is a FormatPart of the message placeholder.
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
A Record is an item which contains required context for the logger.
type RotateDuration ¶
type RotateDuration uint8
RotateDuration specifies rotate duration type, should be either RotateByDate or RotateByHour.
const ( // RotateByDate set the log file to be rotated each day. RotateByDate RotateDuration = iota // RotateByHour set the log file to be rotated each hour. RotateByHour )
type RotatingFileWriter ¶
type RotatingFileWriter struct {
BufferedFileWriter
// contains filtered or unexported fields
}
A RotatingFileWriter is a buffered file writer which will rotate before reaching its maxSize. An exception is when a record is larger than maxSize, it won't be separated into 2 files. It keeps at most backupCount backups.
func NewRotatingFileWriter ¶
func NewRotatingFileWriter(path string, maxSize uint64, backupCount uint8) (*RotatingFileWriter, error)
NewRotatingFileWriter creates a new RotatingFileWriter.
type TimeFormatPart ¶
type TimeFormatPart struct{}
TimeFormatPart is a FormatPart of the time placeholder.
type TimedRotatingFileWriter ¶
type TimedRotatingFileWriter struct {
BufferedFileWriter
// contains filtered or unexported fields
}
A TimedRotatingFileWriter is a buffered file writer which will rotate by time. Its rotateDuration can be either RotateByDate or RotateByHour. It keeps at most backupCount backups.
func NewTimedRotatingFileWriter ¶
func NewTimedRotatingFileWriter(pathPrefix string, rotateDuration RotateDuration, backupCount uint8) (*TimedRotatingFileWriter, error)
NewTimedRotatingFileWriter creates a new TimedRotatingFileWriter.