Skip to content

Commit b550c01

Browse files
committed
refactor log
1 parent 5ec30b7 commit b550c01

File tree

3 files changed

+16
-43
lines changed

3 files changed

+16
-43
lines changed

engine/virt/virt.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ func (v *Virt) Info(ctx context.Context) (*enginetypes.Info, error) {
7575

7676
// Execute executes a command in vm
7777
func (v *Virt) Execute(ctx context.Context, ID string, config *enginetypes.ExecConfig) (pid string, stdout, stderr io.ReadCloser, stdin io.WriteCloser, err error) {
78-
log.Debugf(ctx, "execute opts on %s: %v", ID, config)
79-
defer log.Debugf(ctx, "execute opts done")
8078
if config.Tty {
8179
flags := virttypes.AttachGuestFlags{Safe: true, Force: true}
8280
stream, err := v.client.AttachGuest(ctx, ID, config.Cmd, flags)
@@ -155,7 +153,7 @@ func (v *Virt) NetworkList(ctx context.Context, drivers []string) (nets []*engin
155153

156154
// BuildRefs builds references, it's not necessary for virt. presently.
157155
func (v *Virt) BuildRefs(ctx context.Context, name string, tags []string) (refs []string) {
158-
log.Warnf(ctx, "BuildRefs does not implement")
156+
log.Warn(ctx, "BuildRefs does not implement")
159157
return
160158
}
161159

@@ -195,7 +193,7 @@ func (v *Virt) VirtualizationCreate(ctx context.Context, opts *enginetypes.Virtu
195193
// VirtualizationResourceRemap .
196194
func (v *Virt) VirtualizationResourceRemap(ctx context.Context, opts *enginetypes.VirtualizationRemapOptions) (<-chan enginetypes.VirtualizationRemapMessage, error) {
197195
// VM does not support binding cores.
198-
log.Debugf(ctx, "virtualizationResourceRemap is not supported by vm")
196+
log.Warn(ctx, "virtualizationResourceRemap is not supported by vm")
199197
ch := make(chan enginetypes.VirtualizationRemapMessage)
200198
defer close(ch)
201199
return ch, nil
@@ -247,12 +245,15 @@ func (v *Virt) VirtualizationInspect(ctx context.Context, ID string) (*enginetyp
247245

248246
// VirtualizationLogs streams a specific guest's log.
249247
func (v *Virt) VirtualizationLogs(ctx context.Context, opts *enginetypes.VirtualizationLogStreamOptions) (stdout io.ReadCloser, stderr io.ReadCloser, err error) {
250-
msg, err := v.client.Log(ctx, 15, opts.ID)
251-
if err != nil {
252-
return nil, nil, err
248+
n := -1
249+
if opts.Tail != "all" {
250+
if n, err = strconv.Atoi(opts.Tail); err != nil {
251+
return nil, nil, err
252+
}
253253
}
254-
reader := ioutil.NopCloser(strings.NewReader(strings.Join(msg, "\n")))
255-
return reader, nil, nil
254+
255+
stream, err := v.client.Log(ctx, n, opts.ID)
256+
return stream, nil, err
256257
}
257258

258259
// VirtualizationAttach attaches something to a guest.

go.mod

+4
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ require (
5252
google.golang.org/grpc v1.40.0
5353
google.golang.org/protobuf v1.27.1
5454
)
55+
56+
replace (
57+
github.com/projecteru2/libyavirt => github.com/aceralon/libyavirt v0.0.0-20211109071112-0af23cfc1636
58+
)

0 commit comments

Comments
 (0)