Documentation ¶
Index ¶
- Constants
- func Context(ctx context.Context, opts ...interface{}) context.Context
- func CtxDebug(ctx context.Context, args ...interface{})
- func CtxDebugf(ctx context.Context, fmt string, args ...interface{})
- func CtxDebugw(ctx context.Context, msg string, kvs ...interface{})
- func CtxError(ctx context.Context, args ...interface{})
- func CtxErrorf(ctx context.Context, fmt string, args ...interface{})
- func CtxErrorw(ctx context.Context, msg string, kvs ...interface{})
- func CtxInfo(ctx context.Context, args ...interface{})
- func CtxInfof(ctx context.Context, fmt string, args ...interface{})
- func CtxInfow(ctx context.Context, msg string, kvs ...interface{})
- func CtxPanic(ctx context.Context, args ...interface{})
- func CtxPanicf(ctx context.Context, fmt string, args ...interface{})
- func CtxPanicw(ctx context.Context, msg string, kvs ...interface{})
- func CtxWarn(ctx context.Context, args ...interface{})
- func CtxWarnf(ctx context.Context, fmt string, args ...interface{})
- func CtxWarnw(ctx context.Context, msg string, kvs ...interface{})
- func Debug(args ...interface{})
- func Debugf(fmt string, args ...interface{})
- func Debugw(msg string, kvs ...interface{})
- func Error(args ...interface{})
- func Errorf(fmt string, args ...interface{})
- func Errorw(msg string, kvs ...interface{})
- func Info(args ...interface{})
- func Infof(fmt string, args ...interface{})
- func Infow(msg string, kvs ...interface{})
- func Init(lvl Level, path string)
- func Panic(args ...interface{})
- func Panicf(fmt string, args ...interface{})
- func Panicw(msg string, kvs ...interface{})
- func SetLevel(lvl Level)
- func SetLogger(newLogger Logger)
- func SetWriter(w types.AsyncWriter)
- func StandardizePath(filePath, serviceName string) string
- func Stop()
- func Warn(args ...interface{})
- func Warnf(fmt string, args ...interface{})
- func Warnw(msg string, kvs ...interface{})
- func WithValue(ctx context.Context, k, v string) context.Context
- type AsyncFileWriter
- type AsyncWriter
- type HourTicker
- type Level
- type Logger
Constants ¶
const ( // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel = types.DebugLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel = types.InfoLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel = types.WarnLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel = types.ErrorLevel // PanicLevel level. Logs and then calls panic with the message passed to Debug, Info, ... PanicLevel = types.PanicLevel )
const ( CtxKeyBucketName = "bucket_name" CtxKeyObjectName = "object_name" CtxKeyObjectID = "object_id" CtxKeyTask = "task_key" )
Variables ¶
This section is empty.
Functions ¶
func CtxDebug ¶
CtxDebug uses fmt.Sprint to construct and log a message. The metaInfo in Context will be appended to message as fields.
func CtxDebugf ¶
CtxDebugf uses fmt.Sprintf to log a templated message. The metaInfo in Context will be appended to message as fields.
func CtxDebugw ¶
CtxDebugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With. The metaInfo in Context will be appended to message as fields.
When debug-level logging is disabled, this is much faster than
s.With(keysAndValues).CtxDebug(msg)
func CtxError ¶
CtxError uses fmt.Sprint to construct and log a message. The metaInfo in Context will be appended to message as fields.
func CtxErrorf ¶
CtxErrorf uses fmt.Sprintf to log a templated message. The metaInfo in Context will be appended to message as fields.
func CtxErrorw ¶
CtxErrorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With. The metaInfo in Context will be appended to message as fields.
func CtxInfo ¶
CtxInfo uses fmt.Sprint to construct and log a message. The metaInfo in Context will be appended to message as fields.
func CtxInfof ¶
CtxInfof uses fmt.Sprintf to log a templated message. The metaInfo in Context will be appended to message as fields.
func CtxInfow ¶
CtxInfow logs a message with some additional context. The variadic key-value pairs are treated as they are in With. The metaInfo in Context will be appended to message as fields.
func CtxPanic ¶
CtxPanic uses fmt.Sprint to construct and log a message, then panics. The metaInfo in Context will be appended to message as fields.
func CtxPanicf ¶
CtxPanicf uses fmt.Sprintf to log a templated message, then panics. The metaInfo in Context will be appended to message as fields.
func CtxPanicw ¶
CtxPanicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With. The metaInfo in Context will be appended to message as fields.
func CtxWarn ¶
CtxWarn uses fmt.Sprint to construct and log a message. The metaInfo in Context will be appended to message as fields.
func CtxWarnf ¶
CtxWarnf uses fmt.Sprintf to log a templated message. The metaInfo in Context will be appended to message as fields.
func CtxWarnw ¶
CtxWarnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With. The metaInfo in Context will be appended to message as fields.
func Debugf ¶
func Debugf(fmt string, args ...interface{})
Debugf uses fmt.Sprintf to log a templated message.
func Debugw ¶
func Debugw(msg string, kvs ...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(fmt string, args ...interface{})
Errorf uses fmt.Sprintf to log a templated message.
func Errorw ¶
func Errorw(msg string, kvs ...interface{})
Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func Infof ¶
func Infof(fmt string, args ...interface{})
Infof uses fmt.Sprintf to log a templated message.
func Infow ¶
func Infow(msg string, kvs ...interface{})
Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.
func Panic ¶
func Panic(args ...interface{})
Panic uses fmt.Sprint to construct and log a message, then panics.
func Panicf ¶
func Panicf(fmt string, args ...interface{})
Panicf uses fmt.Sprintf to log a templated message, then panics.
func Panicw ¶
func Panicw(msg string, kvs ...interface{})
Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.
func StandardizePath ¶
StandardizePath is meant to decorate given file path by nodeIP/localIP/serviceName so that the returned path is consistent and unified throughout all services under node-real org The path after decoration will be `<file_path>/<node_ip>/<local_ip>/<service_name>.log`
func Stop ¶
func Stop()
Stop flushes any buffered log entries, then stops writer. This method should be called when program stopping. For example,
func main() { defer log.Stop() log.Init(lvl, path) }
func Warnf ¶
func Warnf(fmt string, args ...interface{})
Warnf uses fmt.Sprintf to log a templated message.
Types ¶
type AsyncFileWriter ¶
type AsyncFileWriter struct {
// contains filtered or unexported fields
}
func NewAsyncFileWriter ¶
func NewAsyncFileWriter(filePath string, bufSize int64) *AsyncFileWriter
func (*AsyncFileWriter) Start ¶
func (w *AsyncFileWriter) Start() error
func (*AsyncFileWriter) Stop ¶
func (w *AsyncFileWriter) Stop() error
func (*AsyncFileWriter) Sync ¶
func (w *AsyncFileWriter) Sync() error
func (*AsyncFileWriter) SyncWrite ¶
func (w *AsyncFileWriter) SyncWrite(msg []byte)
type AsyncWriter ¶
type AsyncWriter types.AsyncWriter
AsyncWriter uses as log writer
func AddSync ¶
func AddSync(w io.Writer) AsyncWriter
func NewMultiWriteSyncer ¶
func NewMultiWriteSyncer(ws ...AsyncWriter) AsyncWriter
NewMultiWriteSyncer creates a WriteSyncer that duplicates its writes and sync calls, much like io.MultiWriter.
type HourTicker ¶
func NewHourTicker ¶
func NewHourTicker() *HourTicker
func (*HourTicker) Stop ¶
func (ht *HourTicker) Stop()
func (*HourTicker) Ticker ¶
func (ht *HourTicker) Ticker() <-chan time.Time
type Logger ¶
func With ¶
func With(kvs ...interface{}) Logger
With adds a variadic number of fields to the logging context. It accepts 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. Note that the keys in key-value pairs should be strings. For example,
log.With( "hello", "world", "failure", errors.New("oh no"), "count", 42, "user", User{Name: "alice"}, "err", errors.New("error") )