@@ -230,40 +230,55 @@ func detectRace(prefix string) bool {
230230}
231231
232232func outputLogs (prefix string ) {
233+ fmt .Printf ("Outputting logs for prefix: %s\n " , prefix )
234+ fmt .Println ("=================================================" )
235+ fmt .Println ("=================================================" )
236+ fmt .Println ("=================================================" )
233237 f , err := os .CreateTemp ("." , prefix + "*.log" )
234238 x .Check (err )
235239 defer func () {
236240 if err := f .Close (); err != nil {
237241 fmt .Printf ("error closing file: %v" , err )
238242 }
239243 }()
240- printLogs := func (container string ) {
241- in := testutil .GetContainerInstance (prefix , container )
242- c := in .GetContainer ()
243- if c == nil {
244- return
245- }
244+
245+ // Get all containers with this prefix instead of hardcoding container names
246+ // This works for both default docker-compose.yml and custom compose files
247+ containers := testutil .AllContainers (prefix )
248+
249+ fmt .Println ("-------------------------------------------------" )
250+ fmt .Printf ("Containers: %+v\n " , containers )
251+ fmt .Println ("-------------------------------------------------" )
252+
253+ for _ , c := range containers {
246254 logCmd := exec .Command ("docker" , "logs" , c .ID )
247255 out , err := logCmd .CombinedOutput ()
248- x .Check (err )
256+ if err != nil {
257+ fmt .Printf ("Error getting logs for container %s (ID: %s): %v\n " , c .Names , c .ID , err )
258+ continue
259+ }
249260 if _ , err := f .Write (out ); err != nil {
250261 fmt .Printf ("error writing container logs to file: %v" , err )
251262 }
252- fmt .Printf ("Docker logs for %s is %s with error %+v " , c .ID , string (out ), err )
253- }
254- for i := 0 ; i <= 3 ; i ++ {
255- printLogs ("zero" + strconv .Itoa (i ))
263+ // Include container name in the log output for easier debugging
264+ containerName := "unknown"
265+ if len (c .Names ) > 0 {
266+ containerName = strings .TrimPrefix (c .Names [0 ], "/" )
267+ }
268+ fmt .Printf ("Docker logs for %s (ID: %s):\n %s\n " , containerName , c .ID , string (out ))
256269 }
257270
258- for i := 0 ; i <= 6 ; i ++ {
259- printLogs ("alpha" + strconv .Itoa (i ))
260- }
271+ fmt .Println ("-------------------------------------------------" )
272+ fmt .Printf ("Logs written to file: %s\n " , f .Name ())
273+ fmt .Println ("-------------------------------------------------" )
274+
261275 s := fmt .Sprintf ("---> LOGS for %s written to %s .\n " , prefix , f .Name ())
262276 _ , err = oc .Write ([]byte (s ))
263277 x .Check (err )
264278}
265279
266280func stopCluster (composeFile , prefix string , wg * sync.WaitGroup , err error ) {
281+ fmt .Println ("in stop cluster function========================" )
267282 go func () {
268283 if err != nil {
269284 outputLogs (prefix )
@@ -547,9 +562,15 @@ func runTests(taskCh chan task, closer *z.Closer) error {
547562 } else {
548563 // we are not using err variable here because we dont want to
549564 // print logs of default cluster in case of custom test fail.
550- if cerr := runCustomClusterTest (ctx , task .pkg .ID , wg , xmlFile ); cerr != nil {
551- return cerr
565+ if err = runCustomClusterTest (ctx , task .pkg .ID , wg , xmlFile ); err != nil {
566+ fmt .Printf ("Ran custom cluster test for package: %s with error: %v\n " , task .pkg .ID , err )
567+ fmt .Println ("=================================================" )
568+ fmt .Println ("=================================================" )
569+ return err
552570 }
571+ fmt .Printf ("Ran custom cluster test for package: %s with error: %v\n " , task .pkg .ID , err )
572+ fmt .Println ("=================================================" )
573+ fmt .Println ("=================================================" )
553574 }
554575 }
555576 return err
0 commit comments