Skip to content

Commit

Permalink
Improve tkn chain log format
Browse files Browse the repository at this point in the history
Prior to this commit, `tkn chain` logs look like:

```
$ tkn chains payload build-push-run-output-image-p229w
sync /dev/stderr: invalid argument
{"level":"info","ts":1654352100.0164135,"caller":"tekton/tekton.go:134","msg":"Retrieving payload on TaskRun default/build-push-run-output-image-p229w"}
{"level":"info","ts":1654352100.0164497,"caller":"tekton/tekton.go:86","msg":"Retrieving annotation \"chains.tekton.dev/payload-taskrun-6e2f020b-7d50-4022-8064-049680f72d32\" on TaskRun default/build-push-run-output-image-p229w"}
No payloads found for taskrun build-push-run-output-image-p229w
```

and after this commit they look like:

```
$ ./tkn chains payload build-push-run-output-image-p229w
sync /dev/stderr: invalid argument
Retrieving payload on TaskRun default/build-push-run-output-image-p229w
Retrieving annotation "chains.tekton.dev/payload-taskrun-6e2f020b-7d50-4022-8064-049680f72d32" on TaskRun default/build-push-run-output-image-p229w
No payloads found for taskrun build-push-run-output-image-p229w
```

which is more in line with how `tkn` logs look like in general.
  • Loading branch information
concaf committed Jun 5, 2022
1 parent b7f7bbe commit 9a23a2b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package chain
import (
"context"
"fmt"
"os"

"go.uber.org/zap/zapcore"

"github.com/tektoncd/chains/pkg/chains/storage"
"github.com/tektoncd/chains/pkg/config"
Expand All @@ -37,10 +40,12 @@ func ConfigMapToContext(cs *cli.Clients, namespace string) (context.Context, err

func GetTaskRunBackends(cs *cli.Clients, namespace string, tr *v1beta1.TaskRun) (map[string]storage.Backend, config.StorageOpts, error) {
// Prepare the logger.
logger, err := zap.NewProduction()
if err != nil {
return nil, config.StorageOpts{}, err
encoderCfg := zapcore.EncoderConfig{
MessageKey: "msg",
}
core := zapcore.NewCore(zapcore.NewConsoleEncoder(encoderCfg), os.Stderr, zapcore.DebugLevel)
logger := zap.New(core).WithOptions()

// flushes buffer, if any
defer func() {
if err := logger.Sync(); err != nil {
Expand Down

0 comments on commit 9a23a2b

Please sign in to comment.