fancylog

package module
v0.0.20 Latest Latest
Warning

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

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

README

fancylog provides stylized, non-blocking log output. It is used across many Golang projects here at NASK.

Documentation

Index

Constants

View Source
const DepthSkip = 3

Variables

View Source
var (

	// Get retrieves a buffer from the pool, creating one if necessary.
	Get = _pool.Get
)
View Source
var HttpPrefixes = map[Level]Prefix{
	GetLevel: {
		Text:  GetLevel,
		Color: ColorCyan,
	},
	DeleteLevel: {
		Text:  DeleteLevel,
		Color: ColorCyan,
	},
	ConnectLevel: {
		Text:  ConnectLevel,
		Color: ColorCyan,
	},
	HeadLevel: {
		Text:  HeadLevel,
		Color: ColorCyan,
	},
	OptionsLevel: {
		Text:  OptionsLevel,
		Color: ColorCyan,
	},
	PostLevel: {
		Text:  PostLevel,
		Color: ColorCyan,
	},
	PutLevel: {
		Text:  PutLevel,
		Color: ColorCyan,
	},
	TraceLevel: {
		Text:  TraceLevel,
		Color: ColorCyan,
	},
}
View Source
var Prefixes = map[Level]Prefix{
	Fatal: {
		Text:  Fatal,
		Color: ColorFatalRed,
		File:  true,
	},
	Error: {
		Text:  Error,
		Color: ColorRed,
	},
	Warn: {
		Text:  Warn,
		Color: ColorOrange,
	},
	Info: {
		Text:  Info,
		Color: ColorGreen,
	},
	Trace: {
		Text:  Trace,
		Color: ColorCyan,
		File:  true,
	},
	Debug: {
		Text:  Debug,
		Color: ColorPurple,
	},
}

Functions

func Blue

func Blue(data []byte) []byte

Blue apply blue color to the data

func Cyan

func Cyan(data []byte) []byte

Cyan apply cyan color to the data

func Gray

func Gray(data []byte) []byte

Gray apply gray color to the data

func Green

func Green(data []byte) []byte

Green apply green color to the data

func Orange

func Orange(data []byte) []byte

Orange apply orange color to the data

func Purple

func Purple(data []byte) []byte

Purple apply purple color to the data

func Red

func Red(data []byte) []byte

Red apply red color to the data

Types

type Color

type Color []byte
var (
	ColorRed    Color = []byte("\u001B[0;31m")
	ColorGreen  Color = []byte("\u001B[0;32m")
	ColorOrange Color = []byte("\u001B[0;33m")
	ColorBlue   Color = []byte("\u001B[0;34m")
	ColorPurple Color = []byte("\u001B[0;35m")
	ColorCyan   Color = []byte("\u001B[0;36m")
	ColorGray   Color = []byte("\u001B[0;37m")

	ColorFatalRed    Color = []byte("\u001b[1m\u001b[31m\u001b[7m")
	ColorDarkOrange  Color = []byte("\u001b[1m\u001b[38;5;202m")
	ColorBrightWhite Color = []byte("\u001b[1m\u001b[38;5;255m")
	ColorNicePurple  Color = []byte("\u001b[1m\u001b[38;5;99m")
)

func UncheckedCustomColor

func UncheckedCustomColor(b []byte) Color

UncheckedCustomColor wrapper, this does not validate color

type ColorLogger

type ColorLogger struct {
	*buffer.Buffer
}

func NewColorLogger

func NewColorLogger() ColorLogger

func (*ColorLogger) Append

func (cb *ColorLogger) Append(data []byte)

Append byte slice to buffer

func (*ColorLogger) AppendSpace

func (cb *ColorLogger) AppendSpace()

func (*ColorLogger) AppendWithColor

func (cb *ColorLogger) AppendWithColor(data []byte, color Color)

AppendWithColor byte slice to buffer

func (*ColorLogger) Blue

func (cb *ColorLogger) Blue()

Blue apply blue color to the data

func (*ColorLogger) BrightOrange

