mirror of
https://github.com/cuigh/swirl
synced 2024-12-30 15:53:24 +00:00
Improve service logs
This commit is contained in:
parent
6ce9d3358e
commit
4a549e156f
@ -245,6 +245,14 @@ dd {
|
||||
border-top-right-radius: 0 !important;
|
||||
}
|
||||
|
||||
.code {
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
textarea.code{
|
||||
padding: 0.75em;
|
||||
}
|
||||
|
||||
.CodeMirror {
|
||||
font-size: 0.8em;
|
||||
border: 1px solid #ddd;
|
||||
|
@ -1,19 +1,15 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"io"
|
||||
|
||||
"bufio"
|
||||
"bytes"
|
||||
|
||||
"strconv"
|
||||
|
||||
"github.com/cuigh/swirl/misc"
|
||||
"github.com/cuigh/swirl/model"
|
||||
"github.com/docker/docker/api/types"
|
||||
@ -21,6 +17,7 @@ import (
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
)
|
||||
|
||||
// ServiceList return service list.
|
||||
@ -523,11 +520,17 @@ func ServiceRemove(name string) error {
|
||||
|
||||
// ServiceLogs returns the logs generated by a service.
|
||||
func ServiceLogs(name string, line int, timestamps bool) (stdout, stderr *bytes.Buffer, err error) {
|
||||
err = mgr.Do(func(ctx context.Context, cli *client.Client) (err error) {
|
||||
var (
|
||||
ctx context.Context
|
||||
cli *client.Client
|
||||
rc io.ReadCloser
|
||||
buf []byte
|
||||
)
|
||||
|
||||
ctx, cli, err = mgr.Client()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
opts := types.ContainerLogsOptions{
|
||||
ShowStdout: true,
|
||||
ShowStderr: true,
|
||||
@ -540,20 +543,7 @@ func ServiceLogs(name string, line int, timestamps bool) (stdout, stderr *bytes.
|
||||
|
||||
stdout = &bytes.Buffer{}
|
||||
stderr = &bytes.Buffer{}
|
||||
scanner := bufio.NewScanner(rc)
|
||||
for scanner.Scan() {
|
||||
buf = scanner.Bytes()
|
||||
if buf[0] == 1 {
|
||||
stdout.Write(buf[8:])
|
||||
stdout.WriteByte('\n')
|
||||
} else if buf[0] == 2 {
|
||||
stdout.Write(buf[8:])
|
||||
stdout.WriteByte('\n')
|
||||
}
|
||||
}
|
||||
err = scanner.Err()
|
||||
_, err = stdcopy.StdCopy(stdout, stderr, rc)
|
||||
}
|
||||
return
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" href="/lyicon/css/lyicon.css">
|
||||
<link rel="stylesheet" href="/bulma/bulma.css?v=0.5.2">
|
||||
<link rel="stylesheet" href="/bulma/bulma.css?v=0.5.3">
|
||||
<link rel="stylesheet" href="/swirl/css/swirl.css?v={{ version }}">
|
||||
{{ block style() }}{{end}}
|
||||
</head>
|
||||
|
@ -4,7 +4,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="stylesheet" href="/lyicon/css/lyicon.css">
|
||||
<link rel="stylesheet" href="/bulma/bulma.css?v=0.5.2">
|
||||
<link rel="stylesheet" href="/bulma/bulma.css?v=0.5.3">
|
||||
<link rel="stylesheet" href="/swirl/css/swirl.css?v={{ version }}">
|
||||
</head>
|
||||
<body>
|
||||
|
@ -77,7 +77,7 @@
|
||||
</form>
|
||||
</nav>
|
||||
|
||||
<div class="tabs is-toggle is-fullwidth is-marginless" data-target="tab-content">
|
||||
<div class="tabs is-boxed" data-target="tab-content">
|
||||
<ul>
|
||||
<li class="is-active">
|
||||
<a><span>Stdout</span></a>
|
||||
@ -88,8 +88,16 @@
|
||||
</ul>
|
||||
</div>
|
||||
<div id="tab-content" class="content">
|
||||
<pre class="is-marginless" style="max-height: 600px; padding: 0.75em">{{ .Stdout }}</pre>
|
||||
<pre class="is-marginless" style="max-height: 600px; padding: 0.75em; display: none">{{ .Stderr }}</pre>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
{{ if .Stdout }}<textarea class="textarea code is-small" rows="30" readonly>{{ .Stdout }}</textarea>{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="field" style="display: none">
|
||||
<div class="control">
|
||||
{{ if .Stderr }}<textarea class="textarea code is-small" rows="30" readonly>{{ .Stderr }}</textarea>{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<a href="/service/" class="button is-primary">
|
||||
<span class="icon"><i class="fa fa-reply"></i></span>
|
||||
|
Loading…
Reference in New Issue
Block a user