summaryrefslogtreecommitdiff
path: root/cmd/podman/logs.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-04-16 14:04:58 -0700
committerGitHub <noreply@github.com>2020-04-16 14:04:58 -0700
commit0d2b5532c417c58bd24e71a56c5c55b43e423a59 (patch)
tree4001e8e47a022bb1b9bfbf2332c42e1aeb802f9e /cmd/podman/logs.go
parent88c6fd06cd54fb9a8826306dfdf1a77e400de5de (diff)
parent241326a9a8c20ad7f2bcf651416b836e7778e090 (diff)
downloadpodman-0d2b5532c417c58bd24e71a56c5c55b43e423a59.tar.gz
podman-0d2b5532c417c58bd24e71a56c5c55b43e423a59.tar.bz2
podman-0d2b5532c417c58bd24e71a56c5c55b43e423a59.zip
Merge pull request #5852 from baude/v1prune
Podman V2 birth
Diffstat (limited to 'cmd/podman/logs.go')
-rw-r--r--cmd/podman/logs.go93
1 files changed, 0 insertions, 93 deletions
diff --git a/cmd/podman/logs.go b/cmd/podman/logs.go
deleted file mode 100644
index 0a86fa128..000000000
--- a/cmd/podman/logs.go
+++ /dev/null
@@ -1,93 +0,0 @@
-package main
-
-import (
- "time"
-
- "github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/libpod/logs"
- "github.com/containers/libpod/pkg/adapter"
- "github.com/containers/libpod/pkg/util"
- "github.com/pkg/errors"
- "github.com/spf13/cobra"
-)
-
-var (
- logsCommand cliconfig.LogsValues
- logsDescription = `Retrieves logs for one or more containers.
-
- This does not guarantee execution order when combined with podman run (i.e. your run may not have generated any logs at the time you execute podman logs).
-`
- _logsCommand = &cobra.Command{
- Use: "logs [flags] CONTAINER [CONTAINER...]",
- Short: "Fetch the logs of a container",
- Long: logsDescription,
- RunE: func(cmd *cobra.Command, args []string) error {
- logsCommand.InputArgs = args
- logsCommand.GlobalFlags = MainGlobalOpts
- logsCommand.Remote = remoteclient
- return logsCmd(&logsCommand)
- },
- Args: func(cmd *cobra.Command, args []string) error {
- if len(args) > 0 && logsCommand.Latest {
- return errors.New("no containers can be specified when using 'latest'")
- }
- if !logsCommand.Latest && len(args) < 1 {
- return errors.New("specify at least one container name or ID to log")
- }
- return nil
- },
- Example: `podman logs ctrID
- podman logs --names ctrID1 ctrID2
- podman logs --tail 2 mywebserver
- podman logs --follow=true --since 10m ctrID
- podman logs mywebserver mydbserver`,
- }
-)
-
-func init() {
- logsCommand.Command = _logsCommand
- logsCommand.SetHelpTemplate(HelpTemplate())
- logsCommand.SetUsageTemplate(UsageTemplate())
- flags := logsCommand.Flags()
- flags.BoolVar(&logsCommand.Details, "details", false, "Show extra details provided to the logs")
- flags.BoolVarP(&logsCommand.Follow, "follow", "f", false, "Follow log output. The default is false")
- flags.BoolVarP(&logsCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
- flags.StringVar(&logsCommand.Since, "since", "", "Show logs since TIMESTAMP")
- flags.Int64Var(&logsCommand.Tail, "tail", -1, "Output the specified number of LINES at the end of the logs. Defaults to -1, which prints all lines")
- flags.BoolVarP(&logsCommand.Timestamps, "timestamps", "t", false, "Output the timestamps in the log")
- flags.BoolVarP(&logsCommand.UseName, "names", "n", false, "Output the container name in the log")
- markFlagHidden(flags, "details")
- flags.SetInterspersed(false)
-
- markFlagHiddenForRemoteClient("latest", flags)
-}
-
-func logsCmd(c *cliconfig.LogsValues) error {
- var err error
-
- runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand)
- if err != nil {
- return errors.Wrapf(err, "could not get runtime")
- }
- defer runtime.DeferredShutdown(false)
-
- sinceTime := time.Time{}
- if c.Flag("since").Changed {
- // parse time, error out if something is wrong
- since, err := util.ParseInputTime(c.Since)
- if err != nil {
- return errors.Wrapf(err, "could not parse time: %q", c.Since)
- }
- sinceTime = since
- }
-
- options := &logs.LogOptions{
- Details: c.Details,
- Follow: c.Follow,
- Since: sinceTime,
- Tail: c.Tail,
- Timestamps: c.Timestamps,
- UseName: c.UseName,
- }
- return runtime.Log(c, options)
-}