tw

package module
v0.0.0-...-9a75a9d Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2016 License: GPL-3.0 Imports: 19 Imported by: 0

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

View Source
const (
	BYTE     = 1.0
	KILOBYTE = 1024 * BYTE
	MEGABYTE = 1024 * KILOBYTE
	GIGABYTE = 1024 * MEGABYTE
	TERABYTE = 1024 * GIGABYTE
)
View Source
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 {{{

View Source
const (
	LOG_NULL   int = 0
	LOG_FILE   int = 1
	LOG_CALLER     = 1 << iota
	LOG_FULL
)
View Source
const MAXDEPTH int = 20

// Enter {{{

Variables

View Source
var (
	Debug = l.Debug
	Info  = l.Info
	Warn  = l.Warn
	Error = l.Error
	Crit  = l.Crit
)

Definiton of global package logger

Functions

func ByteSize

func ByteSize(bytes uint64) string

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 Cls

func Cls()

Cls: Clear screen on windows

func Decorate

func Decorate(l log.Logger, ds ...LoggerDecorator) log.Logger

func DiffIntSlices

func DiffIntSlices(X, Y []int) []int

DiffIntSlices subtracts second slice from first one

func Dump

func Dump(data interface{}) string

dump data in debugging: returns string

func E

func E(format string, v ...interface{}) error

returns IError formated string

func End

func End(start time.Time)

End writes the end message to STDOUT must be invoked with defer to measure block time

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

func Enter2(s string) func(t time.Time)

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 EnterFunc

func EnterFunc(ml MyLevels) func(string) func()

EnterFunc requires stackframe 5 on NewMyLevels

func Exists

func Exists(name string) bool

// Directory/File {{{ Exists tests whether the named file or directory exists.

func First

func First(args ...interface{}) interface{}

func GetFN

func GetFN() string

GetFN gets the name of the calling function

func GetFunctionData

func GetFunctionData(i int) (string, string, int, bool)

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

func IntersectIntSlices(X, Y []int) []int

IntersectIntSlices returns the common elements

func IsDir

func IsDir(path string) (bool, error)

IsDir tests whether file is a directory

func IsStrInSlice

func IsStrInSlice(a string, list []string) bool

func Min

func Min(x int, ys ...int) int

Min returns the minimum

func RandStringBytes

func RandStringBytes(n int) string

func Rint

func Rint(num float64) int

Rint rounds to next integer

func Second

func Second(args ...interface{}) interface{}

func Shuffle

func Shuffle(src []interface{}) []interface{}

Shuffle permutates a slice randomly

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

func TimeTrack(start time.Time) time.Duration

TimeTrack measures execution time of function must be invoked with defer to measure block time

func ToBytes

func ToBytes(s string) (uint64, error)

ToByte parses a string formatted by ByteSize

func ToFixed

func ToFixed(num float64, precision int) float64

ToFixed rounds to fixed decimal precision

func ToMegabytes

func ToMegabytes(s string) (uint64, error)

ToMegabyte parses a string formatted by ByteSize as megabytes

Types

type DedupT

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

type Exit

type Exit struct{ Code int }

in main: panic(tw.Exit{3}) // 3 is the exit code

type Frame

type Frame struct {
	File string
	Line int
	Name string
}

facebookgo/stack

func GetFN2

func GetFN2() Frame

type LogClass

type LogClass int

type LogClassMap

type LogClassMap map[LogClass]bool

type LogLevelT

type LogLevelT int
const (
	UndefLevel LogLevelT = iota
	TraceLevel
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	CriticalLevel
)
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

type LoggerDecorator func(log.Logger) log.Logger

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 LoggerFmtType

type LoggerFmtType int
const (
	JSON LoggerFmtType = iota
	FMT
)

type LoggerFunc

type LoggerFunc func(keyvals ...interface{}) error

// LoggerDecorator {{{

func (LoggerFunc) Log

func (f LoggerFunc) Log(keyvals ...interface{}) error

type MyLevels

type MyLevels struct {
	L levels.Levels
}

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

func (MyLevels) Crit

func (ml MyLevels) Crit(keyvals ...interface{})

func (MyLevels) Debug

func (ml MyLevels) Debug(keyvals ...interface{})

func (MyLevels) Error

func (ml MyLevels) Error(keyvals ...interface{})

func (MyLevels) Info

func (ml MyLevels) Info(keyvals ...interface{})

func (MyLevels) Trace

func (ml MyLevels) Trace(keyvals ...interface{})

func (MyLevels) Warn

func (ml MyLevels) Warn(keyvals ...interface{})

type TWLog

type TWLog struct {
	sync.RWMutex
	LogClassMap
	// contains filtered or unexported fields
}

func NewTWLog

func NewTWLog(m LogClassMap) *TWLog

func (*TWLog) GetColor

func (l *TWLog) GetColor(lgc LogClass) COLOR

func (*TWLog) IsSet

func (l *TWLog) IsSet(lgc LogClass) bool

func (*TWLog) L

func (l *TWLog) L(lgc LogClass, c COLOR, v ...interface{})

func (*TWLog) LC

func (l *TWLog) LC(lgc LogClass, v ...interface{})

L {{{

func (*TWLog) LL

func (l *TWLog) LL(lgc LogClass, c COLOR, ss ...interface{})

func (*TWLog) LLC

func (l *TWLog) LLC(lgc LogClass, ss ...interface{})

func (*TWLog) Set

func (l *TWLog) Set(lgc LogClass)

func (*TWLog) SetColor

func (l *TWLog) SetColor(lgc LogClass, c COLOR)

func (*TWLog) SetDedup

func (l *TWLog) SetDedup(lgc LogClass)

func (*TWLog) Unset

func (l *TWLog) Unset(lgc LogClass)

func (*TWLog) UnsetDedup

func (l *TWLog) UnsetDedup(lgc LogClass)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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