forked from kdar/logrus-cloudwatchlogs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpreq.go
43 lines (35 loc) · 1012 Bytes
/
httpreq.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"io/ioutil"
"log"
"net/http"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
cwl "github.com/kdar/logrus-cloudwatchlogs"
"github.com/sirupsen/logrus"
)
func main() {
key := os.Getenv("AWS_ACCESS_KEY")
secret := os.Getenv("AWS_SECRET_KEY")
group := os.Getenv("AWS_CLOUDWATCHLOGS_GROUP_NAME")
stream := os.Getenv("AWS_CLOUDWATCHLOGS_STREAM_NAME")
// logs.us-east-1.amazonaws.com
cred := credentials.NewStaticCredentials(key, secret, "")
cfg := aws.NewConfig().WithRegion("us-east-1").WithCredentials(cred)
hook, err := cwl.NewHook(group, stream, cfg)
if err != nil {
log.Fatal(err)
}
l := logrus.New()
l.Hooks.Add(hook)
l.Out = ioutil.Discard
l.Formatter = cwl.NewProdFormatter(cwl.HTTPRequest("request"))
req, _ := http.NewRequest("GET", "http://rxmanagement.net", nil)
l.WithFields(logrus.Fields{
"event": "testevent",
"topic": "testtopic",
"key": "testkey",
"request": req,
}).Fatal("Some fatal event")
}