Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more context to error logs #10

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions cmd/catalyst-uploader/catalyst-uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/json"
"flag"
"fmt"
"github.com/livepeer/catalyst-uploader/core"
"github.com/livepeer/go-tools/drivers"
log "github.com/sirupsen/logrus"
"gopkg.in/natefinch/lumberjack.v2"
"io"
"os"
"path/filepath"
"time"

"github.com/livepeer/catalyst-uploader/core"
"github.com/livepeer/go-tools/drivers"
log "github.com/sirupsen/logrus"
"gopkg.in/natefinch/lumberjack.v2"
)

func run() int {
Expand Down Expand Up @@ -74,22 +75,25 @@ Args:
log.Fatal("Object store URI is not specified. See -h for usage.")
}

// Enrich the logs with parameters the uploader was called with
logger := log.WithField("uri", uri).WithField("timeout", *timeout)

storageDriver, err := drivers.ParseOSURL(uri, true)
// path is passed along with the path when uploading
session := storageDriver.NewSession("")
if err != nil {
log.Fatal(err)
logger.WithField("stage", "NewSession").Fatal(err)
}
ctx := context.Background()
resKey, err := session.SaveData(ctx, "", os.Stdin, nil, *timeout)
if err != nil {
log.Fatal(err)
logger.WithField("stage", "SaveData").Fatal(err)
}

// success, write uploaded file details to stdout
err = json.NewEncoder(stdout).Encode(map[string]string{"uri": resKey})
if err != nil {
log.Fatal(err)
logger.WithField("stage", "SuccessResponse").Fatal(err)
}

return 0
Expand Down