Documentation
¶
Index ¶
- Constants
- Variables
- func AppendKVs(e *tlwire.Encoder, b []byte, kvs []interface{}) []byte
- func AppendLabels(e *tlwire.Encoder, b []byte, kvs []interface{}) []byte
- func Color(c ...int) (r []byte)
- func ContextWithSpan(ctx context.Context, s Span) context.Context
- func ExecutableMD5() string
- func ExecutableSHA1() string
- func Hostname() string
- func If(topics string) bool
- func IfDepth(d int, topics string) bool
- func LoggerSetCallers(l *Logger, skip int, callers func(skip int, pc []uintptr) int)
- func LoggerSetTimeNow(l *Logger, now func() time.Time, nano func() int64)
- func ParseLabels(s string) []interface{}
- func Printf(fmt string, args ...interface{})
- func Printw(msg string, kvs ...interface{})
- func RandIDFromReader(read func(p []byte) (int, error)) func() ID
- func SetLabels(kvs ...interface{})
- func SetVerbosity(vfilter string)
- func UUID(read func(p []byte) (int, error)) func() ID
- func User() string
- func Verbosity() string
- type ColorScheme
- type ConsoleWriter
- type EventKind
- type FormatNext
- type ID
- func (id ID) Format(s fmt.State, c rune)
- func (id ID) FormatTo(b []byte, i int, f rune) int
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) String() string
- func (id ID) StringFull() string
- func (id ID) StringUUID() string
- func (id ID) TlogAppend(b []byte) []byte
- func (id *ID) TlogParse(p []byte, i int) int
- func (id *ID) UnmarshalJSON(b []byte) error
- type LogLevel
- type Logger
- func (l *Logger) Copy(w io.Writer) *Logger
- func (l *Logger) Event(kvs ...interface{}) (err error)
- func (l *Logger) IOWriter(d int) io.Writer
- func (l *Logger) If(topics string) bool
- func (l *Logger) IfDepth(d int, topics string) bool
- func (l *Logger) Labels() RawMessage
- func (l *Logger) NewMessage(d int, id ID, msg interface{}, kvs ...interface{})
- func (l *Logger) NewSpan(d int, par ID, name string, kvs ...interface{}) Span
- func (l *Logger) OK() bool
- func (l *Logger) Or(l2 *Logger) *Logger
- func (l *Logger) Printf(fmt string, args ...interface{})
- func (l *Logger) Printw(msg string, kvs ...interface{})
- func (l *Logger) Root() Span
- func (l *Logger) SetLabels(kvs ...interface{})
- func (l *Logger) SetVerbosity(vfilter string)
- func (l *Logger) Start(name string, kvs ...interface{}) Span
- func (l *Logger) V(topics string) *Logger
- func (l *Logger) Verbosity() string
- func (l *Logger) Write(p []byte) (int, error)
- type Modify
- type RawMessage
- type ShortIDError
- type Span
- func Root() Span
- func SpanFromContext(ctx context.Context) (s Span)
- func SpawnFromContext(ctx context.Context, name string, kvs ...interface{}) Span
- func SpawnFromContextAndWrap(ctx context.Context, name string, kvs ...interface{}) (Span, context.Context)
- func SpawnFromContextOrStart(ctx context.Context, name string, kvs ...interface{}) Span
- func Start(name string, kvs ...interface{}) Span
- func (s Span) Copy(w io.Writer) Span
- func (s Span) Event(kvs ...interface{}) (err error)
- func (s Span) Finish(kvs ...interface{})
- func (s Span) IOWriter(d int) io.Writer
- func (s Span) If(topics string) bool
- func (s Span) IfDepth(d int, topics string) bool
- func (s Span) NewMessage(d int, msg interface{}, kvs ...interface{})
- func (s Span) OK() bool
- func (s Span) Or(s2 Span) Span
- func (s Span) Printf(fmt string, args ...interface{})
- func (s Span) Printw(msg string, kvs ...interface{})
- func (s Span) Spawn(name string, kvs ...interface{}) Span
- func (s Span) V(topics string) Span
- type Timestamp
Constants ¶
const ( Ldate = 1 << iota Ltime Lseconds Lmilliseconds Lmicroseconds Lshortfile Llongfile Ltypefunc // pkg.(*Type).Func Lfuncname // Func LUTC Lloglevel // log level LstdFlags = Ldate | Ltime LdetFlags = Ldate | Ltime | Lmicroseconds | Lshortfile | Lloglevel Lnone = 0 )
const ( WireLabel = tlwire.SemanticTlogBase + iota WireID WireMessage WireEventKind WireLogLevel SemanticCommunityBase = tlwire.SemanticTlogBase + 10 )
Wire semantic tags.
const KeyAuto = ""
Variables ¶
var ( ResetColor = Color(0) DefaultColorScheme = ColorScheme{ TimeColor: Color(90), TimeChangeColor: Color(38, 5, 244, 1), FileColor: Color(90), FuncColor: Color(90), KeyColor: Color(36), LevelColor: struct { Info []byte Warn []byte Error []byte Fatal []byte Debug []byte }{ Info: Color(90), Warn: Color(31), Error: Color(31, 1), Fatal: Color(31, 1), Debug: Color(90), }, } )
var ( Stdout = os.Stdout Stderr = os.Stderr )
var ( KeySpan = "_s" KeyParent = "_p" KeyTimestamp = "_t" KeyElapsed = "_e" KeyCaller = "_c" KeyMessage = "_m" KeyEventKind = "_k" KeyLogLevel = "_l" KeyRepeated = "_r" )
Predefined keys.
var ( Hidden = RawMessage{tlwire.Special | tlwire.Hidden} None = RawMessage{tlwire.Special | tlwire.None} Nil = RawMessage{tlwire.Special | tlwire.Nil} Break = RawMessage{tlwire.Special | tlwire.Break} NextAsHex = Modify{tlwire.Semantic | tlwire.Hex} NextAsMessage = Modify{tlwire.Semantic | WireMessage} NextAsType = FormatNext("%T") )
var AutoLabels = map[string]func() interface{}{ "_hostname": func() interface{} { return Hostname() }, "_user": func() interface{} { return User() }, "_os": func() interface{} { return runtime.GOOS }, "_arch": func() interface{} { return runtime.GOARCH }, "_numcpu": func() interface{} { return runtime.NumCPU() }, "_gomaxprocs": func() interface{} { return runtime.GOMAXPROCS(0) }, "_goversion": func() interface{} { return runtime.Version }, "_pid": func() interface{} { return os.Getpid() }, "_timezone": func() interface{} { n, _ := time.Now().Zone() return n }, "_execmd5": func() interface{} { return ExecutableMD5() }, "_execsha1": func() interface{} { return ExecutableSHA1() }, "_execname": func() interface{} { return filepath.Base(os.Args[0]) }, "_randid": func() interface{} { return MathRandID().StringFull() }, }
AutoLabels is a list of automatically filled labels
_hostname - local hostname _user - current user _pid - process pid _timezone - local timezone code (UTC, MSK) _goversion - go version _execmd5 - this binary md5 hash _execsha1 - this binary sha1 hash _execname - executable base name (project name) _randid - random id. May be used to distinguish different runs.
var DefaultLogger = New(NewConsoleWriter(os.Stderr, LdetFlags))
Functions ¶
func ContextWithSpan ¶
ContextWithSpan creates new context with Span ID context.Value. It returns the same context if id is zero.
func ExecutableMD5 ¶
func ExecutableMD5() string
ExecutableMD5 returns current process executable md5 hash. May be useful to find exact executable later.
func ExecutableSHA1 ¶
func ExecutableSHA1() string
ExecutableSHA1 returns current process executable sha1 hash. May be useful to find exact executable later.
func LoggerSetCallers ¶
func ParseLabels ¶
func ParseLabels(s string) []interface{}
ParseLabels parses comma separated list of labels and fills them with values (See FillLabelsWithDefaults).
func SetVerbosity ¶
func SetVerbosity(vfilter string)
Types ¶
type ColorScheme ¶
type ConsoleWriter ¶
type ConsoleWriter struct { io.Writer Flags int Colorize bool PadEmptyMessage bool AllLabels bool AllCallers bool LevelWidth int MessageWidth int IDWidth int Shortfile int Funcname int MaxValPad int TimeFormat string TimeLocation *time.Location DurationFormat string DurationDiv time.Duration FloatFormat string FloatChar byte FloatPrecision int CallerFormat string BytesFormat string StringOnNewLineMinLen int PairSeparator string KVSeparator string QuoteChars string QuoteAnyValue bool QuoteEmptyValue bool ColorScheme // contains filtered or unexported fields }
func NewConsoleWriter ¶
func NewConsoleWriter(w io.Writer, f int) *ConsoleWriter
func (*ConsoleWriter) AppendDuration ¶
func (w *ConsoleWriter) AppendDuration(b []byte, d time.Duration) []byte
func (*ConsoleWriter) ConvertValue ¶
func (w *ConsoleWriter) ConvertValue(b, p []byte, st, ff int) (_ []byte, i int)
type EventKind ¶
type EventKind rune
const ( EventSpanStart EventKind = 's' EventSpanFinish EventKind = 'f' EventMetric EventKind = 'm' )
Event kinds.
func (EventKind) TlogAppend ¶
type FormatNext ¶
type FormatNext string
type ID ¶
type ID [16]byte
func IDFromBytes ¶
IDFromBytes decodes ID from bytes slice.
If byte slice is shorter than type length result is returned as is and ShortIDError as error value. You may use result if you expected short ID prefix.
func IDFromString ¶
IDFromString parses ID from string.
If parsed string is shorter than type length result is returned as is and ShortIDError as error value. You may use result if you expected short ID prefix (profuced by ID.String, for example).
func IDFromStringAsBytes ¶
IDFromStringAsBytes is the same as IDFromString. It avoids alloc in IDFromString(string(b)).
func MathRandID ¶
func MathRandID() (id ID)
func (ID) Format ¶
Format is fmt.Formatter interface implementation. It supports width. '+' flag sets width to full ID length.
func (ID) MarshalJSON ¶
func (ID) String ¶
String returns short string representation.
It's not supposed to be able to recover it back to the same value as it was.
func (ID) StringFull ¶
StringFull returns full id represented as string.
func (ID) StringUUID ¶ added in v0.23.1
func (ID) TlogAppend ¶
func (*ID) UnmarshalJSON ¶
type Logger ¶
type Logger struct { io.Writer // protected by Mutex below tlwire.Encoder NewID func() ID `deep:"compare=pointer"` // must be threadsafe sync.Mutex // contains filtered or unexported fields }
func (*Logger) Labels ¶
func (l *Logger) Labels() RawMessage
func (*Logger) NewMessage ¶
func (*Logger) SetVerbosity ¶
type RawMessage ¶
type RawMessage []byte
func RawTag ¶
func RawTag(tag byte, sub int) RawMessage
func Special ¶
func Special(value int) RawMessage
func (RawMessage) TlogAppend ¶
func (r RawMessage) TlogAppend(b []byte) []byte
type ShortIDError ¶
type ShortIDError struct {
Bytes int // Bytes successfully parsed
}
ShortIDError is an ID parsing error.
func (ShortIDError) Error ¶
func (e ShortIDError) Error() string
Error is an error interface implementation.
type Span ¶
func SpanFromContext ¶
SpanFromContext loads saved by ContextWithSpan Span from Context. It returns valid empty (no-op) Span if none was found.
func SpawnFromContext ¶
SpawnFromContext spawns new Span derived form Span or ID from Context. It returns empty (no-op) Span if no ID found.