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
019ca75f
Commit
019ca75f
authored
Dec 15, 2014
by
jhadvig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Streaming container logs
parent
5ef34bf5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
6 deletions
+21
-6
log.go
pkg/kubectl/cmd/log.go
+21
-6
No files found.
pkg/kubectl/cmd/log.go
View file @
019ca75f
...
...
@@ -18,15 +18,22 @@ package cmd
import
(
"io"
"strconv"
"github.com/spf13/cobra"
)
func
(
f
*
Factory
)
NewCmdLog
(
out
io
.
Writer
)
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"log <pod> [<container>]"
,
Use
:
"log
[-f]
<pod> [<container>]"
,
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
Examples:
$ kubectl log 123456-7890 ruby-container
<returns snapshot of ruby-container logs from pod 123456-7890>
$ kubectl log -f 123456-7890 ruby-container
<starts streaming of ruby-container logs from pod 123456-7890>`
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
if
len
(
args
)
==
0
{
usageError
(
cmd
,
"<pod> is required for log"
)
...
...
@@ -57,19 +64,27 @@ func (f *Factory) NewCmdLog(out io.Writer) *cobra.Command {
container
=
args
[
1
]
}
data
,
err
:=
client
.
RESTClient
.
Get
()
.
follow
:=
false
if
GetFlagBool
(
cmd
,
"follow"
)
{
follow
=
true
}
readCloser
,
err
:=
client
.
RESTClient
.
Get
()
.
Path
(
"proxy/minions"
)
.
Path
(
pod
.
Status
.
Host
)
.
Path
(
"containerLogs"
)
.
Path
(
namespace
)
.
Path
(
podID
)
.
Path
(
container
)
.
Do
(
)
.
Raw
()
Param
(
"follow"
,
strconv
.
FormatBool
(
follow
)
)
.
Stream
()
checkErr
(
err
)
out
.
Write
(
data
)
defer
readCloser
.
Close
()
_
,
err
=
io
.
Copy
(
out
,
readCloser
)
checkErr
(
err
)
},
}
cmd
.
Flags
()
.
BoolP
(
"follow"
,
"f"
,
false
,
"Specify if the logs should be streamed."
)
return
cmd
}
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