Skip to content

Commit

Permalink
Add custom LocalStack LogsEgressAPI using logCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
joe4dev committed Oct 13, 2023
1 parent ed9ea3e commit 6b9d9a6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
31 changes: 31 additions & 0 deletions cmd/localstack/logs_egress_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"io"
"os"
)

// This LocalStack LogsEgressAPI builder allows to customize log capturing, in our case using the logCollector.

type LocalStackLogsEgressAPI struct {
logCollector *LogCollector
}

func NewLocalStackLogsEgressAPI(logCollector *LogCollector) *LocalStackLogsEgressAPI {
return &LocalStackLogsEgressAPI{
logCollector: logCollector,
}
}

// The interface StdLogsEgressAPI for the functions below is defined in the under cmd/localstack/logs_egress_api.go
// The default implementation is a NoOpLogsEgressAPI

func (s *LocalStackLogsEgressAPI) GetExtensionSockets() (io.Writer, io.Writer, error) {
// os.Stderr can not be used for the stderrWriter because stderr is for internal logging (not customer visible).
return io.MultiWriter(s.logCollector, os.Stdout), io.MultiWriter(s.logCollector, os.Stdout), nil
}

func (s *LocalStackLogsEgressAPI) GetRuntimeSockets() (io.Writer, io.Writer, error) {
// os.Stderr can not be used for the stderrWriter because stderr is for internal logging (not customer visible).
return io.MultiWriter(s.logCollector, os.Stdout), io.MultiWriter(s.logCollector, os.Stdout), nil
}
8 changes: 5 additions & 3 deletions cmd/localstack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,12 @@ func main() {
UserLogger().Debugln("Process running as non-root user.")
}

logCollector := NewLogCollector()

// file watcher for hot-reloading
fileWatcherContext, cancelFileWatcher := context.WithCancel(context.Background())

logCollector := NewLogCollector()
localStackLogsEgressApi := NewLocalStackLogsEgressAPI(logCollector)

// build sandbox
sandbox := rapidcore.
NewSandboxBuilder().
Expand All @@ -164,7 +165,8 @@ func main() {
stopDnsServer()
}).
SetExtensionsFlag(true).
SetInitCachingFlag(true)
SetInitCachingFlag(true).
SetLogsEgressAPI(localStackLogsEgressApi)

// xray daemon
endpoint := "http://" + lsOpts.LocalstackIP + ":" + lsOpts.EdgePort
Expand Down

0 comments on commit 6b9d9a6

Please sign in to comment.