Skip to content

Commit

Permalink
Merge pull request #11 from fujiwara/set-output
Browse files Browse the repository at this point in the history
add SetOutput to specify io.Writer
  • Loading branch information
fujiwara authored Jul 3, 2023
2 parents aaa533b + 00e30a2 commit 446cec0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: "1.20"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --rm-dist
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ jobs:
strategy:
matrix:
go:
- 1.18.5
- 1.19
- "1.19"
- "1.20"
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
id: go
Expand Down
10 changes: 8 additions & 2 deletions tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Tracer struct {
sns *sns.Client
timeline *Timeline
buf *bytes.Buffer
w io.Writer

now time.Time
headBegin time.Time
Expand Down Expand Up @@ -113,6 +114,7 @@ func NewWithConfig(config aws.Config) (*Tracer, error) {
seen: make(map[string]bool),
},
buf: new(bytes.Buffer),
w: os.Stdout,
}, nil
}

Expand All @@ -130,6 +132,10 @@ type RunOption struct {
Duration time.Duration
}

func (t *Tracer) SetOutput(w io.Writer) {
t.w = w
}

func (t *Tracer) Run(ctx context.Context, cluster string, taskID string, opt *RunOption) error {
t.now = time.Now()
t.option = opt
Expand Down Expand Up @@ -158,8 +164,8 @@ func (t *Tracer) Run(ctx context.Context, cluster string, taskID string, opt *Ru
func (t *Tracer) report(ctx context.Context, cluster, taskID string) {
opt := t.option
if opt.Stdout {
fmt.Fprintln(os.Stdout, subject(cluster, taskID))
if _, err := t.WriteTo(os.Stdout); err != nil {
fmt.Fprintln(t.w, subject(cluster, taskID))
if _, err := t.WriteTo(t.w); err != nil {
fmt.Fprintln(os.Stderr, err)
}
}
Expand Down

0 comments on commit 446cec0

Please sign in to comment.