func (cb *ColorLogger) BrightOrange()

BrightOrange apply gray color to the data

func (*ColorLogger) Cyan

func (cb *ColorLogger) Cyan()

Cyan apply cyan color to the data

func (*ColorLogger) Gray

func (cb *ColorLogger) Gray()

Gray apply gray color to the data

func (*ColorLogger) Green

func (cb *ColorLogger) Green()

Green apply green color to the data

func (*ColorLogger) NicePurple

func (cb *ColorLogger) NicePurple()

NicePurple apply gray color to the data

func (*ColorLogger) Off

func (cb *ColorLogger) Off()

Off apply no color to the data

func (*ColorLogger) Orange

func (cb *ColorLogger) Orange()

Orange apply orange color to the data

func (*ColorLogger) Purple

func (cb *ColorLogger) Purple()

Purple apply purple color to the data

func (*ColorLogger) Red

func (cb *ColorLogger) Red()

Red apply red color to the data

func (*ColorLogger) White

func (cb *ColorLogger) White()

White apply gray color to the data

func (*ColorLogger) WriteColor

func (cb *ColorLogger) WriteColor(color Color)

WriteColor apply given color

type FancyHttpLog added in v0.0.13

type FancyHttpLog interface {
	FancyLogger
	Methods

	WithHeaders() FancyHttpLog
	DebugHeaders() bool
}

func NewHttpLogger added in v0.0.11

func NewHttpLogger(out FdWriter) FancyHttpLog

func NewHttpLoggerWithError added in v0.0.11

func NewHttpLoggerWithError(out FdWriter, err FdWriter) FancyHttpLog

func NewHttpLoggerWithName added in v0.0.11

func NewHttpLoggerWithName(name string, out FdWriter) FancyHttpLog

func NewHttpLoggerWithNameAndError added in v0.0.11

func NewHttpLoggerWithNameAndError(name string, out FdWriter, err FdWriter) FancyHttpLog

type FancyLogger added in v0.0.11

type FancyLogger interface {
	StandardLog
	FormatLog
	MappedLog
	PrefixLog

	WithColor() FancyLogger
	WithoutColor() FancyLogger
	WithDebug() FancyLogger
	WithoutDebug() FancyLogger
	WithTrace() FancyLogger
	WithoutTrace() FancyLogger
	IsDebug() bool
	IsTrace() bool
	WithTimestamp() FancyLogger
	WithoutTimestamp() FancyLogger
	Quiet() FancyLogger
	NoQuiet() FancyLogger
	IsQuiet() bool
	// contains filtered or unexported methods
}

type FdWriter

type FdWriter interface {
	io.Writer
	Fd() uintptr
}

FdWriter interface extends existing io.Writer with file descriptor function support

type FormatLog added in v0.0.11

type FormatLog interface {
	Infof(format string, a ...any)
	Debugf(format string, a ...any)
	Warnf(format string, a ...any)
	Errorf(format string, a ...any)
	Tracef(format string, a ...any)
	Fatalf(format string, a ...any)
}

type HttpLog added in v0.0.11

type HttpLog struct {
	FancyLogger
	// contains filtered or unexported fields
}

func (*HttpLog) ConnectMethod added in v0.0.13

func (h *HttpLog) ConnectMethod(a map[string]any, status int)

func (*HttpLog) DebugHeaders added in v0.0.13

func (h *HttpLog) DebugHeaders() bool

func (*HttpLog) DeleteMethod added in v0.0.13

func (h *HttpLog) DeleteMethod(a map[string]any, status int)

func (*HttpLog) GetMethod added in v0.0.13

func (h *HttpLog) GetMethod(a map[string]any, status int)

func (*HttpLog) HeadMethod added in v0.0.13

func (h *HttpLog) HeadMethod(a map[string]any, status int)

func (*HttpLog) OptionsMethod added in v0.0.13

func (h *HttpLog) OptionsMethod(a map[string]any, status int)

func (*HttpLog) PostMethod added in v0.0.13

