log

package
v0.0.0-...-782863c Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package log provides support for structured logging.

Index

Constants

View Source
const (
	TypeBool fieldType = iota + 1
	TypeBools
	TypeBytes
	TypeBytesArray
	TypeDigest
	TypeDigests
	TypeDuration
	TypeDurations
	TypeErr
	TypeErrs
	TypeFloat32
	TypeFloat32s
	TypeFloat64
	TypeFloat64s
	TypeInt
	TypeInts
	TypeInt8
	TypeInt8s
	TypeInt16
	TypeInt16s
	TypeInt32
	TypeInt32s
	TypeInt64
	TypeInt64s
	TypeString
	TypeStrings
	TypeTime
	TypeTimes
	TypeUint
	TypeUints
	TypeUint8
	TypeUint8s
	TypeUint16
	TypeUint16s
	TypeUint32
	TypeUint32s
	TypeUint64
	TypeUint64s
)

Log field types.

Variables

This section is empty.

Functions

func AtDebug

func AtDebug() bool

AtDebug returns whether the current configuration will log at the DebugLevel.

func AtError

func AtError() bool

AtError returns whether the current configuration will log at the ErrorLevel.

func AtInfo

func AtInfo() bool

AtInfo returns whether the current configuration will log at the InfoLevel.

func AtStackTrace

func AtStackTrace() bool

AtStackTrace returns whether the current configuration will log at the StackTraceLevel.

func AtWarn

func AtWarn() bool

AtWarn returns whether the current configuration will log at the WarnLevel.

func Debug

func Debug(text string, fields ...Field)

Debug logs the given text and fields at DebugLevel using the root logger.

func Debugf

func Debugf(format string, args ...interface{})

Debugf formats similarly to Printf and logs the resulting output at the DebugLevel using the root logger.

func Error

func Error(text string, fields ...Field)

Error logs the given text and fields at ErrorLevel using the root logger.

func Errorf

func Errorf(format string, args ...interface{})

Errorf formats similarly to Printf and logs the resulting output at the ErrorLevel using the root logger.

func Fatal

func Fatal(text string, fields ...Field)

Fatal logs the given text and fields at FatalLevel using the root logger.

func Fatalf

func Fatalf(format string, args ...interface{})

Fatalf formats similarly to Printf and logs the resulting output at the FatalLevel using the root logger.

func Info

func Info(text string, fields ...Field)

Info logs the given text and fields at InfoLevel using the root logger.

func Infof

func Infof(format string, args ...interface{})

Infof formats similarly to Printf and logs the resulting output at the InfoLevel using the root logger.

func SetGlobal

func SetGlobal(fields ...Field)

SetGlobal sets the given fields on the root logger. SetGlobal is not threadsafe, so should be set before any goroutines that make log calls.

func StackTrace

func StackTrace(text string)

StackTrace logs the given text at StackTraceLevel along with the stacktrace using the root logger.

func ToConsole

func ToConsole(lvl Level)

ToConsole sets the log level of the console logger. By default it will be logging at DebugLevel until this function is used to change the setting.

func ToFile

func ToFile(path string, lvl Level) error

ToFile starts logging at the given file path.

func ToServer

func ToServer(addr string, lvl Level, limit int)

ToServer starts logging to the given server. It starts dropping backfilled entries beyond the given limit.

func Warn

func Warn(text string, fields ...Field)

Warn logs the given text and fields at WarnLevel using the root logger.

func Warnf

func Warnf(format string, args ...interface{})

Warnf formats similarly to Printf and logs the resulting output at the WarnLevel using the root logger.

Types

type Field

type Field struct {
	// contains filtered or unexported fields
}

Field represents a key/value pair for adding to a log entry.

func Bool

func Bool(key string, value bool) Field

Bool represents a field with a boolean value.

func Bools

func Bools(key string, value []bool) Field

Bools represents a field with a slice of boolean values.

func Bytes

func Bytes(key string, value []byte) Field

Bytes represents a field with a byte slice value.

func BytesArray

func BytesArray(key string, value [][]byte) Field

BytesArray represents a field with an array of byte slice values.

func Digest

func Digest(key string, value []byte) Field

Digest represents a field with a hash digest value.

func Digests

func Digests(key string, value [][]byte) Field

Digests represents a field with an array of hash digest values.

func Duration

func Duration(key string, value time.Duration) Field

Duration represents a field with a duration value.

func Durations

func Durations(key string, value []time.Duration) Field

Durations represents a field with an array of duration values.

func Err

func Err(value error) Field

Err represents a field with an error value. It automatically uses "error" as the Field key.

func Errs

func Errs(value error) Field

Errs represents a field with an array of error values. It automatically uses "error" as the Field key.

func Float32

func Float32(key string, value float32) Field

Float32 represents a field with a float32 value.

func Float32s

func Float32s(key string, value []float32) Field

