@@ -208,6 +208,8 @@ import (
208208 "fmt"
209209 "math/big"
210210 "net/http"
211+ "os"
212+ "slices"
211213 "strconv"
212214 "strings"
213215 "sync"
@@ -217,9 +219,11 @@ import (
217219 "github.com/avast/retry-go/v4"
218220 "github.com/ethereum/go-ethereum/accounts/abi/bind"
219221 "github.com/ethereum/go-ethereum/crypto"
222+ "github.com/rs/zerolog"
220223 chainsel "github.com/smartcontractkit/chain-selectors"
221224 "github.com/smartcontractkit/chainlink-testing-framework/framework"
222225 "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
226+ ctfdocker "github.com/smartcontractkit/chainlink-testing-framework/lib/docker"
223227 "github.com/smartcontractkit/freeport"
224228 "github.com/testcontainers/testcontainers-go"
225229
@@ -516,6 +520,14 @@ func (p *CTFAnvilChainProvider) GetNodeHTTPURL() string {
516520// Returns an error if the container termination fails.
517521func (p * CTFAnvilChainProvider ) Cleanup (ctx context.Context ) error {
518522 if p .container != nil {
523+ if shouldSaveCtfContainerLogs () {
524+ zlogger := zerolog .New (os .Stdout )
525+ ctfdocker .WriteAllContainersLogs (zlogger , "logs" )
526+ wd , _ := os .Getwd ()
527+ zlogger .Info ().Msgf ("container logs saved to \" %s/logs\" " , wd )
528+ }
529+
530+ // if slices.Contains([]string{}, strconv.ToLower(os.GetEnv("CTF_CONTAINER_LOGS")) {
519531 err := p .container .Terminate (ctx )
520532 if err != nil {
521533 return fmt .Errorf ("failed to terminate Anvil container: %w" , err )
@@ -714,3 +726,8 @@ func (p *CTFAnvilChainProvider) waitForAnvilReady(ctx context.Context, httpURL s
714726 retry .DelayType (retry .FixedDelay ),
715727 )
716728}
729+
730+ func shouldSaveCtfContainerLogs () bool {
731+ trueValues := []string {"1" , "true" , "on" , "enabled" }
732+ return slices .Contains (trueValues , strings .ToLower (os .Getenv ("CTF_CONTAINER_LOGS" )))
733+ }
0 commit comments