func (h *HttpLog) PostMethod(a map[string]any, status int)

func (*HttpLog) PutMethod added in v0.0.13

func (h *HttpLog) PutMethod(a map[string]any, status int)

func (*HttpLog) TraceMethod added in v0.0.13

func (h *HttpLog) TraceMethod(a map[string]any, status int)

func (*HttpLog) WithHeaders added in v0.0.13

func (h *HttpLog) WithHeaders() FancyHttpLog

type Level added in v0.0.4

type Level string
const (
	Fatal Level = "FATAL"
	Error Level = "ERROR"
	Warn  Level = "WARN"
	Info  Level = "INFO"
	Debug Level = "DEBUG"
	Trace Level = "TRACE"
)
const (
	GetLevel     Level = "GET"
	DeleteLevel  Level = "DELETE"
	ConnectLevel Level = "CONNECT"
	HeadLevel    Level = "HEAD"
	OptionsLevel Level = "OPTIONS"
	PostLevel    Level = "POST"
	PutLevel     Level = "PUT"
	TraceLevel   Level = "TRACE"
)

type Logger

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

Logger struct define the underlying storage for single logger

func New

func New(out FdWriter) *Logger

New returns new Logger instance with predefined writer output and automatically detect terminal coloring support

func NewWithError

func NewWithError(out FdWriter, err FdWriter) *Logger

NewWithError returns new Logger instance with predefined writer output and automatically detect terminal coloring support. out would be something like os.Stdout and err would be something like os.Stderr

func NewWithName

func NewWithName(name string, out FdWriter) *Logger

