MCPcopy Create free account
hub / github.com/convox/rack / Handler

Function Handler

provider/aws/lambda/syslog/handler.go:17–49  ·  view source on GitHub ↗
(ctx context.Context, event cloudwatchlogs.Event)

Source from the content-addressed store, hash-verified

15)
16
17func Handler(ctx context.Context, event cloudwatchlogs.Event) error {
18 d, err := event.AWSLogs.DecodedData()
19 if err != nil {
20 return err
21 }
22
23 u, err := url.Parse(os.Getenv("SYSLOG_URL"))
24 if err != nil {
25 return err
26 }
27
28 w, err := syslog.Dial(u.Scheme, u.Host, syslog.LOG_INFO, "convox/syslog")
29 if err != nil {
30 return err
31 }
32 defer w.Close()
33
34 w.SetFormatter(contentFormatter(d.LogGroup))
35
36 var failures, successes int
37
38 for _, le := range d.LogEvents {
39 if err := w.Info(fmt.Sprintf("%s %d %s", d.LogStream, le.Timestamp, le.Message)); err != nil {
40 failures++
41 } else {
42 successes++
43 }
44 }
45
46 fmt.Printf("group=%s stream=%s type=%s events=%d success=%d failure=%d\n", d.LogGroup, d.LogStream, d.MessageType, len(d.LogEvents), successes, failures)
47
48 return nil
49}
50
51func contentFormatter(group string) syslog.Formatter {
52 return func(p syslog.Priority, hostname, tag, content string) string {

Callers

nothing calls this directly

Calls 2

contentFormatterFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected