Asynchronise batch upload logs to Tencent Cloud CLS for logrus with configurable batch number and max wait time.
package main
import (
"github.com/chuangbo/logruscls"
log "github.com/sirupsen/logrus"
)
func main() {
// NewCLSAsyncClient or NewCLSClient
client, err := logruscls.NewCLSAsyncClient(
"topicID",
"region",
"secretID",
"secretKey",
30, // max number of logs for batch upload
time.Second*30, // max wait time before reach max number of logs
)
if err != nil {
panic(err)
}
hook, err := logruscls.NewHook(client)
if err != nil {
panic(err)
}
log.AddHook(hook)
}
Of course the logrus-free golang cls client CLSClient
and CLSAsyncClient
are for you to use directly as well if logrus is not your thing.
package main
import (
"github.com/chuangbo/logruscls"
"github.com/chuangbo/logruscls/pb"
"github.com/golang/protobuf/proto"
)
func main() {
client, err := logruscls.NewCLSAsyncClient(...)
if err != nil {
panic(err)
}
err = client.Log(&pb.Log{
Time: proto.Int64(time.Now().UnixNano() / int64(time.Millisecond)),
Contents: []*pb.Log_Content{
{
Key: proto.String("message"),
Value: proto.String("Hello Logrus"),
},
},
})
if err != nil {
panic(err)
}
}
For more API please refer to godoc and CLS protobuf definition. But please keep in mind, this may never going to be a full-feature CLS client.
signature for headers and query string(md5 doesn't work so kind of pointless)content md5(seems upload using even wrong random md5 checksum work)lz4 compress(doesn't work)- tests
Copyright (c) 2019-present, Chuangbo Li