8000 Improve logging output (#19) · localstack/lambda-runtime-init@b87667e · GitHub
[go: up one dir, main page]

Skip to content

Commit b87667e

Browse files
authored
Improve logging output (#19)
1 parent fc1ba06 commit b87667e

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

cmd/localstack/main.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func InitLsOpts() *LsOpts {
4545
InteropPort: GetenvWithDefault("LOCALSTACK_INTEROP_PORT", "9563"),
4646
InitTracingPort: GetenvWithDefault("LOCALSTACK_RUNTIME_TRACING_PORT", "9564"),
4747
User: GetenvWithDefault("LOCALSTACK_USER", "sbx_user1051"),
48-
InitLogLevel: GetenvWithDefault("LOCALSTACK_INIT_LOG_LEVEL", "debug"),
48+
InitLogLevel: GetenvWithDefault("LOCALSTACK_INIT_LOG_LEVEL", "warn"),
4949
EdgePort: GetenvWithDefault("EDGE_PORT", "4566"),
5050
// optional or empty
5151
CodeArchives: os.Getenv("LOCALSTACK_CODE_ARCHIVES"),
@@ -93,14 +93,32 @@ func main() {
9393
lsOpts := InitLsOpts()
9494
UnsetLsEnvs()
9595

96-
// set up logging
96+
// set up logging following the Logrus logging levels: https://github.com/sirupsen/logrus#level-logging
9797
log.SetReportCaller(true)
98+
// https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-configuration.html
99+
xRayLogLevel := "info"
98100
switch lsOpts.InitLogLevel {
99-
case "debug":
100-
log.SetLevel(log.DebugLevel)
101101
case "trace":
102102
log.SetFormatter(&log.JSONFormatter{})
103103
log.SetLevel(log.TraceLevel)
104+
xRayLogLevel = "debug"
105+
case "debug":
106+
log.SetLevel(log.DebugLevel)
107+
xRayLogLevel = "debug"
108+
case "info":
109+
log.SetLevel(log.InfoLevel)
110+
case "warn":
111+
log.SetLevel(log.WarnLevel)
112+
xRayLogLevel = "warn"
113+
case "error":
114+
log.SetLevel(log.ErrorLevel)
115+
xRayLogLevel = "error"
116+
case "fatal":
117+
log.SetLevel(log.FatalLevel)
118+
xRayLogLevel = "error"
119+
case "panic":
120+
log.SetLevel(log.PanicLevel)
121+
xRayLogLevel = "error"
104122
default:
105123
log.Fatal("Invalid value for LOCALSTACK_INIT_LOG_LEVEL")
106124
}
@@ -150,7 +168,8 @@ func main() {
150168
SetTailLogOutput(logCollector)
151169

152170
// xray daemon
153-
xrayConfig := initConfig("http://" + lsOpts.LocalstackIP + ":" + lsOpts.EdgePort)
171+
endpoint := "http://" + lsOpts.LocalstackIP + ":" + lsOpts.EdgePort
172+
xrayConfig := initConfig(endpoint, xRayLogLevel)
154173
d := initDaemon(xrayConfig, lsOpts.EnableXRayTelemetry == "1")
155174
sandbox.AddShutdownFunc(func() {
156175
log.Debugln("Shutting down xray daemon")

cmd/localstack/xraydaemon.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ type Daemon struct {
7171
server *proxy.Server
7272
}
7373

74-
func initConfig(endpoint string) *cfg.Config {
74+
// https://docs.aws.amazon.com/xray/latest/devguide/xray-daemon-configuration.html
75+
func initConfig(endpoint string, logLevel string) *cfg.Config {
7576
xrayConfig := cfg.DefaultConfig()
7677
xrayConfig.Socket.UDPAddress = "127.0.0.1:2000"
7778
xrayConfig.Socket.TCPAddress = "127.0.0.1:2000"
7879
xrayConfig.Endpoint = endpoint
7980
xrayConfig.NoVerifySSL = util.Bool(true) // obvious
8081
xrayConfig.LocalMode = util.Bool(true) // skip EC2 metadata check
8182
xrayConfig.Region = GetEnvOrDie("AWS_REGION")
82-
xrayConfig.Logging.LogLevel = "info"
83+
xrayConfig.Logging.LogLevel = logLevel
8384
//xrayConfig.TotalBufferSizeMB
8485
//xrayConfig.RoleARN = roleARN
8586

lambda/rapi/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
// LOCALSTACK CHANGES 2022-03-10: Chi logger middleware added
5+
// LOCALSTACK CHANGES 2023-04-14: Replace Chi logger with the rapid AccessLogMiddleware based on Logrus
56

67
package rapi
78

89
import (
910
"context"
1011
"fmt"
11-
"github.com/go-chi/chi/middleware"
1212
"net"
1313
"net/http"
1414

1515
"github.com/go-chi/chi"
1616
"go.amzn.com/lambda/appctx"
1717

1818
"go.amzn.com/lambda/core"
19+
"go.amzn.com/lambda/rapi/middleware"
1920
"go.amzn.com/lambda/rapi/rendering"
2021
"go.amzn.com/lambda/telemetry"
2122

@@ -52,7 +53,7 @@ func NewServer(host string, port int, appCtx appctx.ApplicationContext,
5253
exitErrors := make(chan error, 1)
5354

5455
router := chi.NewRouter()
55-
router.Use(middleware.Logger)
56+
router.Use(middleware.AccessLogMiddleware())
5657
router.Mount(version20180601, NewRouter(appCtx, registrationService, renderingService))
5758
router.Mount(version20200101, ExtensionsRouter(appCtx, registrationService, renderingService))
5859

0 commit comments

Comments
 (0)
0