Documentation ¶
Index ¶
- Constants
- Variables
- func BasicFormat(ts string, delta string, ns string, msg string) string
- func BuildNegativeMatches(pattern string, orString string) (string, []*regexp.Regexp)
- func BuildPattern(pattern string) (string, []*regexp.Regexp)
- func Disable()
- func Enable(pattern string)
- func RegExWildCard(pattern string) string
- func RegExWrap(pattern string) string
- func RegExWrapCompile(pattern string) *regexp.Regexp
- func SetCache(cacheMinStr string) error
- func SetFormatter(f Formatter)
- func SetFormatterString(s string)
- func SetWriter(w io.Writer)
- type Debugger
- func (dbg Debugger) ApplyRootFields(name string) Debugger
- func (dbg Debugger) Error(args ...interface{})
- func (dbg Debugger) Log(args ...interface{})
- func (dbg Debugger) Spawn(ns string) *Debugger
- func (dbg Debugger) Warn(args ...interface{})
- func (dbg Debugger) WithField(key string, value interface{}) *Debugger
- func (dbg Debugger) WithFields(fields Fields) *Debugger
- type Fields
- type Finalized
- type Formatter
- type IDebugger
- type JSONFormatter
- type TextFormatter
Examples ¶
Constants ¶
const ( FieldKeyMsg = "msg" FieldKeyNamespace = "namespace" FieldKeyTime = "time" FieldKeyDelta = "delta" FieldKeyError = "debug_error" )
Variables ¶
var ( HAS_COLORS = true HAS_TIME = true )
var SetHasColors = setBoolWithLock(func(isOn bool) {
HAS_COLORS = isOn
})
var SetHasTime = setBoolWithLock(func(isOn bool) {
HAS_TIME = isOn
})
Functions ¶
func BasicFormat ¶ added in v0.1.0
func BuildNegativeMatches ¶ added in v0.1.0
Find all negative namespaces and pull them out of the pattern.
But build a slice of negatives ¶
example: pattern="*,-somenamespace"
Returns: "*", ["somenamespace"]
func Enable ¶
func Enable(pattern string)
Enable the given debug `pattern`. Patterns take a glob-like form, for example if you wanted to enable everything, just use "*", or if you had a library named mongodb you could use "mongodb:connection", or "mongodb:*". Multiple matches can be made with a comma, for example "mongo*,redis*".
This function is thread-safe.
Example ¶
Enable("mongo:connection") Enable("mongo:*") Enable("foo,bar,baz") Enable("*")
Output:
func RegExWildCard ¶ added in v0.1.1
func RegExWrapCompile ¶ added in v0.1.1
func SetFormatter ¶ added in v0.1.0
func SetFormatter(f Formatter)
func SetFormatterString ¶ added in v0.2.0
func SetFormatterString(s string)
Types ¶
type Debugger ¶
type Debugger struct {
// contains filtered or unexported fields
}
func Debug ¶
Debug creates a debug function for `name` which you call with printf-style arguments in your application or library.
Example ¶
var debug = Debug("single") for { debug.Log("sending mail") debug.Log("send email to %s", "tobi@segment.io") debug.Log("send email to %s", "loki@segment.io") debug.Log("send email to %s", "jane@segment.io") time.Sleep(500 * time.Millisecond) }
Output:
func (Debugger) ApplyRootFields ¶ added in v0.4.0
func (Debugger) Error ¶ added in v0.1.1
func (dbg Debugger) Error(args ...interface{})
prepend error/warn name as it is easier to filter!
func (Debugger) WithField ¶ added in v0.1.0
NOT *Debugger receiver on purpose to be immutable to not deal with locks on fields
func (Debugger) WithFields ¶ added in v0.1.0
NOT *Debugger receiver on purpose to be immutable to not deal with locks on fields
type JSONFormatter ¶ added in v0.1.0
type JSONFormatter struct { // TimestampFormat sets the format used for marshaling timestamps. TimestampFormat string // HTMLEscape allows disabling html escaping in output HTMLEscape bool Indent int // CallerPrettyfier can be set by the user to modify the content // of the function and file keys in the json data when ReportCaller is // activated. If any of the returned value is the empty string the // corresponding key will be removed from json fields. CallerPrettyfier func(*runtime.Frame) (function string, file string) // PrettyPrint will indent all json logs PrettyPrint bool FlattenMsgFields bool }
JSONFormatter formats logs into parsable json
func (*JSONFormatter) Format ¶ added in v0.1.0
func (f *JSONFormatter) Format(dbg Debugger, _msg interface{}) string
func (*JSONFormatter) GetHasFieldsOnly ¶ added in v0.1.0
func (f *JSONFormatter) GetHasFieldsOnly() bool
type TextFormatter ¶ added in v0.1.0
type TextFormatter struct { HasColor bool ForceQuote bool QuoteEmptyFields bool DisableQuote bool HasFieldsOnly bool SortingFunc func(keys []string) }
func (*TextFormatter) Format ¶ added in v0.1.0
func (t *TextFormatter) Format(dbg Debugger, _msg interface{}) string
func (*TextFormatter) GetHasFieldsOnly ¶ added in v0.1.0
func (t *TextFormatter) GetHasFieldsOnly() bool