logi

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: Unlicense, Unlicense Imports: 10 Imported by: 0

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 (
	Levels = []string{
		Off,
		Fatal,
		Error,
		Check,
		Warn,
		Info,
		Debug,
		Trace,
	}
	Tags = map[string]string{
		Off:   "",
		Fatal: "FTL",
		Error: "ERR",
		Check: "CHK",
		Warn:  "WRN",
		Info:  "INF",
		Debug: "DBG",
		Trace: "TRC",
	}
	LevelsMap = map[string]int{
		Off:   0,
		Fatal: 1,
		Error: 2,
		Check: 3,
		Warn:  4,
		Info:  5,
		Debug: 6,
		Trace: 7,
	}
	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 = NewLogger("nexus")

This needs to be set to an appropriate value by the calling library

View Source
var TermWidth = func() int { return 80 }

Functions

func Composite

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

func DirectionString

func DirectionString(inbound bool) string

DirectionString is a helper function that returns a string that represents the direction of a connection (inbound or outbound).

func FileExists

func FileExists(filePath string) bool

func PickNoun

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

Types

type CheckFunc

type CheckFunc func(pkg string, err error) bool

type Entry

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

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

type LogWriter

type LogWriter struct {
	io.Writer
	// contains filtered or unexported fields
}

func (*LogWriter) Print

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

func (*LogWriter) Printf

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

func (*LogWriter) Println

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

func (*LogWriter) SetLogWriter

func (wr *LogWriter) SetLogWriter(w io.Writer)

type Logger

type Logger struct {
	Packages      *Pk.Package
	Level         string
	Fatal         PrintlnFunc
	Error         PrintlnFunc
	Warn          PrintlnFunc
	Info          PrintlnFunc
	Check         CheckFunc
	Debug         PrintlnFunc
	Trace         PrintlnFunc
	Fatalf        PrintfFunc
	Errorf        PrintfFunc
	Warnf         PrintfFunc
	Infof         PrintfFunc
	Debugf        PrintfFunc
	Tracef        PrintfFunc
	Fatalc        PrintcFunc
	Errorc        PrintcFunc
	Warnc         PrintcFunc
	Infoc         PrintcFunc
	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
	LogChan       []chan Entry
}

Logger is a struct containing all the functions with nice handy names

func NewLogger

func NewLogger(split string) (l *Logger)

func (*Logger) AddLogChan

func (l *Logger) AddLogChan() (ch chan Entry)

AddLogChan adds a channel that log entries are sent to

func (*Logger) GetLoc

func (l *Logger) GetLoc(loc string, line int) (out string)

func (*Logger) LevelIsActive

func (l *Logger) LevelIsActive(level string) (out bool)

func (*Logger) LoadConfig

func (l *Logger) LoadConfig(configFile []byte)

func (*Logger) LocToPkg

func (l *Logger) LocToPkg(pkg string) (out string)

func (*Logger) Register

func (l *Logger) Register(pkg string) string

func (*Logger) SetLevel

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

func (*Logger) SetLogPaths

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

SetLogPaths sets a file path to write logs

type PrintcFunc

type PrintcFunc func(pkg string, fn func() string)

type PrintfFunc

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

type PrintlnFunc

type PrintlnFunc func(pkg string, a ...interface{})

type SpewFunc

type SpewFunc func(pkg string, a interface{})

Directories

Path Synopsis
Package Entry is a message type for logi log entries
Package Entry is a message type for logi log entries
Pkg
Package Package is a message type for logi package filtering
Package Package is a message type for logi package filtering
Pk
Package consume turns off and on the Serve logging messages and provides a way to receive and process the log messages
Package consume turns off and on the Serve logging messages and provides a way to receive and process the log messages
Package serve receives logi.Entry messages on a channel and sends them when it has been told to Run by Consume, and pauses when it is told Pause
Package serve receives logi.Entry messages on a channel and sends them when it has been told to Run by Consume, and pauses when it is told Pause

Jump to

Keyboard shortcuts

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