FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve logging output by joe4dev · Pull Request #19 · localstack/lambda-runtime-init · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
29 changes: 24 additions & 5 deletions cmd/localstack/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions cmd/localstack/xraydaemon.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,16 @@ 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"
xrayConfig.Endpoint = endpoint
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

Expand Down
5 changes: 3 additions & 2 deletions lambda/rapi/server.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
// 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"

"github.com/go-chi/chi"
"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"

Expand Down Expand Up @@ -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))

Expand Down

Back | FazBrowse Home | New Git URL