Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions cli/command/service/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/idresolver"
"github.com/docker/cli/service/logs"
"github.com/docker/cli/cli/internal/logdetails"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still wondering if we need to keep a separate top-level internal/ and cli/internal - not sure if we need to, but we can decide at some point which one makes most sense.

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/swarm"
Expand Down Expand Up @@ -267,7 +267,7 @@ func (lw *logWriter) Write(buf []byte) (int, error) {
return 0, errors.Errorf("invalid context in log message: %v", string(buf))
}
// parse the details out
details, err := logs.ParseLogDetails(string(parts[detailsIndex]))
details, err := logdetails.Parse(string(parts[detailsIndex]))
if err != nil {
return 0, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
/*Package logs contains tools for parsing docker log lines.
*/
package logs
// Package logdetails contains tools for parsing docker log lines.
package logdetails

import (
"errors"
"net/url"
"strings"

"github.com/pkg/errors"
)

// ParseLogDetails parses a string of key value pairs in the form
// Parse parses a string of key value pairs in the form
// "k=v,l=w", where the keys and values are url query escaped, and each pair
// is separated by a comma. Returns a map of the key value pairs on success,
// and an error if the details string is not in a valid format.
//
// The details string encoding is implemented in
// github.com/moby/moby/api/server/httputils/write_log_stream.go
func ParseLogDetails(details string) (map[string]string, error) {
func Parse(details string) (map[string]string, error) {
pairs := strings.Split(details, ",")
detailsMap := make(map[string]string, len(pairs))
for _, pair := range pairs {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package logs
package logdetails

import (
"testing"
Expand All @@ -7,7 +7,7 @@ import (
is "gotest.tools/v3/assert/cmp"
)

func TestParseLogDetails(t *testing.T) {
func TestParse(t *testing.T) {
testCases := []struct {
line string
expected map[string]string
Expand Down Expand Up @@ -48,9 +48,9 @@ func TestParseLogDetails(t *testing.T) {
}
for _, tc := range testCases {
t.Run(tc.line, func(t *testing.T) {
actual, err := ParseLogDetails(tc.line)
actual, err := Parse(tc.line)
if tc.expectedErr != "" {
assert.Check(t, is.ErrorContains(err, tc.expectedErr))
assert.Check(t, is.Error(err, tc.expectedErr))
} else {
assert.Check(t, err)
}
Expand Down