config

package
v0.0.0-...-4c7e257 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//Black is a constant of type int
	Black = iota + 30
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)
View Source
const StackTraceBufferSize = 1024 * 100

StackTraceBufferSize is a constant which defines stack track buffer size

Variables

View Source
var (
	//InfoByte is a variable of type []byte
	DebugByteColor = []byte(fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", Blue, "DEBUG"))
	WarnByteColor  = []byte(fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", Yellow, "WARN"))
	ErrorByteColor = []byte(fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", Red, "ERROR"))
	FatalByteColor = []byte(fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", Magenta, "FATAL"))
)

Functions

func FormatLogLevel

func FormatLogLevel(x LogLevel) string

FormatLogLevel is a function which returns string format of log level

Types

type Data

type Data map[string]interface{}

Data is a map

type LogFormat

type LogFormat struct {
	LogLevel  LogLevel `json:"level"`
	Timestamp string   `json:"timestamp"`
	File      string   `json:"file"`
	Message   string   `json:"msg"`
	Data      Data     `json:"data,omitempty"`
	Service   any      `json:"service,omitempty"`
}

LogFormat is a struct which stores details about log

func (LogFormat) ToJSON

func (log LogFormat) ToJSON() ([]byte, error)

ToJSON which converts data of log file in to JSON file

type LogLevel

type LogLevel int

LogLevel is a user defined variable of type int

const (
	//DEBUG is a constant of user defined type LogLevel
	DEBUG LogLevel = iota
	INFO
	WARN
	ERROR
	FATAL
)

func (LogLevel) MarshalJSON

func (x LogLevel) MarshalJSON() ([]byte, error)

MarshalJSON is a function which returns data in JSON format

type Logger

type Logger interface {
	RegisterSink(Sink)
	Session(task string, data ...Data) Logger
	SessionName() string
	Debug(action string, data ...Data)
	Info(action string, data ...Data)
	Warn(action string, data ...Data)
	Error(action string, err error, data ...Data)
	Fatal(action string, err error, data ...Data)
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Errorf(err error, format string, args ...interface{})
	Fatalf(err error, format string, args ...interface{})
	WithData(Data) Logger
}

Logger is a interface

func NewLogger

func NewLogger(component string) Logger

NewLogger is a function used to get new logger object

func NewLoggerExt

func NewLoggerExt(component string, isFormatText bool) Logger

NewLoggerExt is a function which returns logger struct object

type ReconfigurableSink

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

ReconfigurableSink is a struct

func NewReconfigurableSink

func NewReconfigurableSink(sink Sink, initialMinLogLevel LogLevel) *ReconfigurableSink

NewReconfigurableSink is a function which returns struct object

func (*ReconfigurableSink) GetMinLevel

func (sink *ReconfigurableSink) GetMinLevel() LogLevel

GetMinLevel is a method which gets minimum log level

func (*ReconfigurableSink) Log

func (sink *ReconfigurableSink) Log(level LogLevel, log []byte)

Log is a method which returns log level and log

func (*ReconfigurableSink) SetMinLevel

func (sink *ReconfigurableSink) SetMinLevel(level LogLevel)

SetMinLevel is a function which sets minimum log level

type Sink

type Sink interface {
	//Log to the sink.  Best effort -- no need to worry about errors.
	Log(level LogLevel, payload []byte)
}

A Sink represents a write destination for a Logger. It provides a thread-safe interface for writing logs

func NewWriterSink

func NewWriterSink(name string, writer io.Writer, minLogLevel LogLevel) Sink

NewWriterSink is function which returns new struct object

Jump to

Keyboard shortcuts

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