Documentation ¶
Overview ¶
bytefmt contains helper methods and constants for converting to and from a human readable byte format.
bytefmt.ByteSize(100.5*bytefmt.MEGABYE) // "100.5M" bytefmt.ByteSize(uint64(1024)) // "1K"
vim: fdm=marker ts=4 sts=4 sw=4 fdl=0
for humanlog to work the keys msg, time, level are necessary (see humanlog handler)
vim: fdm=marker ts=4 sts=4 sw=4 fdl=0
Index ¶
- Constants
- Variables
- func ByteSize(bytes uint64) string
- func Cls()
- func Decorate(l log.Logger, ds ...LoggerDecorator) log.Logger
- func DiffIntSlices(X, Y []int) []int
- func Dump(data interface{}) string
- func E(format string, v ...interface{}) error
- func End(start time.Time)
- func Enter(s string) func()
- func Enter2(s string) func(t time.Time)
- func EnterFunc(ml MyLevels) func(string) func()
- func Exists(name string) bool
- func First(args ...interface{}) interface{}
- func GetFN() string
- func GetFunctionData(i int) (string, string, int, bool)
- func GetKeys(m map[interface{}]interface{}) []interface{}
- func HandleExit()
- func IntersectIntSlices(X, Y []int) []int
- func IsDir(path string) (bool, error)
- func IsStrInSlice(a string, list []string) bool
- func Min(x int, ys ...int) int
- func RandStringBytes(n int) string
- func Rint(num float64) int
- func Second(args ...interface{}) interface{}
- func Shuffle(src []interface{}) []interface{}
- func Slice(args ...interface{}) []interface{}
- func TimeTrack(start time.Time) time.Duration
- func ToBytes(s string) (uint64, error)
- func ToFixed(num float64, precision int) float64
- func ToMegabytes(s string) (uint64, error)
- type DedupT
- type Exit
- type Frame
- type LogClass
- type LogClassMap
- type LogLevelT
- type LoggerDecorator
- type LoggerFmtType
- type LoggerFunc
- type MyLevels
- type TWLog
- func (l *TWLog) GetColor(lgc LogClass) COLOR
- func (l *TWLog) IsSet(lgc LogClass) bool
- func (l *TWLog) L(lgc LogClass, c COLOR, v ...interface{})
- func (l *TWLog) LC(lgc LogClass, v ...interface{})
- func (l *TWLog) LL(lgc LogClass, c COLOR, ss ...interface{})
- func (l *TWLog) LLC(lgc LogClass, ss ...interface{})
- func (l *TWLog) Set(lgc LogClass)
- func (l *TWLog) SetColor(lgc LogClass, c COLOR)
- func (l *TWLog) SetDedup(lgc LogClass)
- func (l *TWLog) Unset(lgc LogClass)
- func (l *TWLog) UnsetDedup(lgc LogClass)
Constants ¶
const ( BYTE = 1.0 KILOBYTE = 1024 * BYTE MEGABYTE = 1024 * KILOBYTE GIGABYTE = 1024 * MEGABYTE TERABYTE = 1024 * GIGABYTE )
const ( NULL = "\uE000" CANCEL = "\uE001" HELP = "\uE002" BACK_SPACE = "\uE003" TAB = "\uE004" CLEAR = "\uE005" RETURN = "\uE006" ENTER = "\uE007" SHIFT = "\uE008" LEFT_SHIFT = "\uE008" CONTROL = "\uE009" LEFT_CONTROL = "\uE009" ALT = "\uE00A" LEFT_ALT = "\uE00A" PAUSE = "\uE00B" ESCAPE = "\uE00C" SPACE = "\uE00D" PAGE_UP = "\uE00E" PAGE_DOWN = "\uE00F" END = "\uE010" HOME = "\uE011" LEFT = "\uE012" ARROW_LEFT = "\uE012" UP = "\uE013" ARROW_UP = "\uE013" RIGHT = "\uE014" ARROW_RIGHT = "\uE014" DOWN = "\uE015" ARROW_DOWN = "\uE015" INSERT = "\uE016" DELETE = "\uE017" SEMICOLON = "\uE018" EQUALS = "\uE019" NUMPAD0 = "\uE01A" NUMPAD1 = "\uE01B" NUMPAD2 = "\uE01C" NUMPAD3 = "\uE01D" NUMPAD4 = "\uE01E" NUMPAD5 = "\uE01F" NUMPAD6 = "\uE020" NUMPAD7 = "\uE021" NUMPAD8 = "\uE022" NUMPAD9 = "\uE023" MULTIPLY = "\uE024" ADD = "\uE025" SEPARATOR = "\uE026" SUBTRACT = "\uE027" DECIMAL = "\uE028" DIVIDE = "\uE029" F1 = "\uE031" F2 = "\uE032" F3 = "\uE033" F4 = "\uE034" F5 = "\uE035" F6 = "\uE036" F7 = "\uE037" F8 = "\uE038" F9 = "\uE039" F10 = "\uE03A" F11 = "\uE03B" F12 = "\uE03C" META = "\uE03D" COMMAND = "\uE03D" ZENKAKU_HANKAKU = "\uE040" )
// const {{{
const ( LOG_NULL int = 0 LOG_FILE int = 1 LOG_CALLER = 1 << iota LOG_FULL )
const MAXDEPTH int = 20
// Enter {{{
Variables ¶
var ( Debug = l.Debug Info = l.Info Warn = l.Warn Error = l.Error Crit = l.Crit )
Definiton of global package logger
Functions ¶
func ByteSize ¶
ByteSize returns a human readable byte string, of the format 10M, 12.5K, etc. The following units are available:
T Terabyte G Gigabyte M Megabyte K Kilobyte
the unit that would result in printing the smallest whole number is always chosen
func DiffIntSlices ¶
DiffIntSlices subtracts second slice from first one
func Enter ¶
func Enter(s string) func()
Enter traces function call and caller depth Usage: defer(Enter("..."))() http://stackoverflow.com/questions/25927660/golang-get-current-scope-of-function-name
func Enter2 ¶
Enter2 traces function call and caller depth and measures function duration Usage: defer tw.Enter2(fmt.Sprintf(""))(time.Now()) http://stackoverflow.com/questions/25927660/golang-get-current-scope-of-function-name
func GetFunctionData ¶
GetFunctionData returns the name of the calling function, the file, linennr and ok
func GetKeys ¶
func GetKeys(m map[interface{}]interface{}) []interface{}
// Maps {{{ GetKeys returns a slice of map keys
func HandleExit ¶
func HandleExit()
exit code handler. Usage: defer HandleExit() Recover is only useful inside deferred functions. During normal execution, a call to recover will return nil and have no other effect. If the current goroutine is panicking, a call to recover will capture the value given to panic and resume normal execution. this results in unwinding the stack, so any defered after HandleExit will execute
func IntersectIntSlices ¶
IntersectIntSlices returns the common elements
func IsStrInSlice ¶
func RandStringBytes ¶
func Slice ¶
func Slice(args ...interface{}) []interface{}
// Slices {{{ Slice returns a slice of variadic input. Can be used as: fmt.Printf("%v\n",Slice(ab())[1])
func TimeTrack ¶
TimeTrack measures execution time of function must be invoked with defer to measure block time
func ToMegabytes ¶
ToMegabyte parses a string formatted by ByteSize as megabytes
Types ¶
type LogClassMap ¶
type LogLevelT ¶
type LogLevelT int
var ( // log.Valuer: extends log.Timestamp TimestampUTC log.Valuer = func() interface{} { return time.Now().UTC().Format(time.RFC3339Nano) } // Global Variable defines the LogLevel LogLevel LogLevelT = TraceLevel )
type LoggerDecorator ¶
func Fmt ¶
func Fmt(flag int, skip int) LoggerDecorator
Fmt is decorator for log.Logger, flag determines the verbosity, skip is the number of stack frames to ascend (For tw.MyLevels use 4, otherwise 3).
type LoggerFunc ¶
type LoggerFunc func(keyvals ...interface{}) error
// LoggerDecorator {{{
func (LoggerFunc) Log ¶
func (f LoggerFunc) Log(keyvals ...interface{}) error
type MyLevels ¶
MyLevels extends levels.Levels
func NewMyLevels ¶
func NewMyLevels(flag int, skip int, t LoggerFmtType) MyLevels
TODO: check return value or pointer struct NewMyLevels returns MyLevels logger with skip caller depth
type TWLog ¶
type TWLog struct { sync.RWMutex LogClassMap // contains filtered or unexported fields }
func NewTWLog ¶
func NewTWLog(m LogClassMap) *TWLog