init
This commit is contained in:
commit
68201f06cb
|
|
@ -0,0 +1,35 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
exceptionless "github.com/Exceptionless/Exceptionless.Go"
|
||||||
|
uuid "github.com/satori/go.uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
//SubmitError is a convenience wrapper to quickly build and submit an error
|
||||||
|
func submitError(err error) string {
|
||||||
|
referenceID := uuid.Must(uuid.NewV4())
|
||||||
|
errorMap := map[string]interface{}{}
|
||||||
|
errorMap["type"] = "error"
|
||||||
|
errorMap["message"] = err.Error()
|
||||||
|
errorMap["date"] = time.Now().Format(time.RFC3339)
|
||||||
|
|
||||||
|
data := map[string]interface{}{}
|
||||||
|
data["@simple_error"] = errorMap
|
||||||
|
var mainEvent = exceptionless.Event{
|
||||||
|
EventType: "error",
|
||||||
|
Message: err.Error(),
|
||||||
|
Data: data,
|
||||||
|
ReferenceID: referenceID,
|
||||||
|
}
|
||||||
|
json, err := json.Marshal(mainEvent)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return err.Error()
|
||||||
|
}
|
||||||
|
resp := exceptionless.SubmitEvent(string(json))
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
module myschools.me/suguo/exceptionless-demo
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/Exceptionless/Exceptionless.Go v0.0.0-20210330134134-a0ab04d24cb5
|
||||||
|
github.com/go-errors/errors v1.4.2
|
||||||
|
github.com/gofrs/uuid v4.2.0+incompatible
|
||||||
|
)
|
||||||
|
|
||||||
|
require github.com/satori/go.uuid v1.2.0 // indirect
|
||||||
|
|
||||||
|
replace github.com/Exceptionless/Exceptionless.Go => github.com/exceptionless/Exceptionless.Go v0.0.0-20210330134134-a0ab04d24cb5
|
||||||
|
|
||||||
|
replace github.com/satori/go.uuid v1.2.0 => github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
github.com/exceptionless/Exceptionless.Go v0.0.0-20210330134134-a0ab04d24cb5 h1:I+yqXtQ774pFLulXFCwQIHwSTpXx2vgAu7YKalV4LDM=
|
||||||
|
github.com/exceptionless/Exceptionless.Go v0.0.0-20210330134134-a0ab04d24cb5/go.mod h1:UjL5Eu8+MbmGAabQPZaqPPGDXFTC6pfhJLanxgVczR0=
|
||||||
|
github.com/go-errors/errors v1.1.1/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs=
|
||||||
|
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||||
|
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||||
|
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
|
||||||
|
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||||
|
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||||
|
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||||
|
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||||
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
|
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/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM=
|
||||||
|
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
exceptionless "github.com/Exceptionless/Exceptionless.Go"
|
||||||
|
uuid "github.com/satori/go.uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
//日志初始化
|
||||||
|
exceptionless.Configure(exceptionless.Exceptionless{
|
||||||
|
ApiKey: "QF5OrvQfYCSLX9FQQoKd4ruRawJKpD2S19VYSGud",
|
||||||
|
ServerURL: `http://192.168.0.33:5000/api/v2/`,
|
||||||
|
})
|
||||||
|
|
||||||
|
t := exceptionless.SubmitLog("demo for exceptionless is running...", "info")
|
||||||
|
fmt.Println(t)
|
||||||
|
exceptionless.SubmitLog("demo for exceptionless is running...", "error")
|
||||||
|
exceptionless.SubmitLog("demo for exceptionless is running...", "warn")
|
||||||
|
exceptionless.SubmitLog("demo for exceptionless is running...", "fatal")
|
||||||
|
exceptionless.SubmitLog("demo for exceptionless is running...", "debug")
|
||||||
|
|
||||||
|
referenceID := uuid.Must(uuid.NewV4())
|
||||||
|
event := &struct {
|
||||||
|
Event string
|
||||||
|
Message string
|
||||||
|
Date string
|
||||||
|
EventType string
|
||||||
|
ReferenceID uuid.UUID
|
||||||
|
}{
|
||||||
|
Event: "error",
|
||||||
|
EventType: "error",
|
||||||
|
Message: "aaaaaaaaaaaaaaaaaa",
|
||||||
|
Date: time.Now().Format(time.RFC3339),
|
||||||
|
ReferenceID: referenceID,
|
||||||
|
}
|
||||||
|
ret, _ := json.Marshal(event)
|
||||||
|
t2 := exceptionless.SubmitEvent(string(ret))
|
||||||
|
fmt.Println(t2)
|
||||||
|
|
||||||
|
// t3 := exceptionless.SubmitError(errors.Unwrap(errors.New("dasfasdfasdf")))
|
||||||
|
// fmt.Println(t3) //通不过error stack
|
||||||
|
|
||||||
|
//重定试试error
|
||||||
|
t3 := submitError(errors.New("sadfsdfasdfsdafasdf"))
|
||||||
|
fmt.Println(t3)
|
||||||
|
|
||||||
|
//自定义
|
||||||
|
t4 := exceptionless.SubmitEvent("asfasdfasdfasdfasd")
|
||||||
|
fmt.Println(t4)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue