log

package
v0.0.0-...-d6c8373 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultLogger = NewLogger()

DefaultLogger initializes default logger

Functions

func SetLevel

func SetLevel(l Level)

SetLevel sets the logging verbose level

Types

type Composer

type Composer interface {
	Write(string)
	Bold(string) string
	Underline(string) string
	Blink(string) string
	Grey(string) string
	Red(string) string
	Green(string) string
	Yellow(string) string
	Blue(string) string
	LightGrey(string) string
	String() string
}

Composer encapsulates a text writer

func NewWriter

func NewWriter() Composer

NewWriter returns a new text writer

type Field

type Field struct {
	Key     string    `json:"key"`
	Type    FieldType `json:"type,omitempty"`
	Binary  []byte    `json:"binary,omitempty"`
	Integer int64     `json:"integer,omitempty"`
	Float   float64   `json:"float,omitempty"`
	String  string    `json:"string,omitempty"`
	Bool    bool      `json:"bool,omitempty"`
}

Field encapsulates logging fields

func Binary

func Binary(k string, b []byte) Field

Binary returns a field that contains bytes data

func Bool

func Bool(k string, b bool) Field

Bool returns a field that contains string data

func Float32

func Float32(k string, f float32) Field

Float32 returns a field that contains float data

func Float64

func Float64(k string, f float64) Field

Float64 returns a field that contains float data

func Int

func Int(k string, i int) Field

Int returns a field that contains integer data

func Int16

func Int16(k string, i int16) Field

Int16 returns a field that contains integer data

func Int32

func Int32(k string, i int32) Field

Int32 returns a field that contains integer data

func Int64

func Int64(k string, i int64) Field

Int64 returns a field that contains integer data

func Int8

func Int8(k string, i int8) Field

Int8 returns a field that contains integer data

func String

func String(k string, s string) Field

String returns a field that contains string data

func Tag

func Tag(s string) Field

Tag returns a field that contains string data

func Uint

func Uint(k string, i uint) Field

Uint returns a field that contains integer data

func Uint16

func Uint16(k string, i uint16) Field

Uint16 returns a field that contains integer data

func Uint32

func Uint32(k string, i uint32) Field

Uint32 returns a field that contains integer data

func Uint64

func Uint64(k string, i uint64) Field

Uint64 returns a field that contains integer data

func Uint8

func Uint8(k string, i uint8) Field

Uint8 returns a field that contains integer data

func (Field) Value

func (f Field) Value() string

Value returns field data in string format

type FieldType

type FieldType uint8

FieldType defines the type of field

const (
	UnknownFieldType FieldType = iota
	BinaryType
	IntegerType
	FloatType
	StringType
	BoolType
)

Defines the types of fields

type Level

type Level int

Level defines the importance and urgency of the log message

const (
	LogFatal Level = iota
	LogError
	LogWarn
	LogInfo
	LogDebug
	LogTrace
)

Defines the importance level of logs

func LevelFromString

func LevelFromString(s string) Level

LevelFromString returns the log level enum from a string

func (Level) Head

func (l Level) Head() string

Head pads log level reference to 5 characters, this would left-justifies the strings and add spaces to fill the empty columns on the right.

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	ID() string
	NL()
	Trace(string, ...Field)
	Debug(string, ...Field)
	Info(string, ...Field)
	Warn(string, ...Field)
	Error(string, ...Field)
	Fatal(string, ...Field)
}

Logger implements a simple logging interface

func NewLogger

func NewLogger() Logger

NewLogger initializes and returns a new logger

type Record

type Record struct {
	Time   time.Time  `json:"time"`
	Level  Level      `json:"level"`
	Msg    string     `json:"message"`
	Fields []Field    `json:"fields"`
	Call   stack.Call `json:"call"`
}

Record encapsulates a log event

func (*Record) String

func (r *Record) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL