Documentation ¶
Index ¶
- Constants
- type Log
- func (l *Log) AddWriters(ws ...LogWriter)
- func (l *Log) Debug(args ...interface{})
- func (l *Log) Debugf(format string, args ...interface{})
- func (l *Log) Error(args ...interface{})
- func (l *Log) Errorf(format string, args ...interface{})
- func (l *Log) Info(args ...interface{})
- func (l *Log) Infof(format string, args ...interface{})
- func (l *Log) Warn(args ...interface{})
- func (l *Log) Warnf(format string, args ...interface{})
- type LogConfig
- type LogFormatter
- type LogLevel
- type LogSimpleFormatter
- type LogStreamWriter
- type LogStreamWriterOption
- type LogWriter
- type Logger
Constants ¶
const (
DefaultLogSimpleFormatterTmpl = "%timestamp% %level% --- [%pkg%] %args%"
)
const (
DefaultTimeFormat = "2006-01-02 15:04:05.000"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log is the top-level logger instance. However, it is only an abstracted entrypoint, and need to set LogWriter for output and LogFormatter for formatting.
func (*Log) AddWriters ¶
AddWriters adds LogWriter to Log.
type LogConfig ¶
type LogConfig struct { // Multiple LogWriters can be configured to output logs to multiple destinations. Writers []LogWriter // Only one LogFormatter can be set per Log instance. Formatter LogFormatter // The default value for TimeFormat is DefaultTimeFormat. TimeFormat string // The default value for LogMinLevel is LevelInfo. LogMinLevel LogLevel }
LogConfig is the configurations of Log. There is no way to configure settings directly in the Log, and can only change settings through this config.
type LogFormatter ¶
LogFormatter is the interface that wraps the standard method of Format.
type LogSimpleFormatter ¶
type LogSimpleFormatter struct {
// contains filtered or unexported fields
}
LogSimpleFormatter implements LogFormatter. It outputs simple flat string has params that are timestamp, level, pkg and args. Set each parameter in tmpl freely arranged by enclosing each parameter in % like %timestamp%. The default value of tmpl is DefaultLogSimpleFormatterTmpl. The args param is identical to the args passed in the Logger interface method.
func NewLogSimpleFormatter ¶
func NewLogSimpleFormatter(tmpl string) *LogSimpleFormatter
func (*LogSimpleFormatter) Format ¶
func (f *LogSimpleFormatter) Format(timestamp, level, pkg string, args ...interface{}) string
type LogStreamWriter ¶
type LogStreamWriter struct {
// contains filtered or unexported fields
}
LogStreamWriter implements LogWriter. It is an asynchronous log writer with an internal buffer of log strings and a log output goroutine.
func NewLogStreamWriter ¶
func NewLogStreamWriter(opts LogStreamWriterOption) *LogStreamWriter
NewLogStreamWriter creates LogStreamWriter but does not start logging. Execute LogStreamWriter.Open is required to start logging.
func (*LogStreamWriter) Close ¶
func (w *LogStreamWriter) Close()
Close terminates acceptance of logs and outputs logs accumulated in the buffer.
func (*LogStreamWriter) Open ¶
func (w *LogStreamWriter) Open()
Open starts synchronization of the output goroutine.
func (*LogStreamWriter) Write ¶
func (w *LogStreamWriter) Write(msg string)
type LogStreamWriterOption ¶
type LogStreamWriterOption struct { // Output is the log output destination. // Default is os.Stderr. Output *os.File // SyncIntervalMills is the log output interval. // Default is 100. SyncIntervalMills int64 }
LogStreamWriterOption is the options of LogStreamWriter. There is no way to configure options directly in the LogStreamWriter, and can only change settings through this option.
type LogWriter ¶
type LogWriter interface {
Write(msg string)
}
LogWriter is the interface that wraps standard method of Write.
type Logger ¶
type Logger interface { Info(args ...interface{}) Debug(args ...interface{}) Warn(args ...interface{}) Error(args ...interface{}) Infof(format string, args ...interface{}) Debugf(format string, args ...interface{}) Warnf(format string, args ...interface{}) Errorf(format string, args ...interface{}) }
Logger is the interface that wraps the methods for logging.