Skip to content

Commit

Permalink
Merge pull request #6 from adrianpozueco/main
Browse files Browse the repository at this point in the history
Add logger config methods from AWS events
  • Loading branch information
adrianpozueco authored Jul 7, 2021
2 parents d25d356 + 594f8b2 commit 78c59b7
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 78c59b7

Please sign in to comment.