Skip to content

Commit

Permalink
Add logger config methods from AWS events
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianpozueco committed Jul 7, 2021
1 parent d25d356 commit 594f8b2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logger

import (
"github.com/Ryanair/gofrlib/log"
"github.com/aws/aws-lambda-go/events"
)

func NewLogConfiguration(logLevel string, application string, project string, projectGroup string) log.Configuration {
Expand Down Expand Up @@ -39,8 +40,8 @@ func InitialLambdaConfiguration(functionName string, logGroup string, logStream

func SetTraceId(traceId string) {
if traceId != "" {
log.With("Body.context.trace.spanId", traceId)
log.With("SpanId", traceId)
log.With("Body.context.trace.traceId", traceId)
log.With("TraceId", traceId)
}
}

Expand All @@ -59,8 +60,22 @@ func SetRequestInfo(method string, url string, route string, query string, userA
log.With("Body.context.origin.request.userAgent", userAgent)
}

func SetEvent(source string, body map[string]interface{}, params map[string]interface{}) {
func SetEvent(source string, body string, params map[string]string) {
log.With("Body.context.origin.event.eventSource", source)
log.With("Body.context.origin.event.eventBody", body)
log.With("Body.context.origin.event.eventParams", params)
}

func SetSQSEvent(event events.SQSMessage) {
log.With("Body.context.origin.event.eventSource", event.EventSource)
log.With("Body.context.origin.event.eventBody", event.Body)
log.With("Body.context.origin.event.eventParams", event.Attributes)
}

func SetApigwRequest(event events.APIGatewayV2HTTPRequest) {
log.With("Body.context.origin.request.method", event.RequestContext.HTTP.Method)
log.With("Body.context.origin.request.url", event.RequestContext.DomainName)
log.With("Body.context.origin.request.route", event.RequestContext.RouteKey)
log.With("Body.context.origin.request.query", event.RawQueryString)
log.With("Body.context.origin.request.userAgent", event.RequestContext.HTTP.UserAgent)
}

0 comments on commit 594f8b2

Please sign in to comment.