diff --git a/cmd/localstack/main.go b/cmd/localstack/main.go index c98cf75..e4e096a 100644 --- a/cmd/localstack/main.go +++ b/cmd/localstack/main.go @@ -45,7 +45,7 @@ func InitLsOpts() *LsOpts { InteropPort: GetenvWithDefault("LOCALSTACK_INTEROP_PORT", "9563"), InitTracingPort: GetenvWithDefault("LOCALSTACK_RUNTIME_TRACING_PORT", "9564"), User: GetenvWithDefault("LOCALSTACK_USER", "sbx_user1051"), - InitLogLevel: GetenvWithDefault("LOCALSTACK_INIT_LOG_LEVEL", "debug"), + InitLogLevel: GetenvWithDefault("LOCALSTACK_INIT_LOG_LEVEL", "warn"), EdgePort: GetenvWithDefault("EDGE_PORT", "4566"), // optional or empty CodeArchives: os.Getenv("LOCALSTACK_CODE_ARCHIVES"), @@ -93,14 +93,32 @@ func main() { lsOpts := InitLsOpts() UnsetLsEnvs() - // set up logging + // set up logging following the Logrus logging levels: https://github.com/sirupsen/logrus#level-logging log.SetReportCaller(true) + // https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-configuration.html + xRayLogLevel := "info" switch lsOpts.InitLogLevel { - case "debug": - log.SetLevel(log.DebugLevel) case "trace": log.SetFormatter(&log.JSONFormatter{}) log.SetLevel(log.TraceLevel) + xRayLogLevel = "debug" + case "debug": + log.SetLevel(log.DebugLevel) + xRayLogLevel = "debug" + case "info": + log.SetLevel(log.InfoLevel) + case "warn": + log.SetLevel(log.WarnLevel) + xRayLogLevel = "warn" + case "error": + log.SetLevel(log.ErrorLevel) + xRayLogLevel = "error" + case "fatal": + log.SetLevel(log.FatalLevel) + xRayLogLevel = "error" + case "panic": + log.SetLevel(log.PanicLevel) + xRayLogLevel = "error" default: log.Fatal("Invalid value for LOCALSTACK_INIT_LOG_LEVEL") } @@ -150,7 +168,8 @@ func main() { SetTailLogOutput(logCollector) // xray daemon - xrayConfig := initConfig("http://" + lsOpts.LocalstackIP + ":" + lsOpts.EdgePort) + endpoint := "http://" + lsOpts.LocalstackIP + ":" + lsOpts.EdgePort + xrayConfig := initConfig(endpoint, xRayLogLevel) d := initDaemon(xrayConfig, lsOpts.EnableXRayTelemetry == "1") sandbox.AddShutdownFunc(func() { log.Debugln("Shutting down xray daemon") diff --git a/cmd/localstack/xraydaemon.go b/cmd/localstack/xraydaemon.go index f004503..4af83e8 100644 --- a/cmd/localstack/xraydaemon.go +++ b/cmd/localstack/xraydaemon.go @@ -71,7 +71,8 @@ type Daemon struct { server *proxy.Server } -func initConfig(endpoint string) *cfg.Config { +// https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-configuration.html +func initConfig(endpoint string, logLevel string) *cfg.Config { xrayConfig := cfg.DefaultConfig() xrayConfig.Socket.UDPAddress = "127.0.0.1:2000" xrayConfig.Socket.TCPAddress = "127.0.0.1:2000" @@ -79,7 +80,7 @@ func initConfig(endpoint string) *cfg.Config { xrayConfig.NoVerifySSL = util.Bool(true) // obvious xrayConfig.LocalMode = util.Bool(true) // skip EC2 metadata check xrayConfig.Region = GetEnvOrDie("AWS_REGION") - xrayConfig.Logging.LogLevel = "info" + xrayConfig.Logging.LogLevel = logLevel //xrayConfig.TotalBufferSizeMB //xrayConfig.RoleARN = roleARN diff --git a/lambda/rapi/server.go b/lambda/rapi/server.go index 1879d2e..2d5f48a 100644 --- a/lambda/rapi/server.go +++ b/lambda/rapi/server.go @@ -2,13 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // LOCALSTACK CHANGES 2022-03-10: Chi logger middleware added +// LOCALSTACK CHANGES 2023-04-14: Replace Chi logger with the rapid AccessLogMiddleware based on Logrus package rapi import ( "context" "fmt" - "github.com/go-chi/chi/middleware" "net" "net/http" @@ -16,6 +16,7 @@ import ( "go.amzn.com/lambda/appctx" "go.amzn.com/lambda/core" + "go.amzn.com/lambda/rapi/middleware" "go.amzn.com/lambda/rapi/rendering" "go.amzn.com/lambda/telemetry" @@ -52,7 +53,7 @@ func NewServer(host string, port int, appCtx appctx.ApplicationContext, exitErrors := make(chan error, 1) router := chi.NewRouter() - router.Use(middleware.Logger) + router.Use(middleware.AccessLogMiddleware()) router.Mount(version20180601, NewRouter(appCtx, registrationService, renderingService)) router.Mount(version20200101, ExtensionsRouter(appCtx, registrationService, renderingService))