mirror of
https://github.com/cuigh/swirl
synced 2024-12-28 23:02:02 +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,37 +520,30 @@ 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 (
|
||||
rc io.ReadCloser
|
||||
buf []byte
|
||||
)
|
||||
opts := types.ContainerLogsOptions{
|
||||
ShowStdout: true,
|
||||
ShowStderr: true,
|
||||
Tail: strconv.Itoa(line),
|
||||
Timestamps: timestamps,
|
||||
//Since: (time.Hour * 24).String()
|
||||
}
|
||||
if rc, err = cli.ServiceLogs(ctx, name, opts); err == nil {
|
||||
defer rc.Close()
|
||||
var (
|
||||
ctx context.Context
|
||||
cli *client.Client
|
||||
rc io.ReadCloser
|
||||
)
|
||||
|
||||
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()
|
||||
}
|
||||
ctx, cli, err = mgr.Client()
|
||||
if err != nil {
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
opts := types.ContainerLogsOptions{
|
||||
ShowStdout: true,
|
||||
ShowStderr: true,
|
||||
Tail: strconv.Itoa(line),
|
||||
Timestamps: timestamps,
|
||||
//Since: (time.Hour * 24).String()
|
||||
}
|
||||
if rc, err = cli.ServiceLogs(ctx, name, opts); err == nil {
|
||||
defer rc.Close()
|
||||
|
||||
stdout = &bytes.Buffer{}
|
||||
stderr = &bytes.Buffer{}
|
||||
_, err = stdcopy.StdCopy(stdout, stderr, rc)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ type Setting struct {
|
||||
UpdatedAt time.Time `bson:"updated_at" json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
func Test() {
|
||||
func Test() {
|
||||
time.Now().Zone()
|
||||
}
|
||||
|
@ -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