diff --git a/go.mod b/go.mod index 76ba846..ecc3d21 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,11 @@ module source.hodakov.me/fat0troll/fwzookeeper_helper require ( - github.com/Arman92/go-tdlib v0.0.0-20181103144727-9577ff528640 - github.com/rs/zerolog v1.11.0 + github.com/Arman92/go-tdlib v0.0.0-20191002071913-526f4e1d15f7 + github.com/kr/pretty v0.1.0 // indirect + github.com/rs/zerolog v1.15.0 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect - gopkg.in/yaml.v2 v2.2.2 + gopkg.in/yaml.v2 v2.2.4 ) go 1.13 diff --git a/go.sum b/go.sum index e35cc49..d8baf99 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,31 @@ github.com/Arman92/go-tdlib v0.0.0-20181103144727-9577ff528640 h1:Esv4AF+AVSwjJJFGVLVBncKgq4z7nikN6TK4X7mj2Vg= github.com/Arman92/go-tdlib v0.0.0-20181103144727-9577ff528640/go.mod h1:ZzkRfuaFj8etIYMj/ECtXtgfz72RE6U+dos27b3XIwk= +github.com/Arman92/go-tdlib v0.0.0-20191002071913-526f4e1d15f7 h1:GbV1Lv3lVHsSeKAqPTBem72OCsGjXntW4jfJdXciE+w= +github.com/Arman92/go-tdlib v0.0.0-20191002071913-526f4e1d15f7/go.mod h1:ZzkRfuaFj8etIYMj/ECtXtgfz72RE6U+dos27b3XIwk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.11.0 h1:DRuq/S+4k52uJzBQciUcofXx45GrMC6yrEbb/CoK6+M= github.com/rs/zerolog v1.11.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= +github.com/rs/zerolog v1.15.0 h1:uPRuwkWF4J6fGsJ2R0Gn2jB1EQiav9k3S6CSdygQJXY= +github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= +github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/vendor/github.com/Arman92/go-tdlib/tdlib.go b/vendor/github.com/Arman92/go-tdlib/tdlib.go index 785372a..2ef4efa 100644 --- a/vendor/github.com/Arman92/go-tdlib/tdlib.go +++ b/vendor/github.com/Arman92/go-tdlib/tdlib.go @@ -211,16 +211,31 @@ func (client *Client) Execute(jsonQuery interface{}) UpdateMsg { // By default TDLib writes logs to stderr or an OS specific log. // Use this method to write the log to a file instead. func SetFilePath(path string) { - query := C.CString(path) - defer C.free(unsafe.Pointer(query)) + bytes, _ := json.Marshal(UpdateData{ + "@type": "setLogStream", + "log_stream": UpdateData{ + "@type": "logStreamFile", + "path": path, + "max_file_size": 10485760, + }, + }) - C.td_set_log_file_path(query) + query := C.CString(string(bytes)) + C.td_json_client_execute(nil, query) + C.free(unsafe.Pointer(query)) } // SetLogVerbosityLevel Sets the verbosity level of the internal logging of TDLib. // By default the TDLib uses a verbosity level of 5 for logging. func SetLogVerbosityLevel(level int) { - C.td_set_log_verbosity_level(C.int(level)) + bytes, _ := json.Marshal(UpdateData{ + "@type": "setLogVerbosityLevel", + "new_verbosity_level": level, + }) + + query := C.CString(string(bytes)) + C.td_json_client_execute(nil, query) + C.free(unsafe.Pointer(query)) } // SendAndCatch Sends request to the TDLib client and catches the result in updates channel. diff --git a/vendor/github.com/Arman92/go-tdlib/types.go b/vendor/github.com/Arman92/go-tdlib/types.go index 6c32bdb..ee2f551 100644 --- a/vendor/github.com/Arman92/go-tdlib/types.go +++ b/vendor/github.com/Arman92/go-tdlib/types.go @@ -438,7 +438,7 @@ const ( TextEntityTypeCodeType TextEntityTypeEnum = "textEntityTypeCode" TextEntityTypePreType TextEntityTypeEnum = "textEntityTypePre" TextEntityTypePreCodeType TextEntityTypeEnum = "textEntityTypePreCode" - TextEntityTypeTextURLType TextEntityTypeEnum = "textEntityTypeTextURL" + TextEntityTypeTextURLType TextEntityTypeEnum = "textEntityTypeTextUrl" TextEntityTypeMentionNameType TextEntityTypeEnum = "textEntityTypeMentionName" TextEntityTypePhoneNumberType TextEntityTypeEnum = "textEntityTypePhoneNumber" ) diff --git a/vendor/github.com/rs/zerolog/.travis.yml b/vendor/github.com/rs/zerolog/.travis.yml index 64d202a..70b67c9 100644 --- a/vendor/github.com/rs/zerolog/.travis.yml +++ b/vendor/github.com/rs/zerolog/.travis.yml @@ -4,6 +4,8 @@ go: - "1.8" - "1.9" - "1.10" +- "1.11" +- "1.12" - "master" matrix: allow_failures: diff --git a/vendor/github.com/rs/zerolog/README.md b/vendor/github.com/rs/zerolog/README.md index eefc1f6..f7ff10f 100644 --- a/vendor/github.com/rs/zerolog/README.md +++ b/vendor/github.com/rs/zerolog/README.md @@ -53,7 +53,7 @@ func main() { // UNIX Time is faster and smaller than most timestamps // If you set zerolog.TimeFieldFormat to an empty string, // logs will write with UNIX time - zerolog.TimeFieldFormat = "" + zerolog.TimeFieldFormat = zerolog.TimeFormatUnix log.Print("hello world") } @@ -76,15 +76,20 @@ import ( ) func main() { - zerolog.TimeFieldFormat = "" + zerolog.TimeFieldFormat = zerolog.TimeFormatUnix log.Debug(). Str("Scale", "833 cents"). Float64("Interval", 833.09). Msg("Fibonacci is everywhere") + + log.Debug(). + Str("Name", "Tom"). + Send() } -// Output: {"time":1524104936,"level":"debug","Scale":"833 cents","Interval":833.09,"message":"Fibonacci is everywhere"} +// Output: {"level":"debug","Scale":"833 cents","Interval":833.09,"time":1562212768,"message":"Fibonacci is everywhere"} +// Output: {"level":"debug","Name":"Tom","time":1562212768} ``` > You'll note in the above example that when adding contextual fields, the fields are strongly typed. You can find the full list of supported fields [here](#standard-types) @@ -102,7 +107,7 @@ import ( ) func main() { - zerolog.TimeFieldFormat = "" + zerolog.TimeFieldFormat = zerolog.TimeFormatUnix log.Info().Msg("hello world") } @@ -138,7 +143,7 @@ import ( ) func main() { - zerolog.TimeFieldFormat = "" + zerolog.TimeFieldFormat = zerolog.TimeFormatUnix debug := flag.Bool("debug", false, "sets log level to debug") flag.Parse() @@ -189,7 +194,7 @@ import ( ) func main() { - zerolog.TimeFieldFormat = "" + zerolog.TimeFieldFormat = zerolog.TimeFormatUnix log.Log(). Str("foo", "bar"). @@ -215,7 +220,7 @@ func main() { err := errors.New("A repo man spends his life getting into tense situations") service := "myservice" - zerolog.TimeFieldFormat = "" + zerolog.TimeFieldFormat = zerolog.TimeFormatUnix log.Fatal(). Err(err). @@ -474,9 +479,8 @@ Some settings can be changed and will by applied to all loggers: * `zerolog.LevelFieldName`: Can be set to customize level field name. * `zerolog.MessageFieldName`: Can be set to customize message field name. * `zerolog.ErrorFieldName`: Can be set to customize `Err` field name. -* `zerolog.TimeFieldFormat`: Can be set to customize `Time` field value formatting. If set with an empty string, times are formated as UNIX timestamp. - // DurationFieldUnit defines the unit for time.Duration type fields added - // using the Dur method. +* `zerolog.TimeFieldFormat`: Can be set to customize `Time` field value formatting. If set with `zerolog.TimeFormatUnix` or `zerolog.TimeFormatUnixMs`, times are formated as UNIX timestamp. +* DurationFieldUnit defines the unit for time.Duration type fields added using the Dur method. * `DurationFieldUnit`: Sets the unit of the fields added by `Dur` (default: `time.Millisecond`). * `DurationFieldInteger`: If set to true, `Dur` fields are formatted as integers instead of floats. * `ErrorHandler`: Called whenever zerolog fails to write an event on its output. If not set, an error is printed on the stderr. This handler must be thread safe and non-blocking. @@ -578,7 +582,7 @@ Log a static string, without any context or `printf`-style templating: ## Caveats -Note that zerolog does de-duplication fields. Using the same key multiple times creates multiple keys in final JSON: +Note that zerolog does no de-duplication of fields. Using the same key multiple times creates multiple keys in final JSON: ```go logger := zerolog.New(os.Stderr).With().Timestamp().Logger() @@ -588,4 +592,4 @@ logger.Info(). // Output: {"level":"info","time":1494567715,"time":1494567715,"message":"dup"} ``` -However, it’s not a big deal as JSON accepts dup keys; the last one prevails. +In this case, many consumers will take the last value, but this is not guaranteed; check yours if in doubt. diff --git a/vendor/github.com/rs/zerolog/console.go b/vendor/github.com/rs/zerolog/console.go index f25bc32..15bd063 100644 --- a/vendor/github.com/rs/zerolog/console.go +++ b/vendor/github.com/rs/zerolog/console.go @@ -13,11 +13,6 @@ import ( "time" ) -const ( - colorBold = iota + 1 - colorFaint -) - const ( colorBlack = iota + 30 colorRed @@ -27,6 +22,9 @@ const ( colorMagenta colorCyan colorWhite + + colorBold = 1 + colorDarkGray = 90 ) var ( @@ -35,20 +33,10 @@ var ( return bytes.NewBuffer(make([]byte, 0, 100)) }, } +) +const ( consoleDefaultTimeFormat = time.Kitchen - consoleDefaultFormatter = func(i interface{}) string { return fmt.Sprintf("%s", i) } - consoleDefaultPartsOrder = func() []string { - return []string{ - TimestampFieldName, - LevelFieldName, - CallerFieldName, - MessageFieldName, - } - } - - consoleNoColor = false - consoleTimeFormat = consoleDefaultTimeFormat ) // Formatter transforms the input into a formatted string. @@ -99,21 +87,12 @@ func (w ConsoleWriter) Write(p []byte) (n int, err error) { if w.PartsOrder == nil { w.PartsOrder = consoleDefaultPartsOrder() } - if w.TimeFormat == "" && consoleTimeFormat != consoleDefaultTimeFormat { - consoleTimeFormat = consoleDefaultTimeFormat - } - if w.TimeFormat != "" && consoleTimeFormat != w.TimeFormat { - consoleTimeFormat = w.TimeFormat - } - if w.NoColor == false && consoleNoColor != false { - consoleNoColor = false - } - if w.NoColor == true && consoleNoColor != w.NoColor { - consoleNoColor = w.NoColor - } var buf = consoleBufPool.Get().(*bytes.Buffer) - defer consoleBufPool.Put(buf) + defer func() { + buf.Reset() + consoleBufPool.Put(buf) + }() var evt map[string]interface{} p = decodeIfBinaryToBytes(p) @@ -130,9 +109,12 @@ func (w ConsoleWriter) Write(p []byte) (n int, err error) { w.writeFields(evt, buf) - buf.WriteByte('\n') - buf.WriteTo(w.Out) - return len(p), nil + err = buf.WriteByte('\n') + if err != nil { + return n, err + } + _, err = buf.WriteTo(w.Out) + return len(p), err } // writeFields appends formatted key-value pairs to buf. @@ -172,19 +154,19 @@ func (w ConsoleWriter) writeFields(evt map[string]interface{}, buf *bytes.Buffer if field == ErrorFieldName { if w.FormatErrFieldName == nil { - fn = consoleDefaultFormatErrFieldName + fn = consoleDefaultFormatErrFieldName(w.NoColor) } else { fn = w.FormatErrFieldName } if w.FormatErrFieldValue == nil { - fv = consoleDefaultFormatErrFieldValue + fv = consoleDefaultFormatErrFieldValue(w.NoColor) } else { fv = w.FormatErrFieldValue } } else { if w.FormatFieldName == nil { - fn = consoleDefaultFormatFieldName + fn = consoleDefaultFormatFieldName(w.NoColor) } else { fn = w.FormatFieldName } @@ -229,13 +211,13 @@ func (w ConsoleWriter) writePart(buf *bytes.Buffer, evt map[string]interface{}, switch p { case LevelFieldName: if w.FormatLevel == nil { - f = consoleDefaultFormatLevel + f = consoleDefaultFormatLevel(w.NoColor) } else { f = w.FormatLevel } case TimestampFieldName: if w.FormatTimestamp == nil { - f = consoleDefaultFormatTimestamp + f = consoleDefaultFormatTimestamp(w.TimeFormat, w.NoColor) } else { f = w.FormatTimestamp } @@ -247,7 +229,7 @@ func (w ConsoleWriter) writePart(buf *bytes.Buffer, evt map[string]interface{}, } case CallerFieldName: if w.FormatCaller == nil { - f = consoleDefaultFormatCaller + f = consoleDefaultFormatCaller(w.NoColor) } else { f = w.FormatCaller } @@ -289,49 +271,80 @@ func colorize(s interface{}, c int, disabled bool) string { // ----- DEFAULT FORMATTERS --------------------------------------------------- -var ( - consoleDefaultFormatTimestamp = func(i interface{}) string { +func consoleDefaultPartsOrder() []string { + return []string{ + TimestampFieldName, + LevelFieldName, + CallerFieldName, + MessageFieldName, + } +} + +func consoleDefaultFormatTimestamp(timeFormat string, noColor bool) Formatter { + if timeFormat == "" { + timeFormat = consoleDefaultTimeFormat + } + return func(i interface{}) string { t := "" switch tt := i.(type) { case string: - ts, err := time.Parse(time.RFC3339, tt) + ts, err := time.Parse(TimeFieldFormat, tt) if err != nil { t = tt } else { - t = ts.Format(consoleTimeFormat) + t = ts.Format(timeFormat) } case json.Number: - t = tt.String() + i, err := tt.Int64() + if err != nil { + t = tt.String() + } else { + var sec, nsec int64 = i, 0 + if TimeFieldFormat == TimeFormatUnixMs { + nsec = int64(time.Duration(i) * time.Millisecond) + sec = 0 + } + ts := time.Unix(sec, nsec).UTC() + t = ts.Format(timeFormat) + } } - return colorize(t, colorFaint, consoleNoColor) + return colorize(t, colorDarkGray, noColor) } +} - consoleDefaultFormatLevel = func(i interface{}) string { +func consoleDefaultFormatLevel(noColor bool) Formatter { + return func(i interface{}) string { var l string if ll, ok := i.(string); ok { switch ll { case "debug": - l = colorize("DBG", colorYellow, consoleNoColor) + l = colorize("DBG", colorYellow, noColor) case "info": - l = colorize("INF", colorGreen, consoleNoColor) + l = colorize("INF", colorGreen, noColor) case "warn": - l = colorize("WRN", colorRed, consoleNoColor) + l = colorize("WRN", colorRed, noColor) case "error": - l = colorize(colorize("ERR", colorRed, consoleNoColor), colorBold, consoleNoColor) + l = colorize(colorize("ERR", colorRed, noColor), colorBold, noColor) case "fatal": - l = colorize(colorize("FTL", colorRed, consoleNoColor), colorBold, consoleNoColor) + l = colorize(colorize("FTL", colorRed, noColor), colorBold, noColor) case "panic": - l = colorize(colorize("PNC", colorRed, consoleNoColor), colorBold, consoleNoColor) + l = colorize(colorize("PNC", colorRed, noColor), colorBold, noColor) default: - l = colorize("???", colorBold, consoleNoColor) + l = colorize("???", colorBold, noColor) } } else { - l = strings.ToUpper(fmt.Sprintf("%s", i))[0:3] + if i == nil { + l = colorize("???", colorBold, noColor) + } else { + l = strings.ToUpper(fmt.Sprintf("%s", i))[0:3] + } } return l } +} - consoleDefaultFormatCaller = func(i interface{}) string { +func consoleDefaultFormatCaller(noColor bool) Formatter { + return func(i interface{}) string { var c string if cc, ok := i.(string); ok { c = cc @@ -342,28 +355,37 @@ var ( c = strings.TrimPrefix(c, cwd) c = strings.TrimPrefix(c, "/") } - c = colorize(c, colorBold, consoleNoColor) + colorize(" >", colorFaint, consoleNoColor) + c = colorize(c, colorBold, noColor) + colorize(" >", colorCyan, noColor) } return c } +} - consoleDefaultFormatMessage = func(i interface{}) string { - return fmt.Sprintf("%s", i) +func consoleDefaultFormatMessage(i interface{}) string { + if i == nil { + return "" } + return fmt.Sprintf("%s", i) +} - consoleDefaultFormatFieldName = func(i interface{}) string { - return colorize(fmt.Sprintf("%s=", i), colorFaint, consoleNoColor) +func consoleDefaultFormatFieldName(noColor bool) Formatter { + return func(i interface{}) string { + return colorize(fmt.Sprintf("%s=", i), colorCyan, noColor) } +} - consoleDefaultFormatFieldValue = func(i interface{}) string { - return fmt.Sprintf("%s", i) - } +func consoleDefaultFormatFieldValue(i interface{}) string { + return fmt.Sprintf("%s", i) +} - consoleDefaultFormatErrFieldName = func(i interface{}) string { - return colorize(fmt.Sprintf("%s=", i), colorRed, consoleNoColor) +func consoleDefaultFormatErrFieldName(noColor bool) Formatter { + return func(i interface{}) string { + return colorize(fmt.Sprintf("%s=", i), colorRed, noColor) } +} - consoleDefaultFormatErrFieldValue = func(i interface{}) string { - return colorize(fmt.Sprintf("%s", i), colorRed, consoleNoColor) +func consoleDefaultFormatErrFieldValue(noColor bool) Formatter { + return func(i interface{}) string { + return colorize(fmt.Sprintf("%s", i), colorRed, noColor) } -) +} diff --git a/vendor/github.com/rs/zerolog/context.go b/vendor/github.com/rs/zerolog/context.go index b843179..1815a08 100644 --- a/vendor/github.com/rs/zerolog/context.go +++ b/vendor/github.com/rs/zerolog/context.go @@ -2,6 +2,7 @@ package zerolog import ( "io/ioutil" + "math" "net" "time" ) @@ -347,14 +348,31 @@ func (c Context) Interface(key string, i interface{}) Context { return c } -type callerHook struct{} - -func (ch callerHook) Run(e *Event, level Level, msg string) { - // Three extra frames to skip (added by hook infra). - e.caller(CallerSkipFrameCount + 3) +type callerHook struct { + callerSkipFrameCount int } -var ch = callerHook{} +func newCallerHook(skipFrameCount int) callerHook { + return callerHook{callerSkipFrameCount: skipFrameCount} +} + +func (ch callerHook) Run(e *Event, level Level, msg string) { + switch ch.callerSkipFrameCount { + case useGlobalSkipFrameCount: + // Extra frames to skip (added by hook infra). + e.caller(CallerSkipFrameCount + contextCallerSkipFrameCount) + default: + // Extra frames to skip (added by hook infra). + e.caller(ch.callerSkipFrameCount + contextCallerSkipFrameCount) + } +} + +// useGlobalSkipFrameCount acts as a flag to informat callerHook.Run +// to use the global CallerSkipFrameCount. +const useGlobalSkipFrameCount = math.MinInt32 + +// ch is the default caller hook using the global CallerSkipFrameCount. +var ch = newCallerHook(useGlobalSkipFrameCount) // Caller adds the file:line of the caller with the zerolog.CallerFieldName key. func (c Context) Caller() Context { @@ -362,6 +380,28 @@ func (c Context) Caller() Context { return c } +// CallerWithSkipFrameCount adds the file:line of the caller with the zerolog.CallerFieldName key. +// The specified skipFrameCount int will override the global CallerSkipFrameCount for this context's respective logger. +// If set to -1 the global CallerSkipFrameCount will be used. +func (c Context) CallerWithSkipFrameCount(skipFrameCount int) Context { + c.l = c.l.Hook(newCallerHook(skipFrameCount)) + return c +} + +type stackTraceHook struct{} + +func (sh stackTraceHook) Run(e *Event, level Level, msg string) { + e.Stack() +} + +var sh = stackTraceHook{} + +// Stack enables stack trace printing for the error passed to Err(). +func (c Context) Stack() Context { + c.l = c.l.Hook(sh) + return c +} + // IPAddr adds IPv4 or IPv6 Address to the context func (c Context) IPAddr(key string, ip net.IP) Context { c.l.context = enc.AppendIPAddr(enc.AppendKey(c.l.context, key), ip) diff --git a/vendor/github.com/rs/zerolog/event.go b/vendor/github.com/rs/zerolog/event.go index a0e090a..c1c946b 100644 --- a/vendor/github.com/rs/zerolog/event.go +++ b/vendor/github.com/rs/zerolog/event.go @@ -5,7 +5,6 @@ import ( "net" "os" "runtime" - "strconv" "sync" "time" ) @@ -18,11 +17,6 @@ var eventPool = &sync.Pool{ }, } -// ErrorMarshalFunc allows customization of global error marshaling -var ErrorMarshalFunc = func(err error) interface{} { - return err -} - // Event represents a log event. It is instanced by one of the level method of // Logger and finalized by the Msg or Msgf method. type Event struct { @@ -30,6 +24,7 @@ type Event struct { w LevelWriter level Level done func(msg string) + stack bool // enable error stack trace ch []Hook // hooks from context } @@ -110,10 +105,20 @@ func (e *Event) Msg(msg string) { e.msg(msg) } -// Msgf sends the event with formated msg added as the message field if not empty. +// Send is equivalent to calling Msg(""). // -// NOTICE: once this methid is called, the *Event should be disposed. -// Calling Msg twice can have unexpected result. +// NOTICE: once this method is called, the *Event should be disposed. +func (e *Event) Send() { + if e == nil { + return + } + e.msg("") +} + +// Msgf sends the event with formatted msg added as the message field if not empty. +// +// NOTICE: once this method is called, the *Event should be disposed. +// Calling Msgf twice can have unexpected result. func (e *Event) Msgf(format string, v ...interface{}) { if e == nil { return @@ -122,13 +127,8 @@ func (e *Event) Msgf(format string, v ...interface{}) { } func (e *Event) msg(msg string) { - if len(e.ch) > 0 { - e.ch[0].Run(e, e.level, msg) - if len(e.ch) > 1 { - for _, hook := range e.ch[1:] { - hook.Run(e, e.level, msg) - } - } + for _, hook := range e.ch { + hook.Run(e, e.level, msg) } if msg != "" { e.buf = enc.AppendString(enc.AppendKey(e.buf, MessageFieldName), msg) @@ -271,8 +271,10 @@ func (e *Event) RawJSON(key string, b []byte) *Event { // AnErr adds the field key with serialized err to the *Event context. // If err is nil, no field is added. func (e *Event) AnErr(key string, err error) *Event { - marshaled := ErrorMarshalFunc(err) - switch m := marshaled.(type) { + if e == nil { + return e + } + switch m := ErrorMarshalFunc(err).(type) { case nil: return e case LogObjectMarshaler: @@ -292,11 +294,9 @@ func (e *Event) Errs(key string, errs []error) *Event { if e == nil { return e } - arr := Arr() for _, err := range errs { - marshaled := ErrorMarshalFunc(err) - switch m := marshaled.(type) { + switch m := ErrorMarshalFunc(err).(type) { case LogObjectMarshaler: arr = arr.Object(m) case error: @@ -314,10 +314,42 @@ func (e *Event) Errs(key string, errs []error) *Event { // Err adds the field "error" with serialized err to the *Event context. // If err is nil, no field is added. // To customize the key name, change zerolog.ErrorFieldName. +// +// To customize the key name, change zerolog.ErrorFieldName. +// +// If Stack() has been called before and zerolog.ErrorStackMarshaler is defined, +// the err is passed to ErrorStackMarshaler and the result is appended to the +// zerolog.ErrorStackFieldName. func (e *Event) Err(err error) *Event { + if e == nil { + return e + } + if e.stack && ErrorStackMarshaler != nil { + switch m := ErrorStackMarshaler(err).(type) { + case nil: + case LogObjectMarshaler: + e.Object(ErrorStackFieldName, m) + case error: + e.Str(ErrorStackFieldName, m.Error()) + case string: + e.Str(ErrorStackFieldName, m) + default: + e.Interface(ErrorStackFieldName, m) + } + } return e.AnErr(ErrorFieldName, err) } +// Stack enables stack trace printing for the error passed to Err(). +// +// ErrorStackMarshaler must be set for this method to do something. +func (e *Event) Stack() *Event { + if e != nil { + e.stack = true + } + return e +} + // Bool adds the field key with val as a bool to the *Event context. func (e *Event) Bool(key string, b bool) *Event { if e == nil { @@ -645,7 +677,7 @@ func (e *Event) caller(skip int) *Event { if !ok { return e } - e.buf = enc.AppendString(enc.AppendKey(e.buf, CallerFieldName), file+":"+strconv.Itoa(line)) + e.buf = enc.AppendString(enc.AppendKey(e.buf, CallerFieldName), CallerMarshalFunc(file, line)) return e } diff --git a/vendor/github.com/rs/zerolog/globals.go b/vendor/github.com/rs/zerolog/globals.go index 1c66904..c1fa37c 100644 --- a/vendor/github.com/rs/zerolog/globals.go +++ b/vendor/github.com/rs/zerolog/globals.go @@ -1,8 +1,21 @@ package zerolog -import "time" +import ( + "strconv" + "time" +) import "sync/atomic" +const ( + // TimeFormatUnix defines a time format that makes time fields to be + // serialized as Unix timestamp integers. + TimeFormatUnix = "" + + // TimeFormatUnix defines a time format that makes time fields to be + // serialized as Unix timestamp integers in milliseconds. + TimeFormatUnixMs = "UNIXMS" +) + var ( // TimestampFieldName is the field name used for the timestamp field. TimestampFieldName = "time" @@ -10,6 +23,11 @@ var ( // LevelFieldName is the field name used for the level field. LevelFieldName = "level" + // LevelFieldMarshalFunc allows customization of global level field marshaling + LevelFieldMarshalFunc = func(l Level) string { + return l.String() + } + // MessageFieldName is the field name used for the message field. MessageFieldName = "message" @@ -22,9 +40,25 @@ var ( // CallerSkipFrameCount is the number of stack frames to skip to find the caller. CallerSkipFrameCount = 2 - // TimeFieldFormat defines the time format of the Time field type. - // If set to an empty string, the time is formatted as an UNIX timestamp - // as integer. + // CallerMarshalFunc allows customization of global caller marshaling + CallerMarshalFunc = func(file string, line int) string { + return file + ":" + strconv.Itoa(line) + } + + // ErrorStackFieldName is the field name used for error stacks. + ErrorStackFieldName = "stack" + + // ErrorStackMarshaler extract the stack from err if any. + ErrorStackMarshaler func(err error) interface{} + + // ErrorMarshalFunc allows customization of global error marshaling + ErrorMarshalFunc = func(err error) interface{} { + return err + } + + // TimeFieldFormat defines the time format of the Time field type. If set to + // TimeFormatUnix or TimeFormatUnixMs, the time is formatted as an UNIX + // timestamp as integer. TimeFieldFormat = time.RFC3339 // TimestampFunc defines the function called to generate a timestamp. diff --git a/vendor/github.com/rs/zerolog/go.mod b/vendor/github.com/rs/zerolog/go.mod index ed79427..0275fdd 100644 --- a/vendor/github.com/rs/zerolog/go.mod +++ b/vendor/github.com/rs/zerolog/go.mod @@ -1 +1,9 @@ module github.com/rs/zerolog + +require ( + github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e + github.com/pkg/errors v0.8.1 + github.com/rs/xid v1.2.1 + github.com/zenazn/goji v0.9.0 + golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc +) diff --git a/vendor/github.com/rs/zerolog/go112.go b/vendor/github.com/rs/zerolog/go112.go new file mode 100644 index 0000000..e7b5a1b --- /dev/null +++ b/vendor/github.com/rs/zerolog/go112.go @@ -0,0 +1,7 @@ +// +build go1.12 + +package zerolog + +// Since go 1.12, some auto generated init functions are hidden from +// runtime.Caller. +const contextCallerSkipFrameCount = 2 diff --git a/vendor/github.com/rs/zerolog/internal/cbor/types.go b/vendor/github.com/rs/zerolog/internal/cbor/types.go index eb4f697..3d76ea0 100644 --- a/vendor/github.com/rs/zerolog/internal/cbor/types.go +++ b/vendor/github.com/rs/zerolog/internal/cbor/types.go @@ -24,9 +24,9 @@ func (Encoder) AppendEndMarker(dst []byte) []byte { // AppendObjectData takes an object in form of a byte array and appends to dst. func (Encoder) AppendObjectData(dst []byte, o []byte) []byte { - // BeginMarker is present in the dst, which - // should not be copied when appending to existing data. - return append(dst, o[1:]...) + // BeginMarker is present in the dst, which + // should not be copied when appending to existing data. + return append(dst, o[1:]...) } // AppendArrayStart adds markers to indicate the start of an array. diff --git a/vendor/github.com/rs/zerolog/internal/json/time.go b/vendor/github.com/rs/zerolog/internal/json/time.go index 739afff..18dea5e 100644 --- a/vendor/github.com/rs/zerolog/internal/json/time.go +++ b/vendor/github.com/rs/zerolog/internal/json/time.go @@ -5,11 +5,20 @@ import ( "time" ) +const ( + // Import from zerolog/global.go + timeFormatUnix = "" + timeFormatUnixMs = "UNIXMS" +) + // AppendTime formats the input time with the given format // and appends the encoded string to the input byte slice. func (e Encoder) AppendTime(dst []byte, t time.Time, format string) []byte { - if format == "" { + switch format { + case timeFormatUnix: return e.AppendInt64(dst, t.Unix()) + case timeFormatUnixMs: + return e.AppendInt64(dst, t.UnixNano()/1000000) } return append(t.AppendFormat(append(dst, '"'), format), '"') } @@ -17,8 +26,11 @@ func (e Encoder) AppendTime(dst []byte, t time.Time, format string) []byte { // AppendTimes converts the input times with the given format // and appends the encoded string list to the input byte slice. func (Encoder) AppendTimes(dst []byte, vals []time.Time, format string) []byte { - if format == "" { + switch format { + case timeFormatUnix: return appendUnixTimes(dst, vals) + case timeFormatUnixMs: + return appendUnixMsTimes(dst, vals) } if len(vals) == 0 { return append(dst, '[', ']') @@ -49,6 +61,21 @@ func appendUnixTimes(dst []byte, vals []time.Time) []byte { return dst } +func appendUnixMsTimes(dst []byte, vals []time.Time) []byte { + if len(vals) == 0 { + return append(dst, '[', ']') + } + dst = append(dst, '[') + dst = strconv.AppendInt(dst, vals[0].UnixNano()/1000000, 10) + if len(vals) > 1 { + for _, t := range vals[1:] { + dst = strconv.AppendInt(append(dst, ','), t.UnixNano()/1000000, 10) + } + } + dst = append(dst, ']') + return dst +} + // AppendDuration formats the input duration with the given unit & format // and appends the encoded string to the input byte slice. func (e Encoder) AppendDuration(dst []byte, d time.Duration, unit time.Duration, useInt bool) []byte { diff --git a/vendor/github.com/rs/zerolog/internal/json/types.go b/vendor/github.com/rs/zerolog/internal/json/types.go index f343c86..bc8bc09 100644 --- a/vendor/github.com/rs/zerolog/internal/json/types.go +++ b/vendor/github.com/rs/zerolog/internal/json/types.go @@ -373,12 +373,17 @@ func (e Encoder) AppendInterface(dst []byte, i interface{}) []byte { // AppendObjectData takes in an object that is already in a byte array // and adds it to the dst. func (Encoder) AppendObjectData(dst []byte, o []byte) []byte { - // Two conditions we want to put a ',' between existing content and - // new content: - // 1. new content starts with '{' - which shd be dropped OR - // 2. existing content has already other fields + // Three conditions apply here: + // 1. new content starts with '{' - which should be dropped OR + // 2. new content starts with '{' - which should be replaced with ',' + // to separate with existing content OR + // 3. existing content has already other fields if o[0] == '{' { - o[0] = ',' + if len(dst) == 0 { + o = o[1:] + } else { + o[0] = ',' + } } else if len(dst) > 1 { dst = append(dst, ',') } diff --git a/vendor/github.com/rs/zerolog/log.go b/vendor/github.com/rs/zerolog/log.go index 8eb45a8..da64b8a 100644 --- a/vendor/github.com/rs/zerolog/log.go +++ b/vendor/github.com/rs/zerolog/log.go @@ -94,8 +94,8 @@ // Msg("dup") // // Output: {"level":"info","time":1494567715,"time":1494567715,"message":"dup"} // -// However, it’s not a big deal though as JSON accepts dup keys, -// the last one prevails. +// In this case, many consumers will take the last value, +// but this is not guaranteed; check yours if in doubt. package zerolog import ( @@ -152,19 +152,19 @@ func (l Level) String() string { // returns an error if the input string does not match known values. func ParseLevel(levelStr string) (Level, error) { switch levelStr { - case DebugLevel.String(): + case LevelFieldMarshalFunc(DebugLevel): return DebugLevel, nil - case InfoLevel.String(): + case LevelFieldMarshalFunc(InfoLevel): return InfoLevel, nil - case WarnLevel.String(): + case LevelFieldMarshalFunc(WarnLevel): return WarnLevel, nil - case ErrorLevel.String(): + case LevelFieldMarshalFunc(ErrorLevel): return ErrorLevel, nil - case FatalLevel.String(): + case LevelFieldMarshalFunc(FatalLevel): return FatalLevel, nil - case PanicLevel.String(): + case LevelFieldMarshalFunc(PanicLevel): return PanicLevel, nil - case NoLevel.String(): + case LevelFieldMarshalFunc(NoLevel): return NoLevel, nil } return NoLevel, fmt.Errorf("Unknown Level String: '%s', defaulting to NoLevel", levelStr) @@ -251,6 +251,11 @@ func (l Logger) Level(lvl Level) Logger { return l } +// GetLevel returns the current Level of l. +func (l Logger) GetLevel() Level { + return l.level +} + // Sample returns a logger with the s sampler. func (l Logger) Sample(s Sampler) Logger { l.sampler = s @@ -291,6 +296,18 @@ func (l *Logger) Error() *Event { return l.newEvent(ErrorLevel, nil) } +// Err starts a new message with error level with err as a field if not nil or +// with info level if err is nil. +// +// You must call Msg on the returned event in order to send the event. +func (l *Logger) Err(err error) *Event { + if err != nil { + return l.Error().Err(err) + } else { + return l.Info() + } +} + // Fatal starts a new message with fatal level. The os.Exit(1) function // is called by the Msg method, which terminates the program immediately. // @@ -380,7 +397,7 @@ func (l *Logger) newEvent(level Level, done func(string)) *Event { e.done = done e.ch = l.hooks if level != NoLevel { - e.Str(LevelFieldName, level.String()) + e.Str(LevelFieldName, LevelFieldMarshalFunc(level)) } if l.context != nil && len(l.context) > 0 { e.buf = enc.AppendObjectData(e.buf, l.context) diff --git a/vendor/github.com/rs/zerolog/not_go112.go b/vendor/github.com/rs/zerolog/not_go112.go new file mode 100644 index 0000000..4c43c9e --- /dev/null +++ b/vendor/github.com/rs/zerolog/not_go112.go @@ -0,0 +1,5 @@ +// +build !go1.12 + +package zerolog + +const contextCallerSkipFrameCount = 3 diff --git a/vendor/github.com/rs/zerolog/sampler.go b/vendor/github.com/rs/zerolog/sampler.go index 2360f0d..7b0923e 100644 --- a/vendor/github.com/rs/zerolog/sampler.go +++ b/vendor/github.com/rs/zerolog/sampler.go @@ -46,8 +46,12 @@ type BasicSampler struct { // Sample implements the Sampler interface. func (s *BasicSampler) Sample(lvl Level) bool { + n := s.N + if n == 1 { + return true + } c := atomic.AddUint32(&s.counter, 1) - return c%s.N == s.N-1 + return c%n == 1 } // BurstSampler lets Burst events pass per Period then pass the decision to diff --git a/vendor/gopkg.in/yaml.v2/decode.go b/vendor/gopkg.in/yaml.v2/decode.go index e4e56e2..5310876 100644 --- a/vendor/gopkg.in/yaml.v2/decode.go +++ b/vendor/gopkg.in/yaml.v2/decode.go @@ -229,6 +229,10 @@ type decoder struct { mapType reflect.Type terrors []string strict bool + + decodeCount int + aliasCount int + aliasDepth int } var ( @@ -314,7 +318,39 @@ func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unm return out, false, false } +const ( + // 400,000 decode operations is ~500kb of dense object declarations, or ~5kb of dense object declarations with 10000% alias expansion + alias_ratio_range_low = 400000 + // 4,000,000 decode operations is ~5MB of dense object declarations, or ~4.5MB of dense object declarations with 10% alias expansion + alias_ratio_range_high = 4000000 + // alias_ratio_range is the range over which we scale allowed alias ratios + alias_ratio_range = float64(alias_ratio_range_high - alias_ratio_range_low) +) + +func allowedAliasRatio(decodeCount int) float64 { + switch { + case decodeCount <= alias_ratio_range_low: + // allow 99% to come from alias expansion for small-to-medium documents + return 0.99 + case decodeCount >= alias_ratio_range_high: + // allow 10% to come from alias expansion for very large documents + return 0.10 + default: + // scale smoothly from 99% down to 10% over the range. + // this maps to 396,000 - 400,000 allowed alias-driven decodes over the range. + // 400,000 decode operations is ~100MB of allocations in worst-case scenarios (single-item maps). + return 0.99 - 0.89*(float64(decodeCount-alias_ratio_range_low)/alias_ratio_range) + } +} + func (d *decoder) unmarshal(n *node, out reflect.Value) (good bool) { + d.decodeCount++ + if d.aliasDepth > 0 { + d.aliasCount++ + } + if d.aliasCount > 100 && d.decodeCount > 1000 && float64(d.aliasCount)/float64(d.decodeCount) > allowedAliasRatio(d.decodeCount) { + failf("document contains excessive aliasing") + } switch n.kind { case documentNode: return d.document(n, out) @@ -353,7 +389,9 @@ func (d *decoder) alias(n *node, out reflect.Value) (good bool) { failf("anchor '%s' value contains itself", n.value) } d.aliases[n] = true + d.aliasDepth++ good = d.unmarshal(n.alias, out) + d.aliasDepth-- delete(d.aliases, n) return good } diff --git a/vendor/gopkg.in/yaml.v2/resolve.go b/vendor/gopkg.in/yaml.v2/resolve.go index 6c151db..4120e0c 100644 --- a/vendor/gopkg.in/yaml.v2/resolve.go +++ b/vendor/gopkg.in/yaml.v2/resolve.go @@ -81,7 +81,7 @@ func resolvableTag(tag string) bool { return false } -var yamlStyleFloat = regexp.MustCompile(`^[-+]?[0-9]*\.?[0-9]+([eE][-+][0-9]+)?$`) +var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`) func resolve(tag string, in string) (rtag string, out interface{}) { if !resolvableTag(tag) { diff --git a/vendor/gopkg.in/yaml.v2/scannerc.go b/vendor/gopkg.in/yaml.v2/scannerc.go index 077fd1d..570b8ec 100644 --- a/vendor/gopkg.in/yaml.v2/scannerc.go +++ b/vendor/gopkg.in/yaml.v2/scannerc.go @@ -906,6 +906,9 @@ func yaml_parser_remove_simple_key(parser *yaml_parser_t) bool { return true } +// max_flow_level limits the flow_level +const max_flow_level = 10000 + // Increase the flow level and resize the simple key list if needed. func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool { // Reset the simple key on the next level. @@ -913,6 +916,11 @@ func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool { // Increase the flow level. parser.flow_level++ + if parser.flow_level > max_flow_level { + return yaml_parser_set_scanner_error(parser, + "while increasing flow level", parser.simple_keys[len(parser.simple_keys)-1].mark, + fmt.Sprintf("exceeded max depth of %d", max_flow_level)) + } return true } @@ -925,6 +933,9 @@ func yaml_parser_decrease_flow_level(parser *yaml_parser_t) bool { return true } +// max_indents limits the indents stack size +const max_indents = 10000 + // Push the current indentation level to the stack and set the new level // the current column is greater than the indentation level. In this case, // append or insert the specified token into the token queue. @@ -939,6 +950,11 @@ func yaml_parser_roll_indent(parser *yaml_parser_t, column, number int, typ yaml // indentation level. parser.indents = append(parser.indents, parser.indent) parser.indent = column + if len(parser.indents) > max_indents { + return yaml_parser_set_scanner_error(parser, + "while increasing indent level", parser.simple_keys[len(parser.simple_keys)-1].mark, + fmt.Sprintf("exceeded max depth of %d", max_indents)) + } // Create a token and insert it into the queue. token := yaml_token_t{ diff --git a/vendor/modules.txt b/vendor/modules.txt index 8afaad5..56fc10d 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,8 +1,8 @@ -# github.com/Arman92/go-tdlib v0.0.0-20181103144727-9577ff528640 +# github.com/Arman92/go-tdlib v0.0.0-20191002071913-526f4e1d15f7 github.com/Arman92/go-tdlib -# github.com/rs/zerolog v1.11.0 +# github.com/rs/zerolog v1.15.0 github.com/rs/zerolog github.com/rs/zerolog/internal/cbor github.com/rs/zerolog/internal/json -# gopkg.in/yaml.v2 v2.2.2 +# gopkg.in/yaml.v2 v2.2.4 gopkg.in/yaml.v2