NewWithName {(name string out FdWriter) *Logger { returns new Logger instance with predefined writer output and automatically detect terminal coloring support

func NewWithNameAndError

func NewWithNameAndError(name string, out FdWriter, err FdWriter) *Logger

NewWithNameAndError {(name string out FdWriter) *Logger { returns new Logger instance with predefined writer output and automatically detect terminal coloring support

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug print debug message to output if debug output enabled

func (*Logger) DebugMap

func (l *Logger) DebugMap(v map[string]interface{})

func (*Logger) Debugf

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

Debugf print formatted debug message to output if debug output enabled

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

Error print error message to output

func (*Logger) ErrorMap

func (l *Logger) ErrorMap(v map[string]interface{})

func (*Logger) Errorf

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

Errorf print formatted error message to output

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

Fatal print fatal message to output and quit the application with status 1

func (*Logger) FatalMap

func (l *Logger) FatalMap(v map[string]interface{})

func (*Logger) FatalMapWithCode

func (l *Logger) FatalMapWithCode(exit int, v map[string]interface{})

func (*Logger) FatalWithCode

func (l *Logger) FatalWithCode(exit int, v ...interface{})

FatalWithCode print formatted fatal message to output and quit the application with status code provider

func (*Logger) FatalWithCodef

func (l *Logger) FatalWithCodef(format string, exit int, v ...interface{})

FatalWithCodef print formatted fatal message to output and quit the application with status code provider

func (*Logger) Fatalf

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

Fatalf print formatted fatal message to output and quit the application with status 1

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

Info print informational message to output

func (*Logger) InfoMap

func (l *Logger) InfoMap(v map[string]interface{})

func (*Logger) Infof

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

Infof print formatted informational message to output

func (*Logger) IsDebug

func (l *Logger) IsDebug() bool

IsDebug check the state of debugging output

func (*Logger) IsQuiet

func (l *Logger) IsQuiet() bool

IsQuiet check for quiet state

func (*Logger) IsTrace

func (l *Logger) IsTrace() bool

IsTrace check the state of trace output

func (*Logger) Log added in v0.0.11

func (l *Logger) Log(prefix Prefix, a ...any)

func (*Logger) LogMap added in v0.0.11

func (l *Logger) LogMap(prefix Prefix, a map[string]any)

func (*Logger) Logf added in v0.0.11

func (l *Logger) Logf(prefix Prefix, format string, a ...any)

func (*Logger) NoQuiet

func (l *Logger) NoQuiet() FancyLogger

NoQuiet turn on all log output

func (*Logger) Quiet

func (l *Logger) Quiet() FancyLogger

Quiet turn off all log output

func (*Logger) SetDefaultTimeFn

func (l *Logger) SetDefaultTimeFn(timestampFunc TimestampFunc)

SetDefaultTimeFn override the default timestamp producer

func (*Logger) SetTimestampColor

func (l *Logger) SetTimestampColor(color Color)

SetTimestampColor override the default color for timestamps

func (*Logger) Trace

func (l *Logger) Trace(v ...interface{})

Trace print trace message to output if debug output enabled

func (*Logger) TraceMap

func (l *Logger) TraceMap(v map[string]interface{})

TraceMap print formatted trace message to output if debug output enabled

func (*Logger) Tracef

func (l *Logger) Tracef(format string, v ...interface{})

Tracef print formatted trace message to output if debug output enabled

func (*Logger) Warn

func (l *Logger) Warn(v ...interface{})

Warn print warning message to output

func (*Logger) WarnMap

func (l *Logger) WarnMap(v map[string]interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...any)

Warnf print formatted warning message to output

func (*Logger) WithColor

func (l *Logger) WithColor() FancyLogger

WithColor explicitly turn on colorful features on the log

func (*Logger) WithDebug

func (l *Logger) WithDebug() FancyLogger

WithDebug turn on debugging output on the log to reveal debug and trace level

func (*Logger) WithTimestamp

func (l *Logger) WithTimestamp() FancyLogger

WithTimestamp turn on timestamp output on the log

func (*Logger) WithTrace

func (l *Logger) WithTrace() FancyLogger

WithTrace turn on trace output on the log to reveal debug and trace level

func (*Logger) WithoutColor

func (l *Logger) WithoutColor() FancyLogger

WithoutColor explicitly turn off colorful features on the log

func (*Logger) WithoutDebug

func (l *Logger) WithoutDebug() FancyLogger

WithoutDebug turn off debugging output on the log

func (*Logger) WithoutTimestamp

func (l *Logger) WithoutTimestamp() FancyLogger

WithoutTimestamp turn off timestamp output on the log

func (*Logger) WithoutTrace

func (l *Logger) WithoutTrace() FancyLogger

WithoutTrace turn off trace output on the log

type MappedLog added in v0.0.11

type MappedLog interface {
	InfoMap(a map[string]any)
	DebugMap(a map[string]any)
	WarnMap(a map[string]any)
	ErrorMap(a map[string]any)
	TraceMap(a map[string]any)
	FatalMap(a map[string]any)
}

type Methods added in v0.0.11

type Methods interface {
	GetMethod(a map[string]any, status int)
	DeleteMethod(a map[string]any, status int)
	ConnectMethod(a map[string]any, status int)
	HeadMethod(a map[string]any, status int)
	OptionsMethod(a map[string]any, status int)
	PostMethod(a map[string]any, status int)
	PutMethod(a map[string]any, status int)
	TraceMethod(a map[string]any, status int)
}

type Prefix

type Prefix struct {
	Text  Level
	Color Color
	File  bool
}

Prefix struct define plain and color byte Text will prefix text to include in the log Color will be the color applied to the log File flag set to true will display code trace

type PrefixLog added in v0.0.11

type PrefixLog interface {
	Log(prefix Prefix, a ...any)
	Logf(prefix Prefix, format string, a ...any)
	LogMap(prefix Prefix, a map[string]any)
}

type PrefixText added in v0.0.11

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

PrefixText struct to hold the values of the prefixes to be used, and the tail size to add spaces to the end of the prefix

type StandardLog added in v0.0.11

type StandardLog interface {
	Info(a ...any)
	Debug(a ...any)
	Warn(a ...any)
	Error(a ...any)
	Trace(a ...any)
	Fatal(a ...any)
}

type TimestampFunc

type TimestampFunc func() (time time.Time, layout string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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