Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ecaf0874
Commit
ecaf0874
authored
Apr 22, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce --previous option to kubectl log
parent
35c644a4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
2 deletions
+25
-2
kubectl
contrib/completions/bash/kubectl
+2
-0
kubectl_log.md
docs/kubectl_log.md
+5
-1
kubectl-log.1
docs/man/man1/kubectl-log.1
+7
-0
log.go
pkg/kubectl/cmd/log.go
+11
-1
No files found.
contrib/completions/bash/kubectl
View file @
ecaf0874
...
@@ -404,6 +404,8 @@ _kubectl_log()
...
@@ -404,6 +404,8 @@ _kubectl_log()
flags+
=(
"--help"
)
flags+
=(
"--help"
)
flags+
=(
"-h"
)
flags+
=(
"-h"
)
flags+
=(
"--interactive"
)
flags+
=(
"--interactive"
)
flags+
=(
"--previous"
)
flags+
=(
"-p"
)
must_have_one_flag
=()
must_have_one_flag
=()
must_have_one_noun
=()
must_have_one_noun
=()
...
...
docs/kubectl_log.md
View file @
ecaf0874
...
@@ -8,7 +8,7 @@ Print the logs for a container in a pod.
...
@@ -8,7 +8,7 @@ Print the logs for a container in a pod.
Print the logs for a container in a pod. If the pod has only one container, the container name is optional.
Print the logs for a container in a pod. If the pod has only one container, the container name is optional.
```
```
kubectl log [-f] POD [CONTAINER]
kubectl log [-f]
[-p]
POD [CONTAINER]
```
```
### Examples
### Examples
...
@@ -17,6 +17,9 @@ kubectl log [-f] POD [CONTAINER]
...
@@ -17,6 +17,9 @@ kubectl log [-f] POD [CONTAINER]
// Returns snapshot of ruby-container logs from pod 123456-7890.
// Returns snapshot of ruby-container logs from pod 123456-7890.
$ kubectl log 123456-7890 ruby-container
$ kubectl log 123456-7890 ruby-container
// Returns snapshot of previous terminated ruby-container logs from pod 123456-7890.
$ kubectl log -p 123456-7890 ruby-container
// Starts streaming of ruby-container logs from pod 123456-7890.
// Starts streaming of ruby-container logs from pod 123456-7890.
$ kubectl log -f 123456-7890 ruby-container
$ kubectl log -f 123456-7890 ruby-container
```
```
...
@@ -27,6 +30,7 @@ $ kubectl log -f 123456-7890 ruby-container
...
@@ -27,6 +30,7 @@ $ kubectl log -f 123456-7890 ruby-container
-f, --follow=false: Specify if the logs should be streamed.
-f, --follow=false: Specify if the logs should be streamed.
-h, --help=false: help for log
-h, --help=false: help for log
--interactive=true: If true, prompt the user for input when required. Default true.
--interactive=true: If true, prompt the user for input when required. Default true.
-p, --previous=false: If true, print the logs for the previous instance of the container in a pod if it exists.
```
```
### Options inherited from parent commands
### Options inherited from parent commands
...
...
docs/man/man1/kubectl-log.1
View file @
ecaf0874
...
@@ -29,6 +29,10 @@ Print the logs for a container in a pod. If the pod has only one container, the
...
@@ -29,6 +29,10 @@ Print the logs for a container in a pod. If the pod has only one container, the
\fB\-\-interactive\fP=true
\fB\-\-interactive\fP=true
If true, prompt the user for input when required. Default true.
If true, prompt the user for input when required. Default true.
.PP
\fB\-p\fP, \fB\-\-previous\fP=false
If true, print the logs for the previous instance of the container in a pod if it exists.
.SH OPTIONS INHERITED FROM PARENT COMMANDS
.SH OPTIONS INHERITED FROM PARENT COMMANDS
.PP
.PP
...
@@ -140,6 +144,9 @@ Print the logs for a container in a pod. If the pod has only one container, the
...
@@ -140,6 +144,9 @@ Print the logs for a container in a pod. If the pod has only one container, the
// Returns snapshot of ruby\-container logs from pod 123456\-7890.
// Returns snapshot of ruby\-container logs from pod 123456\-7890.
$ kubectl log 123456\-7890 ruby\-container
$ kubectl log 123456\-7890 ruby\-container
// Returns snapshot of previous terminated ruby\-container logs from pod 123456\-7890.
$ kubectl log \-p 123456\-7890 ruby\-container
// Starts streaming of ruby\-container logs from pod 123456\-7890.
// Starts streaming of ruby\-container logs from pod 123456\-7890.
$ kubectl log \-f 123456\-7890 ruby\-container
$ kubectl log \-f 123456\-7890 ruby\-container
...
...
pkg/kubectl/cmd/log.go
View file @
ecaf0874
...
@@ -31,6 +31,9 @@ const (
...
@@ -31,6 +31,9 @@ const (
log_example
=
`// Returns snapshot of ruby-container logs from pod 123456-7890.
log_example
=
`// Returns snapshot of ruby-container logs from pod 123456-7890.
$ kubectl log 123456-7890 ruby-container
$ kubectl log 123456-7890 ruby-container
// Returns snapshot of previous terminated ruby-container logs from pod 123456-7890.
$ kubectl log -p 123456-7890 ruby-container
// Starts streaming of ruby-container logs from pod 123456-7890.
// Starts streaming of ruby-container logs from pod 123456-7890.
$ kubectl log -f 123456-7890 ruby-container`
$ kubectl log -f 123456-7890 ruby-container`
)
)
...
@@ -60,7 +63,7 @@ func selectContainer(pod *api.Pod, in io.Reader, out io.Writer) string {
...
@@ -60,7 +63,7 @@ func selectContainer(pod *api.Pod, in io.Reader, out io.Writer) string {
// NewCmdLog creates a new pod log command
// NewCmdLog creates a new pod log command
func
NewCmdLog
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
)
*
cobra
.
Command
{
func
NewCmdLog
(
f
*
cmdutil
.
Factory
,
out
io
.
Writer
)
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"log [-f] POD [CONTAINER]"
,
Use
:
"log [-f]
[-p]
POD [CONTAINER]"
,
Short
:
"Print the logs for a container in a pod."
,
Short
:
"Print the logs for a container in a pod."
,
Long
:
"Print the logs for a container in a pod. If the pod has only one container, the container name is optional."
,
Long
:
"Print the logs for a container in a pod. If the pod has only one container, the container name is optional."
,
Example
:
log_example
,
Example
:
log_example
,
...
@@ -71,6 +74,7 @@ func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command {
...
@@ -71,6 +74,7 @@ func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command {
}
}
cmd
.
Flags
()
.
BoolP
(
"follow"
,
"f"
,
false
,
"Specify if the logs should be streamed."
)
cmd
.
Flags
()
.
BoolP
(
"follow"
,
"f"
,
false
,
"Specify if the logs should be streamed."
)
cmd
.
Flags
()
.
Bool
(
"interactive"
,
true
,
"If true, prompt the user for input when required. Default true."
)
cmd
.
Flags
()
.
Bool
(
"interactive"
,
true
,
"If true, prompt the user for input when required. Default true."
)
cmd
.
Flags
()
.
BoolP
(
"previous"
,
"p"
,
false
,
"If true, print the logs for the previous instance of the container in a pod if it exists."
)
return
cmd
return
cmd
}
}
...
@@ -115,6 +119,11 @@ func RunLog(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
...
@@ -115,6 +119,11 @@ func RunLog(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
follow
=
true
follow
=
true
}
}
previous
:=
false
if
cmdutil
.
GetFlagBool
(
cmd
,
"previous"
)
{
previous
=
true
}
readCloser
,
err
:=
client
.
RESTClient
.
Get
()
.
readCloser
,
err
:=
client
.
RESTClient
.
Get
()
.
Namespace
(
namespace
)
.
Namespace
(
namespace
)
.
Name
(
podID
)
.
Name
(
podID
)
.
...
@@ -122,6 +131,7 @@ func RunLog(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
...
@@ -122,6 +131,7 @@ func RunLog(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []string
SubResource
(
"log"
)
.
SubResource
(
"log"
)
.
Param
(
"follow"
,
strconv
.
FormatBool
(
follow
))
.
Param
(
"follow"
,
strconv
.
FormatBool
(
follow
))
.
Param
(
"container"
,
container
)
.
Param
(
"container"
,
container
)
.
Param
(
"previous"
,
strconv
.
FormatBool
(
previous
))
.
Stream
()
Stream
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment