Skip to content

Commit

Permalink
Merge pull request #362 from rcrowe/configure-logger
Browse files Browse the repository at this point in the history
Expose configuration of logger
  • Loading branch information
gianarb committed Oct 22, 2021
2 parents 48ce5b9 + cceef31 commit efe05c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package testcontainers
import (
"context"
"io"
"log"
"os"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Expand All @@ -14,6 +16,9 @@ import (
"github.com/testcontainers/testcontainers-go/wait"
)

// Logger is the default log instance
var Logger = log.New(os.Stderr, "", log.LstdFlags)

// DeprecatedContainer shows methods that were supported before, but are now deprecated
// Deprecated: Use Container
type DeprecatedContainer interface {
Expand Down
9 changes: 4 additions & 5 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net/url"
"os"
"os/exec"
Expand Down Expand Up @@ -157,20 +156,20 @@ func (c *DockerContainer) SessionID() string {
// Start will start an already created container
func (c *DockerContainer) Start(ctx context.Context) error {
shortID := c.ID[:12]
log.Printf("Starting container id: %s image: %s", shortID, c.Image)
Logger.Printf("Starting container id: %s image: %s", shortID, c.Image)

if err := c.provider.client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{}); err != nil {
return err
}

// if a Wait Strategy has been specified, wait before returning
if c.WaitingFor != nil {
log.Printf("Waiting for container id %s image: %s", shortID, c.Image)
Logger.Printf("Waiting for container id %s image: %s", shortID, c.Image)
if err := c.WaitingFor.WaitUntilReady(ctx, c); err != nil {
return err
}
}
log.Printf("Container is ready id: %s image: %s", shortID, c.Image)
Logger.Printf("Container is ready id: %s image: %s", shortID, c.Image)

return nil
}
Expand Down Expand Up @@ -778,7 +777,7 @@ func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pul
if _, ok := err.(errdefs.ErrNotFound); ok {
return backoff.Permanent(err)
}
log.Printf("Failed to pull image: %s, will retry", err)
Logger.Printf("Failed to pull image: %s, will retry", err)
return err
}
return nil
Expand Down

0 comments on commit efe05c4

Please sign in to comment.