Float32s represents a field with an array of float32 values.

func Float64

func Float64(key string, value float64) Field

Float64 represents a field with a float64 value.

func Float64s

func Float64s(key string, value []float64) Field

Float64s represents a field with an array of float64 values.

func Int

func Int(key string, value int) Field

Int represents a field with an int value.

func Int16

func Int16(key string, value int16) Field

Int16 represents a field with an int16 value.

func Int16s

func Int16s(key string, value []int16) Field

Int16s represents a field with an array of int16 values.

func Int32

func Int32(key string, value int32) Field

Int32 represents a field with an int32 value.

func Int32s

func Int32s(key string, value []int32) Field

Int32s represents a field with an array of int32 values.

func Int64

func Int64(key string, value int64) Field

Int64 represents a field with an int64 value.

func Int64s

func Int64s(key string, value []int64) Field

Int64s represents a field with an array of int64 values.

func Int8

func Int8(key string, value int8) Field

Int8 represents a field with an int8 value.

func Int8s

func Int8s(key string, value []int8) Field

Int8s represents a field with an array of int8 values.

func Ints

func Ints(key string, value []int) Field

Ints represents a field with an array of int values.

func String

func String(key string, value string) Field

String represents a field with a string value.

func Strings

func Strings(key string, value []string) Field

Strings represents a field with an array of string values.

func Time

func Time(key string, value time.Time) Field

Time represents a field with a time value.

func Times

func Times(key string, value []time.Time) Field

Times represents a field with an array of time values.

func Uint

func Uint(key string, value uint) Field

Uint represents a field with a uint value.

func Uint16

func Uint16(key string, value uint16) Field

Uint16 represents a field with a uint16 value.

func Uint16s

func Uint16s(key string, value []uint16) Field

Uint16s represents a field with an array of uint16 values.

func Uint32

func Uint32(key string, value uint32) Field

Uint32 represents a field with a uint32 value.

func Uint32s

func Uint32s(key string, value []uint32) Field

Uint32s represents a field with an array of uint32 values.

func Uint64

func Uint64(key string, value uint64) Field

Uint64 represents a field with a uint64 value.

func Uint64s

func Uint64s(key string, value []uint64) Field

Uint64s represents a field with an array of uint64 values.

func Uint8

func Uint8(key string, value uint8) Field

Uint8 represents a field with a uint8 value.

func Uint8s

func Uint8s(key string, value []uint8) Field

Uint8s represents a field with an array of uint8 values.

func Uints

func Uints(key string, value []uint) Field

Uints represents a field with an array of uint values.

type Level

type Level int8

Level represents a logging level.

const (
	DebugLevel Level = iota + 1
	InfoLevel
	WarnLevel
	ErrorLevel
	StackTraceLevel
	FatalLevel
)

Logging levels.

func (Level) MarshalYAML

func (l Level) MarshalYAML() (interface{}, error)

MarshalYAML implements the YAML encoding interface.

func (Level) String

func (l Level) String() string

func (*Level) UnmarshalYAML

func (l *Level) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the YAML decoding interface.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger encapsulates the state of a logger with custom fields.

func With

func With(fields ...Field) *Logger

With returns a new logger based off of the root logger that comes preset with the given fields.

func (*Logger) Debug

func (l *Logger) Debug(text string, fields ...Field)

Debug logs the given text and fields at DebugLevel.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf formats similarly to Printf and logs the resulting output at the DebugLevel.

func (*Logger) Error

func (l *Logger) Error(text string, fields ...Field)

Error logs the given text and fields at ErrorLevel.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf formats similarly to Printf and logs the resulting output at the ErrorLevel.

func (*Logger) Fatal

func (l *Logger) Fatal(text string, fields ...Field)

Fatal logs the given text and fields at FatalLevel.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

Fatalf formats similarly to Printf and logs the resulting output at the FatalLevel.

func (*Logger) Info

func (l *Logger) Info(text string, fields ...Field)

Info logs the given text and fields at InfoLevel.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof formats similarly to Printf and logs the resulting output at the InfoLevel.

func (*Logger) StackTrace

func (l *Logger) StackTrace(text string)

StackTrace logs the given text at StackTraceLevel along with the stacktrace.

func (*Logger) Warn

func (l *Logger) Warn(text string, fields ...Field)

Warn logs the given text and fields at WarnLevel.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

Warnf formats similarly to Printf and logs the resulting output at the WarnLevel.

func (*Logger) With

func (l *Logger) With(fields ...Field) *Logger

With returns a new logger that comes preset with the given fields.

type Server

type Server struct {
	DB *badger.DB
}

Server represents a TCP log server.

func (*Server) Run

func (s *Server) Run(addr string) error

Run instantiates the TCP log server.

Directories

Path Synopsis
Package fld provides field constructors with preset key names.
Package fld provides field constructors with preset key names.

Jump to

Keyboard shortcuts

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