Documentation
¶
Index ¶
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 FIFO queue (channel to be exact) 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(timeout time.Duration)
Close terminates acceptance of logs and outputs logs accumulated in the queue. However, since asynchronous goroutine is output while synchronizing, a timeout is set, and synchronization is terminated when the timeout is exceeded.
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
// SyncQueueSize is the log string queue size.
// Default is 10000.
SyncQueueSize uint16
}
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.