Skip to content

Commit

Permalink
minor refine
Browse files Browse the repository at this point in the history
Signed-off-by: Lixia (Sylvia) Lei <[email protected]>
  • Loading branch information
Wwwsylvia committed Dec 6, 2024
1 parent 06b314d commit 93d0de1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
7 changes: 0 additions & 7 deletions cmd/oras/root/repo/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ func listRepository(cmd *cobra.Command, opts *repositoryOptions) error {
if err != nil {
return err
}

// TEST: to be removed
logger = logger.WithField("registry", reg.Reference.Host())
logger = logger.WithField("testkey", 123)
logger.Info("test info")
logger.Warn("test warn")

err = reg.Repositories(ctx, opts.last, func(repos []string) error {
for _, repo := range repos {
if subRepo, found := strings.CutPrefix(repo, opts.namespace); found {
Expand Down
1 change: 0 additions & 1 deletion internal/trace/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func NewLogger(ctx context.Context, debug bool) (context.Context, logrus.FieldLo

logger := logrus.New()
logger.SetFormatter(&TextFormatter{})

logger.SetLevel(logLevel)
entry := logger.WithContext(ctx)
return context.WithValue(ctx, loggerKey, entry), entry
Expand Down
1 change: 0 additions & 1 deletion internal/trace/text_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ func (f *TextFormatter) Format(entry *logrus.Entry) ([]byte, error) {
}

buf.WriteString(logEntrySeperator)

return buf.Bytes(), nil
}
8 changes: 5 additions & 3 deletions internal/trace/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ func logHeader(header http.Header) string {
return " Empty header"
}

// TODO: test and docs
// logResponseBody prints out the response body if it is printable and within
// the size limit.
func logResponseBody(resp *http.Response) string {
if resp.Body == nil || resp.Body == http.NoBody || resp.ContentLength <= 0 {
return ""
}
contentType := resp.Header.Get("Content-Type")
if !shouldPrint(contentType) {
if !isPrintableContentType(contentType) {
return fmt.Sprintf(" Body of content type \"%s\" is not printed", contentType)
}
if resp.ContentLength > payloadSizeLimit {
Expand All @@ -121,7 +122,8 @@ func logResponseBody(resp *http.Response) string {
return builder.String()
}

func shouldPrint(contentType string) bool {
// isPrintableContentType returns true if the content of contentType is printable.
func isPrintableContentType(contentType string) bool {
// JSON types
if strings.HasPrefix(contentType, "application/json") || strings.HasSuffix(contentType, "+json") {
return true
Expand Down

0 comments on commit 93d0de1

Please sign in to comment.