Documentation ¶
Index ¶
- Constants
- Variables
- func CloseEnuf(a, b float64) bool
- func CloseInt(a, b int) bool
- func CoerceFloat(v interface{}) (float64, error)
- func CoerceFloatShort(v interface{}) float64
- func CoerceFloats(v interface{}) []float64
- func CoerceInt(v interface{}) (int, error)
- func CoerceInt64(v interface{}) (int64, error)
- func CoerceInt64Short(v interface{}) int64
- func CoerceIntShort(v interface{}) int
- func CoerceInts(v interface{}) []int
- func CoerceString(v interface{}) (string, error)
- func CoerceStringShort(v interface{}) string
- func CoerceStrings(v interface{}) []string
- func CoerceUint(v interface{}) (uint64, error)
- func CoerceUintShort(v interface{}) uint64
- func Debug(v ...interface{})
- func DebugCtx(ctx context.Context, format string, v ...interface{})
- func DebugT(lineCt int)
- func Debugf(format string, v ...interface{})
- func DeleteJson(url, body string) (ret string, err error, resp *http.Response)
- func DiscardStandardLogger()
- func DoLog(depth, logLvl int, msg string)
- func DoLogFields(depth, logLvl int, msg string, fields map[string]interface{})
- func Error(v ...interface{})
- func ErrorCtx(ctx context.Context, format string, v ...interface{})
- func Errorf(format string, v ...interface{})
- func EscapeNewlines(str string) string
- func Fetch(url string) (ret []byte, err error)
- func FetchResp(url string) (ret []byte, err error, resp *http.Response)
- func FromContext(ctx context.Context) string
- func GetErrLogger() *log.Logger
- func GetLogger() *log.Logger
- func Info(v ...interface{})
- func InfoCtx(ctx context.Context, format string, v ...interface{})
- func InfoT(lineCt int)
- func Infof(format string, v ...interface{})
- func IsJson(by []byte) bool
- func IsJsonArray(by []byte) bool
- func IsJsonObject(by []byte) bool
- func IsTerminal() bool
- func JsonString(v interface{}) string
- func Log(logLvl int, v ...interface{})
- func LogCtx(ctx context.Context, depth, logLvl int, format string, v ...interface{})
- func LogD(depth int, logLvl int, v ...interface{})
- func LogErrorf(format string, v ...interface{}) error
- func LogFieldsf(logLvl int, fields map[string]interface{}, format string, v ...interface{})
- func LogLevelSet(levelWord string)
- func LogP(logLvl int, prefix string, v ...interface{})
- func LogPf(logLvl int, prefix string, format string, v ...interface{})
- func LogThrottle(logLvl, limit int, format string, v ...interface{})
- func LogThrottleCtx(ctx context.Context, logLvl, limit int, format string, v ...interface{})
- func LogThrottleD(depth, logLvl, limit int, format string, v ...interface{})
- func LogThrottleKey(logLvl, limit int, key, format string, v ...interface{})
- func LogThrottleKeyCtx(ctx context.Context, logLvl, limit int, key, format string, v ...interface{})
- func LogTraceDf(logLvl, lineCt int, format string, v ...interface{})
- func LogTracef(logLvl int, format string, v ...interface{})
- func Logf(logLvl int, format string, v ...interface{})
- func MakeJsonList(b []byte) []byte
- func NewContext(ctx context.Context, msg string) context.Context
- func NewContextWrap(ctx context.Context, msg string) context.Context
- func NewUid() uint64
- func PostForm(url, body string) (ret string, err error, resp *http.Response)
- func PostJson(postUrl string, data interface{}) (ret string, err error, resp *http.Response)
- func PrettyStack(lineCt int) string
- func PutJson(url, body string) (ret string, err error, resp *http.Response)
- func SetColorIfTerminal()
- func SetColorOutput()
- func SetCustomLogger(cl LoggerCustom)
- func SetErrLogger(l *log.Logger, logLevel string)
- func SetEscapeNewlines(en bool)
- func SetLogger(l *log.Logger, logLevel string)
- func SetStopper(f func())
- func SetupLogging(lvl string)
- func SetupLoggingFile(f *os.File, lvl string)
- func SetupLoggingLong(lvl string)
- func StartTest()
- func StopCheck()
- func WaitFor(check func() bool, timeoutSecs int)
- func Warn(v ...interface{})
- func WarnCtx(ctx context.Context, format string, v ...interface{})
- func WarnT(lineCt int)
- func Warnf(format string, v ...interface{})
- type DevNull
- type JsonHelper
- func JsonHelperHttp(method, urlStr string, data interface{}) (JsonHelper, error)
- func NewJsonHelper(b []byte) JsonHelper
- func NewJsonHelperFromResp(resp *http.Response) (JsonHelper, error)
- func NewJsonHelperMapString(m map[string]string) JsonHelper
- func NewJsonHelperReader(r io.Reader) (jh JsonHelper, err error)
- func NewJsonHelpers(b []byte) []JsonHelper
- func (j JsonHelper) Bool(n string) bool
- func (j JsonHelper) BoolSafe(n string) (val bool, ok bool)
- func (j *JsonHelper) DecodeSpanner(val interface{}) (err error)
- func (j JsonHelper) EncodeSpanner() (interface{}, error)
- func (j JsonHelper) Float64(n string) float64
- func (j JsonHelper) Float64Safe(n string) (float64, bool)
- func (j JsonHelper) Get(n string) interface{}
- func (j *JsonHelper) GobDecode(data []byte) error
- func (j *JsonHelper) GobEncode() ([]byte, error)
- func (j JsonHelper) HasKey(name string) bool
- func (j JsonHelper) Helper(n string) JsonHelper
- func (j JsonHelper) HelperSafe(n string) (JsonHelper, bool)
- func (j JsonHelper) Helpers(n string) []JsonHelper
- func (j JsonHelper) Int(n string) int
- func (j JsonHelper) Int64(n string) int64
- func (j JsonHelper) Int64Safe(n string) (int64, bool)
- func (j JsonHelper) IntSafe(n string) (int, bool)
- func (j JsonHelper) Ints(n string) []int
- func (j JsonHelper) Keys() []string
- func (j JsonHelper) List(n string) []interface{}
- func (j JsonHelper) Map(n string) map[string]interface{}
- func (j JsonHelper) MapSafe(n string) (map[string]interface{}, bool)
- func (j JsonHelper) PrettyJson() []byte
- func (j JsonHelper) String(n string) string
- func (j JsonHelper) StringSafe(n string) (string, bool)
- func (j JsonHelper) Strings(n string) []string
- func (j JsonHelper) Uint64(n string) uint64
- func (j JsonHelper) Uint64Safe(n string) (uint64, bool)
- type JsonRawWriter
- type LoggerCustom
- type Throttler
- type Uid
Constants ¶
const ( MaxInt = 1<<(BitsPerWord-1) - 1 // either 1<<31 - 1 or 1<<63 - 1 MinInt = -MaxInt - 1 // either -1 << 31 or -1 << 63 MaxUint = 1<<BitsPerWord - 1 // either 1<<32 - 1 or 1<<64 - 1 )
Implementation-specific integer limit values.
const ( NOLOGGING = -1 FATAL = 0 ERROR = 1 WARN = 2 INFO = 3 DEBUG = 4 )
const BitsPerWord = bitsPerWord // either 32 or 64
Implementation-specific size of int and uint in bits.
Variables ¶
var ( LogLevel int = ERROR EMPTY struct{} ErrLogLevel int = ERROR LogColor = map[int]string{FATAL: "\033[0m\033[37m", ERROR: "\033[0m\033[31m", WARN: "\033[0m\033[33m", INFO: "\033[0m\033[35m", DEBUG: "\033[0m\033[34m"} LogPrefix = map[int]string{ FATAL: "[FATAL] ", ERROR: "[ERROR] ", WARN: "[WARN] ", INFO: "[INFO] ", DEBUG: "[DEBUG] ", } LogLevelWords map[string]int = map[string]int{"fatal": 0, "error": 1, "warn": 2, "info": 3, "debug": 4, "none": -1} )
Functions ¶
func CoerceFloat ¶
func CoerceFloatShort ¶
func CoerceFloatShort(v interface{}) float64
func CoerceFloats ¶
func CoerceFloats(v interface{}) []float64
func CoerceInt64 ¶
func CoerceInt64Short ¶
func CoerceInt64Short(v interface{}) int64
func CoerceIntShort ¶
func CoerceIntShort(v interface{}) int
func CoerceInts ¶
func CoerceInts(v interface{}) []int
func CoerceString ¶
Coerce types (string,int,int64, float, []byte) into String type
func CoerceStringShort ¶
func CoerceStringShort(v interface{}) string
Coerce type to string, returning zero length string if error or nil
func CoerceStrings ¶
func CoerceStrings(v interface{}) []string
CoerceStrings Coerce type to strings, will split on comma by default.
func CoerceUint ¶
Coerce a val(interface{}) into a Uint64
func CoerceUintShort ¶
func CoerceUintShort(v interface{}) uint64
Coerce a Val(interface{}) into Uint64
func DeleteJson ¶
issues http delete an application/json to url with body
func DiscardStandardLogger ¶
func DiscardStandardLogger()
Setup default log output to go to a dev/null
log.SetOutput(new(DevNull))
func DoLogFields ¶
DoLogFields allows the inclusion of additional context for logrus logs file and line number are included in the fields by default
func EscapeNewlines ¶
Replace standard newline characters with escaped newlines so long msgs will remain one line.
func FromContext ¶
FromContext extracts the Log Context prefix from context
func GetErrLogger ¶
func IsJson ¶
Determines if the bytes is a json array, only looks at prefix
not parsing the entire thing
func IsJsonArray ¶
Determines if the bytes is a json array, only looks at prefix
not parsing the entire thing
func IsJsonObject ¶
func JsonString ¶
func JsonString(v interface{}) string
func LogD ¶
When you want to use the log short filename flag, and want to use the lower level logging functions (say from an *Assert* type function) you need to modify the stack depth:
func init() {} SetLogger(log.New(os.Stderr, "", log.Ltime|log.Lshortfile|log.Lmicroseconds), lvl) } func assert(t *testing.T, myData) { // we want log line to show line that called this assert, not this line LogD(5, DEBUG, v...) }
func LogFieldsf ¶
func LogPf ¶
Log to logger if setup with a prefix
LogPf(ERROR, "prefix", "formatString %s %v", anyItems, youWant)
func LogThrottle ¶
LogThrottleD logging based on @format as a key, such that key would never occur more than @limit times per hour
LogThrottle(u.ERROR, 1, "message %s", varx)
func LogThrottleCtx ¶
LogThrottleCtx log formatted context writer, limits to @limit/hour.
func LogThrottleD ¶
LogThrottleD Throttle logging based on @format as a key, such that key would never occur more than @limit times per hour
LogThrottleD(5, u.ERROR, 1, "message %s", varx)
func LogThrottleKey ¶
Throttle logging based on key, such that key would never occur more than @limit times per hour
LogThrottleKey(u.ERROR, 1,"error_that_happens_a_lot" "message %s", varx)
func LogThrottleKeyCtx ¶
func LogThrottleKeyCtx(ctx context.Context, logLvl, limit int, key, format string, v ...interface{})
LogThrottleKeyCtx log formatted context writer
func LogTraceDf ¶
Log to logger if setup, grab a stack trace and add that as well
u.LogTracef(u.ERROR, "message %s", varx)
func LogTracef ¶
Log to logger if setup, grab a stack trace and add that as well
u.LogTracef(u.ERROR, "message %s", varx)
func NewContext ¶
NewContext returns a new Context carrying contextual log message that gets prefixed to log statements.
func NewContextWrap ¶
NewContextWrap returns a new Context carrying contextual log message that gets prefixed to log statements.
func PrettyStack ¶
PrettyStack is a helper to pull stack-trace, prettify it.
func SetCustomLogger ¶
func SetCustomLogger(cl LoggerCustom)
SetCustomLogger sets the logger to a custom logger
func SetErrLogger ¶
you can set a logger, and log level. this is for errors, and assumes you are logging to Stderr (seperate from stdout above), allowing you to seperate debug&info logging from errors
gou.SetLogger(log.New(os.Stderr, "", log.LstdFlags), "debug") loglevls: debug, info, warn, error, fatal
func SetEscapeNewlines ¶
func SetEscapeNewlines(en bool)
Set whether to escape newline characters in log messages
func SetLogger ¶
you can set a logger, and log level,most common usage is:
gou.SetLogger(log.New(os.Stdout, "", log.LstdFlags), "debug") loglevls: debug, info, warn, error, fatal
Note, that you can also set a separate Error Log Level
func SetStopper ¶
func SetStopper(f func())
Use this in combo with StopCheck() for test functions that must start processes such as
func SetupLogging ¶
func SetupLogging(lvl string)
Setup default logging to Stderr, equivalent to:
gou.SetLogger(log.New(os.Stderr, "", log.Ltime|log.Lshortfile), "debug")
func SetupLoggingFile ¶
SetupLoggingFile writes logs to the file object parameter.
func SetupLoggingLong ¶
func SetupLoggingLong(lvl string)
Setup default logging to Stderr, equivalent to:
gou.SetLogger(log.New(os.Stderr, "", log.LstdFlags|log.Lshortfile|log.Lmicroseconds), level)
func WaitFor ¶
Wait for condition (defined by func) to be true this is mostly for testing, but a utility to create a ticker checking back every 100 ms to see if something (the supplied check func) is done
WaitFor(func() bool { return ctr.Ct == 0 },10)
timeout (in seconds) is the last arg
Types ¶
type DevNull ¶
type DevNull struct{}
http://play.golang.org/p/5LIA41Iqfp Dummy discard, satisfies io.Writer without importing io or os.
type JsonHelper ¶
type JsonHelper map[string]interface{}
A wrapper around a map[string]interface{} to facilitate coercion of json data to what you want
allows usage such as this
jh := NewJsonHelper([]byte(`{ "name":"string", "ints":[1,5,9,11], "int":1, "int64":1234567890, "MaxSize" : 1048576, "strings":["string1"], "nested":{ "nest":"string2", "strings":["string1"], "int":2, "list":["value"], "nest2":{ "test":"good" } }, "nested2":[ {"sub":5} ] }`) i := jh.Int("nested.int") // 2 i2 := jh.Int("ints[1]") // 5 array position 1 from [1,5,9,11] s := jh.String("nested.nest") // "string2"
func JsonHelperHttp ¶
func JsonHelperHttp(method, urlStr string, data interface{}) (JsonHelper, error)
Simple Fetch Wrapper, given a url it returns Helper, error Sends as type application/json, interprets whatever datatype is sent in appropriately
func NewJsonHelper ¶
func NewJsonHelper(b []byte) JsonHelper
func NewJsonHelperFromResp ¶
func NewJsonHelperFromResp(resp *http.Response) (JsonHelper, error)
Make a JsonHelper from http response. This will automatically close the response body
func NewJsonHelperMapString ¶
func NewJsonHelperMapString(m map[string]string) JsonHelper
func NewJsonHelperReader ¶
func NewJsonHelperReader(r io.Reader) (jh JsonHelper, err error)
func NewJsonHelpers ¶
func NewJsonHelpers(b []byte) []JsonHelper
func (JsonHelper) Bool ¶
func (j JsonHelper) Bool(n string) bool
func (*JsonHelper) DecodeSpanner ¶ added in v1.0.3
func (j *JsonHelper) DecodeSpanner(val interface{}) (err error)
func (JsonHelper) EncodeSpanner ¶ added in v1.0.3
func (j JsonHelper) EncodeSpanner() (interface{}, error)
func (JsonHelper) Float64 ¶
func (j JsonHelper) Float64(n string) float64
func (JsonHelper) Float64Safe ¶
func (j JsonHelper) Float64Safe(n string) (float64, bool)
func (JsonHelper) Get ¶
func (j JsonHelper) Get(n string) interface{}
Get the key (or keypath) value as interface, mostly used internally through String, etc methods
jh.Get("name.subname") jh.Get("name/subname") jh.Get("name.arrayname[1]") jh.Get("name.arrayname[]")
func (*JsonHelper) GobDecode ¶
func (j *JsonHelper) GobDecode(data []byte) error
GobDecode overwrites the receiver, which must be a pointer, with the value represented by the byte slice, which was written by GobEncode, usually for the same concrete type. GobDecode([]byte) error
func (*JsonHelper) GobEncode ¶
func (j *JsonHelper) GobEncode() ([]byte, error)
func (JsonHelper) HasKey ¶
func (j JsonHelper) HasKey(name string) bool
func (JsonHelper) Helper ¶
func (j JsonHelper) Helper(n string) JsonHelper
func (JsonHelper) HelperSafe ¶ added in v1.0.3
func (j JsonHelper) HelperSafe(n string) (JsonHelper, bool)
Get a Helper from a string path
func (JsonHelper) Helpers ¶
func (j JsonHelper) Helpers(n string) []JsonHelper
Get list of Helpers at given name. Trys to coerce into proper Helper type
func (JsonHelper) Int ¶
func (j JsonHelper) Int(n string) int
func (JsonHelper) Int64 ¶
func (j JsonHelper) Int64(n string) int64
func (JsonHelper) Ints ¶
func (j JsonHelper) Ints(n string) []int
func (JsonHelper) Keys ¶
func (j JsonHelper) Keys() []string
func (JsonHelper) Map ¶
func (j JsonHelper) Map(n string) map[string]interface{}
func (JsonHelper) PrettyJson ¶
func (j JsonHelper) PrettyJson() []byte
func (JsonHelper) String ¶
func (j JsonHelper) String(n string) string
func (JsonHelper) StringSafe ¶
func (j JsonHelper) StringSafe(n string) (string, bool)
func (JsonHelper) Strings ¶
func (j JsonHelper) Strings(n string) []string
func (JsonHelper) Uint64 ¶
func (j JsonHelper) Uint64(n string) uint64
func (JsonHelper) Uint64Safe ¶
func (j JsonHelper) Uint64Safe(n string) (uint64, bool)
type JsonRawWriter ¶
func (*JsonRawWriter) MarshalJSON ¶
func (m *JsonRawWriter) MarshalJSON() ([]byte, error)
func (*JsonRawWriter) Raw ¶
func (m *JsonRawWriter) Raw() json.RawMessage
type LoggerCustom ¶
LoggerCustom defines custom interface for logger implementation
func GetCustomLogger ¶
func GetCustomLogger() LoggerCustom
GetCustomLogger returns the custom logger if initialized
type Throttler ¶
type Throttler struct {
// contains filtered or unexported fields
}
func NewThrottler ¶
new Throttler that will tell you to limit or not based on given @max events @per duration
func (*Throttler) Throttle ¶
Should we limit this because we are above rate? Returns a bool of whether to throttle the message, and a count of previous log messages throttled since last log message.
func (*Throttler) ThrottleAdd ¶
Should we limit this because we are above rate? Returns a bool of whether to throttle the message, and a count of previous log messages throttled since last log message.