ng

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: MIT Imports: 18 Imported by: 40

Documentation

Overview

//http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#8-colors

//Global Format
	\u001b[+COLOR+m		Non BRIGHT
	\u001b[+COLOR+;1m	BRIGHT

// FORMATTING
	\u001b[1m		BOLD
	\u001b[4m		Underline
	\u001b[7m		Reversed

// Formats Foreground
	8 bit		\u001b[30m
	16 bit		\u001b[30;1m
	256 bit 	\u001b[38;5;${ID}m

//Colors
	CLR_BLK       = "\x1b[30m"   // black
	CLR_BLKBRIGHT = "\x1b[30;1m" // black bright
	CLR_RED       = "\x1b[31m"   // red
	CLR_REDBRT    = "\x1b[31;1m" // red
	CLR_GRN       = "\x1b[32m"   // green
	CLR_YLLW      = "\x1b[33m"   // yellow
	CLR_BLU       = "\x1b[34;1m" // blue
	CLR_MAG       = "\x1b[35;1m" // magenta
	CLR_CYAN      = "\x1b[36;1m" // cyan
	CLR_WHT   = "\x1b[37;1m" // white

CLR_RESET = "\x1b[0m" // reset to default

//ASCII 256
	CLR_DEFAULT = "\x1b[38;5;10m"
	CLR_ERR     = "\x1b[38;5;196m" //red
	CLR_WARN    = "\x1b[38;5;11m"  //yellow
	CLR_INFO    = "\x1b[38;5;174m" // light red/brown

//Formats Background Color
bright versions of the background colors do not change the background,
	but rather make the foreground text brighter
8 bit 	\u001b[40m
16 bit 	\u001b[40;1m
256 bit	\u001b[48;5;
CLRBG_BLK        = "\x1b[40m"
CLRBG_BLKBRIGHTb = "\x1b[40;1m"

Index

Constants

View Source
const (
	ParamMsg   = "msg"
	ParamLevel = "level"
	ParamTime  = "time"
)

Default key names for the default fields

View Source
const DefaultTimestampFormat = time.RFC3339

Variables

View Source
var (
	// if NOT a terminal then turn off COLOR
	DumbTerm    = os.Getenv("TERM") == "dumb"
	Term        = isatty.IsTerminal(os.Stdout.Fd())
	CygwinTerm  = isatty.IsCygwinTerminal(os.Stdout.Fd())
	NotTerminal = os.Getenv("TERM") == "dumb" ||
		(!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()))
)
View Source
var (
	DEBUGX2 = enum.DEBUGX2
	DEBUG   = enum.DEBUG
	FATAL   = enum.FATAL
	ERROR   = enum.ERROR
	WARN    = enum.WARN
	INFO    = enum.INFO
	NONE    = enum.NONE
)

Functions

func Black

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

func Blue

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

func Bool2Str

func Bool2Str(val bool) string

func ColorBrightFmt

func ColorBrightFmt(color ColorAttr) string

func ColorFmt

func ColorFmt(color ColorAttr) string

func Cyan

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

func Debug

func Debug(format string, args ...interface{})

func DebugX2

func DebugX2(format string, args ...interface{})

func DebugX2ln

func DebugX2ln(args ...interface{})

func Debugln

func Debugln(args ...interface{})

func DisableTimestamp

func DisableTimestamp()

func EnableTimestamp

func EnableTimestamp()

func Error

func Error(format string, args ...interface{})

func Errorln

func Errorln(args ...interface{})

func Exit

func Exit(code int)

func Flags

func Flags() int

func Green

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

func HiBlack

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

func Info

func Info(format string, args ...interface{})

func Infoln

func Infoln(args ...interface{})

func IsDebug

func IsDebug() bool

func IsDebugX2

func IsDebugX2() bool

func IsError

func IsError() bool

func IsFatal

func IsFatal() bool

func IsInfo

func IsInfo() bool

func IsNone

func IsNone() bool

func IsWarn

func IsWarn() bool

func Level

func Level() enum.LogLevel

func Logf

func Logf(lvl enum.LogLevel, format string, args ...interface{})

func Logln

func Logln(lvl enum.LogLevel, args ...interface{})

func Magenta

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

func Modify

func Modify(opts ...LogOption)

func Print

func Print(args ...interface{})

func Printf

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

func Println

func Println(args ...interface{})

func Red

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

func SetFlags

func SetFlags(flg enum.Flags)

func SetFormatter

func SetFormatter(formatter Layout)

func SetLevel

func SetLevel(level enum.LogLevel)

func ShowConfig

func ShowConfig()

func White

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

func Yellow

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

Types

type Appender

type Appender interface {
	Name() string
	//package or name to find in message, in Java this was a package
	Applicable(filter string) bool
	Process(msg []byte)
	DisableColor() bool
}

type Clr

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

func CachedColor

func CachedColor(p ColorAttr) *Clr

func New

func New(value ...ColorAttr) *Clr

func (*Clr) Add

func (c *Clr) Add(value ...ColorAttr) *Clr

func (*Clr) DisableColor

func (c *Clr) DisableColor()

func (*Clr) Print

func (c *Clr) Print(format string) string

func (*Clr) Printf

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

func (*Clr) Set

func (c *Clr) Set() string

type ColorAttr

type ColorAttr int
const (
	Reset ColorAttr = iota
	BOLD
	FAINT // does nothing
	ITALIC
	UNDERLINE
	BlinkSlow  // does nothing
	BlinkRapid // does nothing
	Reversed
	NonDisplayed
)

Base Color Attributes

const (
	FgBlack ColorAttr = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite

	CLRRESET              = "\u001b[0m" // reset to default
	ClearTerminalSequence = "\033[2J"
)

FG Text Colors

const (
	HiBLACK ColorAttr = iota + 90
	HiRED
	HiGREEN
	HiYELLOW
	HiBLUE
	HiMAGENTA
	HiCYAN
	HiWHITE
)

FG Hi-Intensity Text

const (
	BgBlack ColorAttr = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
)

BG text colors

const (
	BgHiBlack ColorAttr = iota + 100
	BgHiRed
	BgHiGreen
	BgHiYellow
	BgHiBlue
	BgHiMagenta
	BgHiCyan
	BgHiWhite
)

Background Hi-Intensity text colors

func (ColorAttr) String

func (l ColorAttr) String() string

func (ColorAttr) Types

func (l ColorAttr) Types() map[int]string

Types pulls full list as []string

func (ColorAttr) Val

func (l ColorAttr) Val() int

func (ColorAttr) ValAsString

func (l ColorAttr) ValAsString() string

type Column

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

type ConsoleAppender

type ConsoleAppender struct {
	*OutAppender
}

******************* CONSOLE APPENDER ********************

func NewConsoleAppender

func NewConsoleAppender(filter string) *ConsoleAppender

func (*ConsoleAppender) Applicable

func (c *ConsoleAppender) Applicable(filter string) bool

func (*ConsoleAppender) DisableColor

func (c *ConsoleAppender) DisableColor() bool

func (*ConsoleAppender) Name

func (c *ConsoleAppender) Name() string

func (*ConsoleAppender) Process

func (c *ConsoleAppender) Process(msg []byte)

type CronTriggerPolicy

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

tests using cron

func NewCronTriggerPolicy

func NewCronTriggerPolicy(schedule string, evalOnStart bool) *CronTriggerPolicy

func (*CronTriggerPolicy) Rotate

func (s *CronTriggerPolicy) Rotate(fileName string) bool

type DefaultStrategy

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

func NewDefaultStrategy

func NewDefaultStrategy(name, location string, min, max, compressionLevel int) *DefaultStrategy

func (*DefaultStrategy) CompressionLevel

func (s *DefaultStrategy) CompressionLevel() int

func (*DefaultStrategy) Location

func (s *DefaultStrategy) Location() string

func (*DefaultStrategy) Max

func (s *DefaultStrategy) Max() int

func (*DefaultStrategy) Min

func (s *DefaultStrategy) Min() int

func (*DefaultStrategy) Name

func (s *DefaultStrategy) Name() string

type FailoverAppender

type FailoverAppender struct {
	RetryIntervalSeconds int // default 60 sec
	// contains filtered or unexported fields
}

******************* FAIL OVER APPENDER ********************

func NewFailoverAppender

func NewFailoverAppender(primary Appender, failovers []Appender) *FailoverAppender

func (*FailoverAppender) Applicable

func (f *FailoverAppender) Applicable(msg string) bool

func (*FailoverAppender) DisableColor

func (f *FailoverAppender) DisableColor() bool

func (*FailoverAppender) Name

func (f *FailoverAppender) Name() string

func (*FailoverAppender) Process

func (f *FailoverAppender) Process(msg []byte)

type Fields

type Fields map[string]interface{}

Fields type, used to pass to `WithFields`.

type FileAppender

type FileAppender struct {
	*OutAppender

	FilePerm os.FileMode //default 0777
	UserID   int
	GroupID  int
	// contains filtered or unexported fields
}

func NewFileAppender

func NewFileAppender(filter, fileName, name string, bufferSize int) (*FileAppender, error)

func (*FileAppender) Applicable

func (f *FileAppender) Applicable(msg string) bool

func (*FileAppender) DisableColor

func (f *FileAppender) DisableColor() bool

func (*FileAppender) Name

func (f *FileAppender) Name() string

func (*FileAppender) Process

func (f *FileAppender) Process(msg []byte)

type JSONLayout

type JSONLayout struct {
	// TimestampFormat sets the format used for marshaling timestamps.
	TimestampFormat string

	// DisableTimestamp allows disabling automatic timestamps in output
	DisableTimestamp bool

	ParamMap ParamMap
}

func (*JSONLayout) Colors

func (f *JSONLayout) Colors(enable bool)

func (*JSONLayout) Description

func (f *JSONLayout) Description() string

func (*JSONLayout) DisableTimeStamp

func (f *JSONLayout) DisableTimeStamp()

func (*JSONLayout) EnableTimeStamp

func (f *JSONLayout) EnableTimeStamp()

func (*JSONLayout) Format

func (f *JSONLayout) Format(entry *LogMsg, disableColor bool) ([]byte, error)

type Layout

type Layout interface {
	Format(*LogMsg, bool) ([]byte, error)
	Description() string
	Colors(bool)
	DisableTimeStamp()
	EnableTimeStamp()
}

type LogMsg

type LogMsg struct {
	Logger *StdLogger
	//None, Fatal, Error, Warn, Info, Debug
	Level enum.LogLevel
	//Message passed into logger
	Message string
	//Fields passed to template i.e. for JSON output
	Fields []Fields
	// Time entry was created
	Time time.Time
	// When formatter is called in entry.log(), an Buffer may be set to entry
	Buffer *bytes.Buffer
	// contains filtered or unexported fields
}

Create a pool for reuse in order to speed up process of logging

func NewEntry

func NewEntry(logger *StdLogger) *LogMsg

func WithFields

func WithFields(fields []Fields) *LogMsg

WithFields creates an entry from the standard logger and adds multiple fields to it. This is simply a helper for `WithField`, invoking it once for each field.

Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal or Panic on the Entry it returns.

func (*LogMsg) Error

func (entry *LogMsg) Error(args ...interface{})

func (*LogMsg) Fatal

func (entry *LogMsg) Fatal(args ...interface{})

func (*LogMsg) Info

func (entry *LogMsg) Info(args ...interface{})

func (*LogMsg) LogEnt

func (entry *LogMsg) LogEnt(level enum.LogLevel, format, caller string, rtn bool, args ...interface{})

func (*LogMsg) WithFields

func (entry *LogMsg) WithFields(fields []Fields) *LogMsg

Add a map of fields to the Entry.

type LogOption

type LogOption func(h *StdLogger)

func Appenders

func Appenders(a ...Appender) LogOption

func CallDepth

func CallDepth(i int) LogOption

func ColorsOn

func ColorsOn() LogOption

func DebugColor

func DebugColor(clr ColorAttr) LogOption

func ErrColor

func ErrColor(clr ColorAttr) LogOption

func Formatr

func Formatr(f Layout) LogOption

func HiColorsOn

func HiColorsOn() LogOption

func InfoColor

func InfoColor(clr ColorAttr) LogOption

func LogLevel

func LogLevel(l enum.LogLevel) LogOption

Logger returns a MDHashOption that sets the logger for the hash.

func LogOut

func LogOut(i io.Writer) LogOption

func SetFlgs

func SetFlgs(i enum.Flags) LogOption

func WarnColor

func WarnColor(clr ColorAttr) LogOption

type MailAppender added in v0.0.4

type MailAppender struct {
	*OutAppender
	// contains filtered or unexported fields
}

func NewMailAppender added in v0.0.4

func NewMailAppender(filter, smtpServer, smtpUsername, smtpPass, smtpFrom, smtpTo, smtpSubject string, smtpPort int) (*MailAppender, error)

func (*MailAppender) Applicable added in v0.0.4

func (f *MailAppender) Applicable(msg string) bool

func (*MailAppender) DisableColor added in v0.0.4

func (f *MailAppender) DisableColor() bool

func (*MailAppender) Name added in v0.0.4

func (f *MailAppender) Name() string

func (*MailAppender) Process added in v0.0.4

func (f *MailAppender) Process(msg []byte)

type OutAppender

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

type ParamMap

type ParamMap map[key]string

FieldMap allows customization of the key names for default fields.

func (ParamMap) Find

func (f ParamMap) Find(key key) string

type PrinterTable

type PrinterTable struct {
	Table
	// contains filtered or unexported fields
}

func NewTable

func NewTable(header []string, rows [][]string, opts ...TableOption) (*PrinterTable, error)

func (*PrinterTable) AdjustData

func (t *PrinterTable) AdjustData()

func (*PrinterTable) Print

func (t *PrinterTable) Print()

Loop over each column and find largest width to make that column for all in it

func (*PrinterTable) Sizes

func (t *PrinterTable) Sizes()

type ResyncOnce

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

func (*ResyncOnce) Do

func (o *ResyncOnce) Do(f func())

func (*ResyncOnce) Reset

func (o *ResyncOnce) Reset()

type RollingFileAppender

type RollingFileAppender struct {
	*FileAppender
	// contains filtered or unexported fields
}

func NewRollingFileAppender

func NewRollingFileAppender(filter, fileName, name string, bufferSize int, trigger TriggerPolicy, strategy Strategy) (*RollingFileAppender, error)

func (*RollingFileAppender) Applicable

func (r *RollingFileAppender) Applicable(filter string) bool

func (*RollingFileAppender) DisableColor

func (r *RollingFileAppender) DisableColor() bool

func (*RollingFileAppender) Name

func (r *RollingFileAppender) Name() string

func (*RollingFileAppender) Process

func (r *RollingFileAppender) Process(msg []byte)

TODO add logging for rolling

type Row

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

func BuildRow

func BuildRow(row []string) *Row

func BuildTableBody

func BuildTableBody(rowsData [][]string) []*Row

type SizeTriggerPolicy

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

checks while running or on start

func NewSizeTriggerPolicy

func NewSizeTriggerPolicy(maxsize int64, evalOnStart bool) *SizeTriggerPolicy

func (*SizeTriggerPolicy) Rotate

func (s *SizeTriggerPolicy) Rotate(fileName string) bool

type StdLogger

type StdLogger struct {
	Formatter Layout

	Out io.Writer

	ColorDEFAULT string
	ColorERR     string
	ColorWARN    string
	ColorINFO    string
	ColorDEBUG   string
	ColorDEBUGX2 string

	// Used to sync writing to the log. Locking is enabled by Default
	MU  util.MutexWrap
	Now time.Time
	// contains filtered or unexported fields
}

func Logger

func Logger() *StdLogger

func NewLogger

func NewLogger(opts ...LogOption) *StdLogger

NewLogger can be used instead of the default to change settings

func (*StdLogger) Caller

func (l *StdLogger) Caller() string

func (*StdLogger) Flags

func (l *StdLogger) Flags() int

func (*StdLogger) Level

func (l *StdLogger) Level() enum.LogLevel

func (*StdLogger) Logf

func (l *StdLogger) Logf(lvl enum.LogLevel, format string, args ...interface{})

func (*StdLogger) Logln

func (l *StdLogger) Logln(lvl enum.LogLevel, args ...interface{})

func (*StdLogger) Print

func (l *StdLogger) Print(args ...interface{})

func (*StdLogger) Printf

func (l *StdLogger) Printf(format string, args ...interface{})

func (*StdLogger) Println

func (l *StdLogger) Println(args ...interface{})

func (*StdLogger) SetFlags

func (l *StdLogger) SetFlags(flg enum.Flags)

* SetFlags Ldate = 1 << iota // the date in the local time zone: 2009/01/23 Ltime // the time in the local time zone: 01:23:23 Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime. Llongfile // full file name and line number: /a/b/c/d.go:23 Lshortfile // final file name element and line number: d.go:23. overrides Llongfile LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone LstdFlags = Ldate | Ltime // initial values for the standard logger

func (*StdLogger) SetFormatter

func (l *StdLogger) SetFormatter(formatter Layout)

func (*StdLogger) SetLevel

func (l *StdLogger) SetLevel(level enum.LogLevel)

func (*StdLogger) ShowOptions

func (l *StdLogger) ShowOptions()

func (*StdLogger) WithFields

func (l *StdLogger) WithFields(fields []Fields) *LogMsg

Adds a struct of fields to the log entry. All it does is call `WithField` for each `Field`.

type Strategy

type Strategy interface {
	Name() string     // Name of file
	Location() string // Location to store old files
	Min() int
	Max() int
	CompressionLevel() int
}

Archive strategy

type Table

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

type TableOption

type TableOption func(h *PrinterTable)

func TableBorder

func TableBorder(border bool) TableOption

func TableHorizontal

func TableHorizontal(horizontal bool) TableOption

func TableName

func TableName(tblName string) TableOption

type TextLayout

type TextLayout struct {
	//Force Color
	ForceColor bool
	// Force disabling colors.
	DisableColors bool

	// TimestampFormat to use for display when a full timestamp is printed
	TimestampFormat string // The fields are sorted by default for a consistent output. For applications
	// that log extremely frequently and don't use the JSON formatter this may not
	// be desired.
	DisableSorting   bool
	QuoteEmptyVal    bool
	DisableTimestamp bool
	sync.Once
	// contains filtered or unexported fields
}

func (*TextLayout) Colors

func (f *TextLayout) Colors(enable bool)

func (*TextLayout) Description

func (f *TextLayout) Description() string

func (*TextLayout) DisableTimeStamp

func (f *TextLayout) DisableTimeStamp()

func (*TextLayout) EnableTimeStamp

func (f *TextLayout) EnableTimeStamp()

func (*TextLayout) Format

func (f *TextLayout) Format(entry *LogMsg, disableColor bool) ([]byte, error)

type TimeTriggerPolicy

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

tests on interval of hours with a possible max random delay of X

func NewTimeTriggerPolicy

func NewTimeTriggerPolicy(interval, maxRandomDelay int) *TimeTriggerPolicy

func (*TimeTriggerPolicy) Rotate

func (s *TimeTriggerPolicy) Rotate(fileName string) bool

type TriggerPolicy

type TriggerPolicy interface {
	Rotate(string) bool
}

Jump to

Keyboard shortcuts

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