logi

package module
v0.0.17-0...-58d91fe Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2020 License: Unlicense Imports: 10 Imported by: 74

README

Logo Logi

Logging subsystem with pretty print, code loc, channel and Writer outputs

GoDoc Go Report Card

Documentation

Index

Constants

View Source
const (
	Off   = "off"
	Fatal = "fatal"
	Error = "error"
	Warn  = "warn"
	Info  = "info"
	Check = "check"
	Debug = "debug"
	Trace = "trace"
)

Variables

View Source
var (
	// NoClosure is a noop for a closure print function
	NoClosure = func() PrintcFunc {
		f := func(_ func() string) {}
		return f
	}
	// NoPrintf is a noop for a closure printf function
	NoPrintf = func() PrintfFunc {
		f := func(_ string, _ ...interface{}) {}
		return f
	}
	// NoPrintln is a noop for a println function
	NoPrintln = func() PrintlnFunc {
		f := func(_ ...interface{}) {}
		return f
	}
	// NoPrintln is a noop for a println function
	NoCheck = func() CheckFunc {
		f := func(_ error) bool {
			return true
		}
		return f
	}
	// NoSpew is a noop for a spew function
	NoSpew = func() SpewFunc {
		f := func(_ interface{}) {}
		return f
	}
	// StartupTime allows a shorter log prefix as time since start
	StartupTime    = time.Now()
	BackgroundGrey = "\u001b[48;5;240m"
	ColorBlue      = "\u001b[38;5;33m"
	ColorBold      = "\u001b[1m"
	ColorBrown     = "\u001b[38;5;130m"
	ColorCyan      = "\u001b[36m"
	ColorFaint     = "\u001b[2m"
	ColorGreen     = "\u001b[38;5;40m"
	ColorItalic    = "\u001b[3m"
	ColorOff       = "\u001b[0m"
	ColorOrange    = "\u001b[38;5;208m"
	ColorPurple    = "\u001b[38;5;99m"
	ColorRed       = "\u001b[38;5;196m"
	ColorUnderline = "\u001b[4m"
	ColorViolet    = "\u001b[38;5;201m"
	ColorYellow    = "\u001b[38;5;226m"
)
View Source
var L = Empty()
View Source
var Levels = []string{
	Off, Fatal, Error, Warn, Info, Check, Debug, Trace,
}

Functions

func Composite

func Composite(text, level string, color bool, split string) string

func DirectionString

func DirectionString(inbound bool) string

printlnFunc prints a log entry like Println

func FileExists

func FileExists(filePath string) bool

sanitizeLoglevel accepts a string and returns a default if the input is not in the Levels slice

func PickNoun

func PickNoun(n int, singular, plural string) string

func Print

func Print(a ...interface{})

func Printf

func Printf(format string, a ...interface{})

ps spews a variable

func Println

func Println(a ...interface{})

printcFunc prints from a closure returning a string

func SetLogWriter

func SetLogWriter(w io.Writer)

Types

type CheckFunc

type CheckFunc func(err error) bool

type Entry

type Entry struct {
	Time         time.Time
	Level        string
	CodeLocation string
	Text         string
}

type LogWriter

type LogWriter struct {
	io.Writer
}

func (*LogWriter) Print

func (w *LogWriter) Print(a ...interface{})

SetLevel enables or disables the various print functions

func (*LogWriter) Printf

func (w *LogWriter) Printf(format string, a ...interface{})

func (*LogWriter) Println

func (w *LogWriter) Println(a ...interface{})

SetLogPaths sets a file path to write logs

type Logger

type Logger struct {
	Fatal         PrintlnFunc
	Error         PrintlnFunc
	Warn          PrintlnFunc
	Info          PrintlnFunc
	Check         CheckFunc
	Debug         PrintlnFunc
	Trace         PrintlnFunc
	Fatalf        PrintfFunc
	Errorf        PrintfFunc
	Warnf         PrintfFunc
	Infof         PrintfFunc
	Checkf        CheckFunc
	Debugf        PrintfFunc
	Tracef        PrintfFunc
	Fatalc        PrintcFunc
	Errorc        PrintcFunc
	Warnc         PrintcFunc
	Infoc         PrintcFunc
	Checkc        CheckFunc
	Debugc        PrintcFunc
	Tracec        PrintcFunc
	Fatals        SpewFunc
	Errors        SpewFunc
	Warns         SpewFunc
	Infos         SpewFunc
	Debugs        SpewFunc
	Traces        SpewFunc
	LogFileHandle *os.File
	Writer        LogWriter
	Color         bool
	Split         string
	// If this channel is loaded log entries are composed and sent to it
	LogChan chan Entry
}

func Empty

func Empty() *Logger

PickNoun returns the singular or plural form of a noun depending on the count n.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level string, color bool, split string) *Logger

Entry is a log entry to be printed as json to the log file

func (*Logger) SetLogPaths

func (l *Logger) SetLogPaths(logPath, logFileName string)

type PrintcFunc

type PrintcFunc func(func() string)

type PrintfFunc

type PrintfFunc func(format string, a ...interface{})

type PrintlnFunc

type PrintlnFunc func(a ...interface{})

type SpewFunc

type SpewFunc func(interface{})

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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