fastlog

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LevelError = LogLevel(0)
	LevelInfo  = LogLevel(1)
	LevelDebug = LogLevel(2)
)

Variables

View Source
var DefaultIOWriter io.Writer = os.Stderr

DefaultIOWriter keep package io writer to msg output

Functions

This section is empty.

Types

type FastLog added in v0.2.0

type FastLog interface {
	FastLog(*Line) *Line
}

FastLog is an interface to extensible struct logging.

type Line

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

Line contains the internal buffer to be written to the input socket.

func (*Line) Bool added in v0.1.3

func (l *Line) Bool(name string, value bool) *Line

Bool appends a boolean field to the line

func (*Line) ByteArray

func (l *Line) ByteArray(name string, value []byte) *Line

ByteArray log a []byte in hexadecimal

func (*Line) Bytes added in v0.2.0

func (l *Line) Bytes(name string, value []byte) *Line

Bytes append an unmodified byte string to line.

func (*Line) Duration added in v0.2.0

func (l *Line) Duration(name string, duration time.Duration) *Line

Duration appends a duration field to the line

func (*Line) Error added in v0.1.3

func (l *Line) Error(value error) *Line

Error appends an error field to the line

func (*Line) IP

func (l *Line) IP(name string, value netip.Addr) *Line

IP appends a netip.Addr field to the line

func (*Line) IPArray added in v0.3.0

func (l *Line) IPArray(name string, value []net.IP) *Line

IPArray appends a array of IPs to the line

func (*Line) IPSlice added in v0.3.0

func (l *Line) IPSlice(name string, value net.IP) *Line

IPSlice appends a net.IP field to the line

func (*Line) Int

func (l *Line) Int(name string, value int) *Line

Int appends a int to the line

func (*Line) LF

func (l *Line) LF() *Line

LF append a line feed to line

func (*Line) Label added in v0.2.0

func (l *Line) Label(name string) *Line

Label appends a static string to the line

func (*Line) MAC

func (l *Line) MAC(name string, value net.HardwareAddr) *Line

MAC appends a mac address to the line

func (*Line) Module

func (l *Line) Module(name string, msg string) *Line

Module creates a new line with a different module name

func (*Line) Sprintf added in v0.2.0

func (l *Line) Sprintf(name string, value interface{}) *Line

Sprintf appends the result of the sprintf function to the line

func (*Line) String

func (l *Line) String(name string, value string) *Line

String appends the string to the line

func (*Line) StringArray added in v0.2.0

func (l *Line) StringArray(name string, value []string) *Line

StringArray appends an array of strings to the line

func (*Line) Stringer added in v0.2.0

func (l *Line) Stringer(value fmt.Stringer) *Line

Stringer appends a string to the line. This requires introspection and should seldome be used. It is a convenient function to log unknown data types that implemt the Stringer interface.

func (*Line) Struct

func (l *Line) Struct(value FastLog) *Line

Struct appends a struct to the line. the struct must implement the FasLog interface

func (*Line) Time added in v0.2.0

func (l *Line) Time(name string, t time.Time) *Line

Time appends a time field to the line

func (*Line) ToString added in v0.2.0

func (l *Line) ToString() string

ToString converts the line to string and return the line to the pool. The line buffer is no longer available after calling this function.

func (*Line) Uint16 added in v0.2.0

func (l *Line) Uint16(name string, value uint16) *Line

Uint16 appends a uint16 field to the line

func (*Line) Uint16Hex

func (l *Line) Uint16Hex(name string, value uint16) *Line

Uint16Hex appends a uint16 in hexadecimal format

func (*Line) Uint32 added in v0.2.0

func (l *Line) Uint32(name string, value uint32) *Line

Uint32 appends a uint32 field to the line

func (*Line) Uint8

func (l *Line) Uint8(name string, value uint8) *Line

Uint8 appends a uint8 field to the line

func (*Line) Uint8Hex added in v0.2.2

func (l *Line) Uint8Hex(name string, value uint8) *Line

Uint8Hex appends a uint8 field in hexadecimal

func (*Line) Write

func (l *Line) Write() error

Write writes the line and return the line to the pool. The line buffer is no longer available after calling this function.

type LogLevel added in v0.3.0

type LogLevel uint32

LogLevel is type to hold the log level

func Str2LogLevel added in v0.3.0

func Str2LogLevel(level string) LogLevel

Str2LogLevel converts a string to a LogLevel. Valid strings are: error, info, debug If the string is invalid, the function returns LevelError

func (LogLevel) String added in v0.3.0

func (l LogLevel) String() string

type Logger

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

Logger is a handler to access logging functions. The typical way is to instantiate a Logger variable for the package and log messages via Msg(). Example:

   var Logger = New("package")

   func test() {
	    Logger.Msg("hello world").Write()
   }

func New added in v0.3.0

func New(module string) *Logger

New creates a new logger

func (*Logger) Disable added in v0.3.0

func (l *Logger) Disable()

func (*Logger) EnableDebug added in v0.3.0

func (l *Logger) EnableDebug()

func (*Logger) EnableInfo added in v0.3.0

func (l *Logger) EnableInfo()

func (*Logger) IsDebug added in v0.3.0

func (l *Logger) IsDebug() bool

func (*Logger) IsInfo added in v0.3.0

func (l *Logger) IsInfo() bool

func (*Logger) Level added in v0.3.0

func (l *Logger) Level() LogLevel

func (*Logger) Msg added in v0.3.0

func (logger *Logger) Msg(msg string) *Line

Msg allocates a new line and appends msg to it.

Msg() allocates an underlying buffer from the buffer pool and appends the msg to it. Msg() does not write the buffer. The caller must call Write() or ToString() to write the line and free the underlying buffer to the buffer pool. for example:

  l := New("mypackage").Msg("Hello world").Int("mynumber", 1)
  l.Write()
or
  l.ToString()

func (*Logger) SetLevel added in v0.3.0

func (l *Logger) SetLevel(level LogLevel)

Jump to

Keyboard shortcuts

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