Selaa lähdekoodia

intorude logs --timestamp

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 4 vuotta sitten
vanhempi
sitoutus
c25fd5689e
3 muutettua tiedostoa jossa 13 lisäystä ja 8 poistoa
  1. 4 3
      api/compose/api.go
  2. 7 4
      cli/cmd/compose/logs.go
  3. 2 1
      local/compose/logs.go

+ 4 - 3
api/compose/api.go

@@ -178,9 +178,10 @@ type ServiceStatus struct {
 
 // LogOptions defines optional parameters for the `Log` API
 type LogOptions struct {
-	Services []string
-	Tail     string
-	Follow   bool
+	Services   []string
+	Tail       string
+	Follow     bool
+	Timestamps bool
 }
 
 const (

+ 7 - 4
cli/cmd/compose/logs.go

@@ -31,10 +31,11 @@ import (
 type logsOptions struct {
 	*projectOptions
 	composeOptions
-	follow   bool
-	tail     string
-	noColor  bool
-	noPrefix bool
+	follow     bool
+	tail       string
+	noColor    bool
+	noPrefix   bool
+	timestamps bool
 }
 
 func logsCommand(p *projectOptions, contextType string) *cobra.Command {
@@ -52,6 +53,7 @@ func logsCommand(p *projectOptions, contextType string) *cobra.Command {
 	flags.BoolVar(&opts.follow, "follow", false, "Follow log output.")
 	flags.BoolVar(&opts.noColor, "no-color", false, "Produce monochrome output.")
 	flags.BoolVar(&opts.noPrefix, "no-log-prefix", false, "Don't print prefix in logs.")
+	flags.BoolVarP(&opts.timestamps, "timestamps", "t", false, "Show timestamps.")
 
 	if contextType == store.DefaultContextType {
 		flags.StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs for each container.")
@@ -74,5 +76,6 @@ func runLogs(ctx context.Context, opts logsOptions, services []string) error {
 		Services: services,
 		Follow:   opts.follow,
 		Tail:     opts.tail,
+		Timestamps: opts.timestamps,
 	})
 }

+ 2 - 1
local/compose/logs.go

@@ -68,6 +68,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
 				ShowStderr: true,
 				Follow:     options.Follow,
 				Tail:       options.Tail,
+				Timestamps: options.Timestamps,
 			})
 			defer r.Close() // nolint errcheck
 
@@ -76,7 +77,7 @@ func (s *composeService) Logs(ctx context.Context, projectName string, consumer
 			}
 			name := getContainerNameWithoutProject(c)
 			w := utils.GetWriter(name, service, c.ID, func(event compose.ContainerEvent) {
-				consumer.Log(event.Service, event.Name, event.Line)
+				consumer.Log(name, event.Name, event.Line)
 			})
 			if container.Config.Tty {
 				_, err = io.Copy(w, r)