Merge pull request #1323 from docker/timestamp

introduce logs --timestamp
This commit is contained in:
Nicolas De loof 2021-02-18 19:41:05 +01:00 committed by GitHub
commit 32fdd08485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

View File

@ -181,6 +181,7 @@ type LogOptions struct {
Services []string Services []string
Tail string Tail string
Follow bool Follow bool
Timestamps bool
} }
const ( const (

View File

@ -35,6 +35,7 @@ type logsOptions struct {
tail string tail string
noColor bool noColor bool
noPrefix bool noPrefix bool
timestamps bool
} }
func logsCommand(p *projectOptions, contextType string) *cobra.Command { 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.follow, "follow", false, "Follow log output.")
flags.BoolVar(&opts.noColor, "no-color", false, "Produce monochrome 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.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 { if contextType == store.DefaultContextType {
flags.StringVar(&opts.tail, "tail", "all", "Number of lines to show from the end of the logs for each container.") 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, Services: services,
Follow: opts.follow, Follow: opts.follow,
Tail: opts.tail, Tail: opts.tail,
Timestamps: opts.timestamps,
}) })
} }

View File

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