Documentation ¶
Index ¶
- Constants
- func DPanicError(err error)
- func Debug(v ...interface{})
- func Debugc(ctx context.Context, msg string, v ...interface{})
- func Debugf(msg string, v ...interface{})
- func Derive(src, dest context.Context) context.Context
- func EnableDebug()
- func Error(v ...interface{})
- func Errorc(ctx context.Context, msg string, v ...interface{})
- func Errorf(msg string, v ...interface{})
- func Fatal(v ...interface{})
- func Fatalc(ctx context.Context, msg string, v ...interface{})
- func Fatalf(msg string, v ...interface{})
- func ForkLog(tailBytes int) io.ReadCloser
- func GetFuncName(i interface{}) string
- func Info(v ...interface{})
- func Infoc(ctx context.Context, msg string, v ...interface{})
- func Infof(msg string, v ...interface{})
- func InterceptLogs(w io.Writer) io.Writer
- func IsDebugging() bool
- func Jsonify(v interface{}) string
- func JsonifyNested(v interface{}) string
- func PanicError(err error, msg ...interface{})
- func PrintJSON(v interface{})
- func PrintJSONc(ctx context.Context, v interface{})
- func SetEncoding(t EncodingType)
- func StreamClientInterceptor(from string) ...
- func StreamServerInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func TimeDebugc(ctx context.Context, msg string, v ...interface{}) func()
- func TimeFunc(v ...interface{}) func()
- func TimeFuncDebug(v ...interface{}) func()
- func TimeFuncDuration() func() time.Duration
- func TimeInfoc(ctx context.Context, msg string, v ...interface{}) func()
- func TimeInfocSlow(ctx context.Context, slowDuration time.Duration, msg string, v ...interface{}) func()
- func UnaryClientInterceptor(from string) func(ctx context.Context, method string, req, reply interface{}, ...) error
- func UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- func Warn(v ...interface{})
- func Warnc(ctx context.Context, msg string, v ...interface{})
- func Warnf(msg string, v ...interface{})
- func With(ctx context.Context, msg string, v ...interface{}) context.Context
- func WithKV(ctx context.Context, key string, val interface{}) context.Context
- func WithLogger(ctx context.Context, w io.Writer) context.Context
- type EncodingType
- type LogContext
- func (lc *LogContext) Empty() bool
- func (lc *LogContext) From() string
- func (lc *LogContext) JSON() string
- func (lc *LogContext) Logfmt(enableColor bool) string
- func (lc *LogContext) Map() map[string]string
- func (lc *LogContext) Message() string
- func (lc *LogContext) Since() time.Time
- func (lc *LogContext) String() string
- func (lc *LogContext) UUID() int64
- type Span
- type StripColorReader
- type StripColorWriter
- type StripPrefixReader
- type Terminal
- type Timer
Constants ¶
const SlowPrefix = "!SLOW! "
Variables ¶
This section is empty.
Functions ¶
func DPanicError ¶
func DPanicError(err error)
DPanicError provide a quick way to check unexpected errors that should never happen. It's almost the same as Check(), except only in debug mode will throw panic.
func Debug ¶
func Debug(v ...interface{})
Debug prints info to standard output with [DEBUG] prefix in debug mode.
func Fatal ¶
func Fatal(v ...interface{})
Fatal prints error to error output with [FATAL] prefix, and terminate the application.
func ForkLog ¶
func ForkLog(tailBytes int) io.ReadCloser
func GetFuncName ¶
func GetFuncName(i interface{}) string
GetFuncName provides shortcut to print the name of any function.
func Jsonify ¶
func Jsonify(v interface{}) string
Jsonify provides shortcut to return an json format string of any varible.
func JsonifyNested ¶
func JsonifyNested(v interface{}) string
func PanicError ¶
func PanicError(err error, msg ...interface{})
PanicError provide a quick way to check unexpected errors that should never happen. It's basically an assertion that once err != nil, fatal panic is thrown.
func PrintJSON ¶
func PrintJSON(v interface{})
PrintJSON outputs any varible in JSON format to console. Useful for debuging.
func PrintJSONc ¶
PrintJSONc outputs any varible in JSON format to console, and logger within context. Useful for debuging.
func StreamClientInterceptor ¶
func StreamClientInterceptor(from string) func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error)
StreamClientInterceptor injects log context into outgoing grpc request.
func StreamServerInterceptor ¶
func StreamServerInterceptor(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
StreamServerInterceptor retrieve log context from incoming grpc request.
func TimeDebugc ¶
func TimeFunc ¶
func TimeFunc(v ...interface{}) func()
TimeFunc prints the info with timing consumed by function. It has specified usage like:
defer TimeFunc("Hello world")()
func TimeFuncDebug ¶
func TimeFuncDebug(v ...interface{}) func()
func TimeFuncDuration ¶
TimeFuncDuration returns the duration consumed by function. It has specified usage like:
f := TimeFuncDuration() DoSomething() duration := f()
func TimeInfocSlow ¶
func TimeInfocSlow(ctx context.Context, slowDuration time.Duration, msg string, v ...interface{}) func()
TimeInfocSlow prints the info with timing consumed by function. If the cost is larger than slowDuration, it will be printed with !SLOW! prefix before msg.
func UnaryClientInterceptor ¶
func UnaryClientInterceptor(from string) func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
UnaryClientInterceptor injects log context into outgoing grpc request.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
UnaryServerInterceptor retrieve log context from incoming grpc request.
Types ¶
type EncodingType ¶
type EncodingType string
EncodingType represent the type to use for log encoding.
const ( // TypeJSON encodes log into one-line json. TypeJSON EncodingType = "json" // TypeLogfmt encodes log into logfmt(structlog) format. TypeLogfmt EncodingType = "logfmt" )
type LogContext ¶
type LogContext struct {
// contains filtered or unexported fields
}
LogContext indicates all the contextual logs in a request.
func FromContext ¶
func FromContext(ctx context.Context) *LogContext
FromContext returns a the potential LogContext object from Context if any.
func (*LogContext) Empty ¶
func (lc *LogContext) Empty() bool
Empty returns true if the log context contains nothing.
func (*LogContext) From ¶
func (lc *LogContext) From() string
func (*LogContext) Logfmt ¶
func (lc *LogContext) Logfmt(enableColor bool) string
Logfmt returns the log in LOGFMT format.
func (*LogContext) Map ¶
func (lc *LogContext) Map() map[string]string
func (*LogContext) Message ¶
func (lc *LogContext) Message() string
func (*LogContext) Since ¶
func (lc *LogContext) Since() time.Time
func (*LogContext) String ¶
func (lc *LogContext) String() string
String returns a string representing the log.
func (*LogContext) UUID ¶
func (lc *LogContext) UUID() int64
type StripColorReader ¶
type StripColorReader struct {
// contains filtered or unexported fields
}
func NewStripColorReader ¶
func NewStripColorReader(r io.Reader) *StripColorReader
type StripColorWriter ¶
type StripColorWriter struct {
// contains filtered or unexported fields
}
func NewStripColorWriter ¶
func NewStripColorWriter(w io.Writer) *StripColorWriter
type StripPrefixReader ¶
type StripPrefixReader struct {
// contains filtered or unexported fields
}
func NewStripPrefixReader ¶
func NewStripPrefixReader(r io.Reader, prefix []byte) *StripPrefixReader
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
func NewTerminal ¶
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer is a helper to time multiple tick. Simple usage like: ``` t := lg.NewTimer("Search similar", itemID) defer lg.Info(t) meta := getMeta(itemID) t.Tick("Get meta") results := querySimilar(itemID) t.Tick("Query") return formatResult(results) ```