Skip to content

Commit d596d3d

Browse files
committed
fix: use *string for detailPrefix
Signed-off-by: Ruihua Wen <[email protected]>
1 parent 5f5a7b0 commit d596d3d

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

pkg/cmd/container/logs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func Logs(ctx context.Context, client *containerd.Client, container string, opti
105105
}
106106
}
107107

108-
detailPrefix := ""
108+
var detailPrefix string
109109
if options.Details {
110110
if logConfigJSON, ok := l["nerdctl/log-config"]; ok {
111111
type logConfig struct {
@@ -154,7 +154,7 @@ func Logs(ctx context.Context, client *containerd.Client, container string, opti
154154
Since: options.Since,
155155
Until: options.Until,
156156
Details: options.Details,
157-
DetailPrefix: detailPrefix,
157+
DetailPrefix: &detailPrefix,
158158
}
159159
logViewer, err := logging.InitContainerLogViewer(l, logViewOpts, stopChannel, options.GOptions.Experimental)
160160
if err != nil {

pkg/logging/log_viewer.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type LogViewOptions struct {
8787
Details bool
8888

8989
// DetailPrefix is the prefix added when Details is enabled.
90-
DetailPrefix string
90+
DetailPrefix *string
9191
}
9292

9393
func (lvo *LogViewOptions) Validate() error {
@@ -157,13 +157,12 @@ func InitContainerLogViewer(containerLabels map[string]string, lvopts LogViewOpt
157157
// Prints all logs for this LogViewer's containers to the provided io.Writers.
158158
func (lv *ContainerLogViewer) PrintLogsTo(stdout, stderr io.Writer) error {
159159
if lv.logViewingOptions.Details {
160-
prefix := " "
161-
if lv.logViewingOptions.DetailPrefix != "" {
162-
prefix = lv.logViewingOptions.DetailPrefix + " "
160+
if lv.logViewingOptions.DetailPrefix != nil {
161+
prefix := *lv.logViewingOptions.DetailPrefix + " "
162+
stdout = NewDetailWriter(stdout, prefix)
163+
stderr = NewDetailWriter(stderr, prefix)
163164
}
164165

165-
stdout = NewDetailWriter(stdout, prefix)
166-
stderr = NewDetailWriter(stderr, prefix)
167166
}
168167
viewerFunc, err := getLogViewer(lv.loggingConfig.Driver)
169168
if err != nil {

0 commit comments

Comments
 (0)