fix log hanging issue, and implement close-notify for commands
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Oct 29, 2015 at 21:26 UTC
2f5563b3c0059c7bec1ab3896fe7e62315083b21
20 files changed
+23
-710
Godeps/Godeps.json
-4
@@ -144,10 +144,6 @@
144
"ImportPath": "github.com/inconshreveable/go-update",
145
"Rev": "68f5725818189545231c1fd8694793d45f2fc529"
146
},
147
- {
148
- "ImportPath": "github.com/ipfs/go-log",
149
- "Rev": "bf32e06c2f9c81eb33460bc08305aa946f0d893d"
150
- },
147
{
148
"ImportPath": "github.com/jackpal/go-nat-pmp",
149
"Rev": "a45aa3d54aef73b504e15eb71bea0e5565b5e6e1"
Godeps/_workspace/src/github.com/ipfs/go-log/.gxlastpubver
deleted
-1
@@ -1 +0,0 @@
1
-QmTBXYb6y2ZcJmoXVKk3pf9rzSEjbCg7tQaJW7RSuH14nv
\ No newline at end of file
Godeps/_workspace/src/github.com/ipfs/go-log/context.go
deleted
-38
@@ -1,38 +0,0 @@
1
-package log
2
-
3
-import (
4
- "errors"
5
-
6
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
7
-)
8
-
9
-type key int
10
-
11
-const metadataKey key = 0
12
-
13
-// ContextWithLoggable returns a derived context which contains the provided
14
-// Loggable. Any Events logged with the derived context will include the
15
-// provided Loggable.
16
-func ContextWithLoggable(ctx context.Context, l Loggable) context.Context {
17
- existing, err := MetadataFromContext(ctx)
18
- if err != nil {
19
- // context does not contain meta. just set the new metadata
20
- child := context.WithValue(ctx, metadataKey, Metadata(l.Loggable()))
21
- return child
22
- }
23
-
24
- merged := DeepMerge(existing, l.Loggable())
25
- child := context.WithValue(ctx, metadataKey, merged)
26
- return child
27
-}
28
-
29
-func MetadataFromContext(ctx context.Context) (Metadata, error) {
30
- value := ctx.Value(metadataKey)
31
- if value != nil {
32
- metadata, ok := value.(Metadata)
33
- if ok {
34
- return metadata, nil
35
- }
36
- }
37
- return nil, errors.New("context contains no metadata")
38
-}
Godeps/_workspace/src/github.com/ipfs/go-log/context_test.go
deleted
-44
@@ -1,44 +0,0 @@
1
-package log
2
-
3
-import (
4
- "testing"
5
-
6
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
7
-)
8
-
9
-func TestContextContainsMetadata(t *testing.T) {
10
- t.Parallel()
11
-
12
- m := Metadata{"foo": "bar"}
13
- ctx := ContextWithLoggable(context.Background(), m)
14
- got, err := MetadataFromContext(ctx)
15
- if err != nil {
16
- t.Fatal(err)
17
- }
18
-
19
- _, exists := got["foo"]
20
- if !exists {
21
- t.Fail()
22
- }
23
-}
24
-
25
-func TestContextWithPreexistingMetadata(t *testing.T) {
26
- t.Parallel()
27
-
28
- ctx := ContextWithLoggable(context.Background(), Metadata{"hello": "world"})
29
- ctx = ContextWithLoggable(ctx, Metadata{"goodbye": "earth"})
30
-
31
- got, err := MetadataFromContext(ctx)
32
- if err != nil {
33
- t.Fatal(err)
34
- }
35
-
36
- _, exists := got["hello"]
37
- if !exists {
38
- t.Fatal("original key not present")
39
- }
40
- _, exists = got["goodbye"]
41
- if !exists {
42
- t.Fatal("new key not present")
43
- }
44
-}
Godeps/_workspace/src/github.com/ipfs/go-log/entry.go
deleted
-7
@@ -1,7 +0,0 @@
1
-package log
2
-
3
-type entry struct {
4
- loggables []Loggable
5
- system string
6
- event string
7
-}
Godeps/_workspace/src/github.com/ipfs/go-log/example_test.go
deleted
-16
@@ -1,16 +0,0 @@
1
-package log
2
-
3
-import "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
4
-
5
-func ExampleEventLogger() {
6
- {
7
- log := EventLogger(nil)
8
- e := log.EventBegin(context.Background(), "dial")
9
- e.Done()
10
- }
11
- {
12
- log := EventLogger(nil)
13
- e := log.EventBegin(context.Background(), "dial")
14
- _ = e.Close() // implements io.Closer for convenience
15
- }
16
-}
Godeps/_workspace/src/github.com/ipfs/go-log/log.go
deleted
-170
@@ -1,170 +0,0 @@
1
-package log
2
-
3
-import (
4
- "encoding/json"
5
- "fmt"
6
- "time"
7
-
8
- context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
9
-)
10
-
11
-// StandardLogger provides API compatibility with standard printf loggers
12
-// eg. go-logging
13
-type StandardLogger interface {
14
- Debug(args ...interface{})
15
- Debugf(format string, args ...interface{})
16
- Error(args ...interface{})
17
- Errorf(format string, args ...interface{})
18
- Fatal(args ...interface{})
19
- Fatalf(format string, args ...interface{})
20
- Info(args ...interface{})
21
- Infof(format string, args ...interface{})
22
- Panic(args ...interface{})
23
- Panicf(format string, args ...interface{})
24
- Warning(args ...interface{})
25
- Warningf(format string, args ...interface{})
26
-}
27
-
28
-// EventLogger extends the StandardLogger interface to allow for log items
29
-// containing structured metadata
30
-type EventLogger interface {
31
- StandardLogger
32
-
33
- // Event merges structured data from the provided inputs into a single
34
- // machine-readable log event.
35
- //
36
- // If the context contains metadata, a copy of this is used as the base
37
- // metadata accumulator.
38
- //
39
- // If one or more loggable objects are provided, these are deep-merged into base blob.
40
- //
41
- // Next, the event name is added to the blob under the key "event". If
42
- // the key "event" already exists, it will be over-written.
43
- //
44
- // Finally the timestamp and package name are added to the accumulator and
45
- // the metadata is logged.
46
- Event(ctx context.Context, event string, m ...Loggable)
47
-
48
- EventBegin(ctx context.Context, event string, m ...Loggable) *EventInProgress
49
-}
50
-
51
-// Logger retrieves an event logger by name
52
-func Logger(system string) EventLogger {
53
-
54
- // TODO if we would like to adjust log levels at run-time. Store this event
55
- // logger in a map (just like the util.Logger impl)
56
- if len(system) == 0 {
57
- setuplog := getLogger("setup-logger")
58
- setuplog.Warning("Missing name parameter")
59
- system = "undefined"
60
- }
61
-
62
- logger := getLogger(system)
63
-
64
- return &eventLogger{system: system, StandardLogger: logger}
65
-}
66
-
67
-// eventLogger implements the EventLogger and wraps a go-logging Logger
68
-type eventLogger struct {
69
- StandardLogger
70
-
71
- system string
72
- // TODO add log-level
73
-}
74
-
75
-func (el *eventLogger) EventBegin(ctx context.Context, event string, metadata ...Loggable) *EventInProgress {
76
- start := time.Now()
77
- el.Event(ctx, fmt.Sprintf("%sBegin", event), metadata...)
78
-
79
- eip := &EventInProgress{}
80
- eip.doneFunc = func(additional []Loggable) {
81
-
82
- metadata = append(metadata, additional...) // anything added during the operation
83
- metadata = append(metadata, LoggableMap(map[string]interface{}{ // finally, duration of event
84
- "duration": time.Now().Sub(start),
85
- }))
86
-
87
- el.Event(ctx, event, metadata...)
88
- }
89
- return eip
90
-}
91
-
92
-func (el *eventLogger) Event(ctx context.Context, event string, metadata ...Loggable) {
93
-
94
- // short circuit if theres nothing to write to
95
- if !WriterGroup.Active() {
96
- return
97
- }
98
-
99
- // Collect loggables for later logging
100
- var loggables []Loggable
101
-
102
- // get any existing metadata from the context
103
- existing, err := MetadataFromContext(ctx)
104
- if err != nil {
105
- existing = Metadata{}
106
- }
107
- loggables = append(loggables, existing)
108
-
109
- for _, datum := range metadata {
110
- loggables = append(loggables, datum)
111
- }
112
-
113
- e := entry{
114
- loggables: loggables,
115
- system: el.system,
116
- event: event,
117
- }
118
-
119
- accum := Metadata{}
120
- for _, loggable := range e.loggables {
121
- accum = DeepMerge(accum, loggable.Loggable())
122
- }
123
-
124
- // apply final attributes to reserved keys
125
- // TODO accum["level"] = level
126
- accum["event"] = e.event
127
- accum["system"] = e.system
128
- accum["time"] = FormatRFC3339(time.Now())
129
-
130
- out, err := json.Marshal(accum)
131
- if err != nil {
132
- el.Errorf("ERROR FORMATTING EVENT ENTRY: %s", err)
133
- return
134
- }
135
-
136
- WriterGroup.Write(append(out, '\n'))
137
-}
138
-
139
-type EventInProgress struct {
140
- loggables []Loggable
141
- doneFunc func([]Loggable)
142
-}
143
-
144
-// Append adds loggables to be included in the call to Done
145
-func (eip *EventInProgress) Append(l Loggable) {
146
- eip.loggables = append(eip.loggables, l)
147
-}
148
-
149
-// SetError includes the provided error
150
-func (eip *EventInProgress) SetError(err error) {
151
- eip.loggables = append(eip.loggables, LoggableMap{
152
- "error": err.Error(),
153
- })
154
-}
155
-
156
-// Done creates a new Event entry that includes the duration and appended
157
-// loggables.
158
-func (eip *EventInProgress) Done() {
159
- eip.doneFunc(eip.loggables) // create final event with extra data
160
-}
161
-
162
-// Close is an alias for done
163
-func (eip *EventInProgress) Close() error {
164
- eip.Done()
165
- return nil
166
-}
167
-
168
-func FormatRFC3339(t time.Time) string {
169
- return t.UTC().Format(time.RFC3339Nano)
170
-}
Godeps/_workspace/src/github.com/ipfs/go-log/loggable.go
deleted
-34
@@ -1,34 +0,0 @@
1
-package log
2
-
3
-// Loggable describes objects that can be marshalled into Metadata for logging
4
-type Loggable interface {
5
- Loggable() map[string]interface{}
6
-}
7
-
8
-type LoggableMap map[string]interface{}
9
-
10
-func (l LoggableMap) Loggable() map[string]interface{} {
11
- return l
12
-}
13
-
14
-// LoggableF converts a func into a Loggable
15
-type LoggableF func() map[string]interface{}
16
-
17
-func (l LoggableF) Loggable() map[string]interface{} {
18
- return l()
19
-}
20
-
21
-func Deferred(key string, f func() string) Loggable {
22
- function := func() map[string]interface{} {
23
- return map[string]interface{}{
24
- key: f(),
25
- }
26
- }
27
- return LoggableF(function)
28
-}
29
-
30
-func Pair(key string, l Loggable) Loggable {
31
- return LoggableMap{
32
- key: l,
33
- }
34
-}
Godeps/_workspace/src/github.com/ipfs/go-log/metadata.go
deleted
-82
@@ -1,82 +0,0 @@
1
-package log
2
-
3
-import (
4
- "encoding/json"
5
- "errors"
6
- "reflect"
7
-
8
- "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/satori/go.uuid"
9
-)
10
-
11
-// Metadata is a convenience type for generic maps
12
-type Metadata map[string]interface{}
13
-
14
-// Uuid returns a Metadata with the string key and UUID value
15
-func Uuid(key string) Metadata {
16
- return Metadata{
17
- key: uuid.NewV4().String(),
18
- }
19
-}
20
-
21
-// DeepMerge merges the second Metadata parameter into the first.
22
-// Nested Metadata are merged recursively. Primitives are over-written.
23
-func DeepMerge(b, a Metadata) Metadata {
24
- out := Metadata{}
25
- for k, v := range b {
26
- out[k] = v
27
- }
28
- for k, v := range a {
29
-
30
- maybe, err := Metadatify(v)
31
- if err != nil {
32
- // if the new value is not meta. just overwrite the dest vaue
33
- out[k] = v
34
- continue
35
- }
36
-
37
- // it is meta. What about dest?
38
- outv, exists := out[k]
39
- if !exists {
40
- // the new value is meta, but there's no dest value. just write it
41
- out[k] = v
42
- continue
43
- }
44
-
45
- outMetadataValue, err := Metadatify(outv)
46
- if err != nil {
47
- // the new value is meta and there's a dest value, but the dest
48
- // value isn't meta. just overwrite
49
- out[k] = v
50
- continue
51
- }
52
-
53
- // both are meta. merge them.
54
- out[k] = DeepMerge(outMetadataValue, maybe)
55
- }
56
- return out
57
-}
58
-
59
-// Loggable implements the Loggable interface
60
-func (m Metadata) Loggable() map[string]interface{} {
61
- // NB: method defined on value to avoid de-referencing nil Metadata
62
- return m
63
-}
64
-
65
-func (m Metadata) JsonString() (string, error) {
66
- // NB: method defined on value
67
- b, err := json.Marshal(m)
68
- return string(b), err
69
-}
70
-
71
-// Metadatify converts maps into Metadata
72
-func Metadatify(i interface{}) (Metadata, error) {
73
- value := reflect.ValueOf(i)
74
- if value.Kind() == reflect.Map {
75
- m := map[string]interface{}{}
76
- for _, k := range value.MapKeys() {
77
- m[k.String()] = value.MapIndex(k).Interface()
78
- }
79
- return Metadata(m), nil
80
- }
81
- return nil, errors.New("is not a map")
82
-}
Godeps/_workspace/src/github.com/ipfs/go-log/metadata_test.go
deleted
-50
@@ -1,50 +0,0 @@
1
-package log
2
-
3
-import "testing"
4
-
5
-func TestOverwrite(t *testing.T) {
6
- t.Parallel()
7
-
8
- under := Metadata{
9
- "a": Metadata{
10
- "b": Metadata{
11
- "c": Metadata{
12
- "d": "the original value",
13
- "other": "SURVIVE",
14
- },
15
- },
16
- },
17
- }
18
- over := Metadata{
19
- "a": Metadata{
20
- "b": Metadata{
21
- "c": Metadata{
22
- "d": "a new value",
23
- },
24
- },
25
- },
26
- }
27
-
28
- out := DeepMerge(under, over)
29
-
30
- dval := out["a"].(Metadata)["b"].(Metadata)["c"].(Metadata)["d"].(string)
31
- if dval != "a new value" {
32
- t.Fatal(dval)
33
- }
34
- surv := out["a"].(Metadata)["b"].(Metadata)["c"].(Metadata)["other"].(string)
35
- if surv != "SURVIVE" {
36
- t.Fatal(surv)
37
- }
38
-}
39
-
40
-func TestMarshalJSON(t *testing.T) {
41
- t.Parallel()
42
- bs, _ := Metadata{"a": "b"}.JsonString()
43
- t.Log(bs)
44
-}
45
-
46
-func TestMetadataIsLoggable(t *testing.T) {
47
- t.Parallel()
48
- func(l Loggable) {
49
- }(Metadata{})
50
-}
Godeps/_workspace/src/github.com/ipfs/go-log/oldlog.go
deleted
-104
@@ -1,104 +0,0 @@
1
-package log
2
-
3
-import (
4
- "errors"
5
- "os"
6
-
7
- logging "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/go-logging"
8
-)
9
-
10
-func init() {
11
- SetupLogging()
12
-}
13
-
14
-var ansiGray = "\033[0;37m"
15
-var ansiBlue = "\033[0;34m"
16
-
17
-var LogFormats = map[string]string{
18
- "nocolor": "%{time:2006-01-02 15:04:05.000000} %{level} %{module} %{shortfile}: %{message}",
19
- "color": ansiGray + "%{time:15:04:05.000} %{color}%{level:5.5s} " + ansiBlue +
20
- "%{module:10.10s}: %{color:reset}%{message} " + ansiGray + "%{shortfile}%{color:reset}",
21
-}
22
-
23
-var defaultLogFormat = "color"
24
-
25
-// Logging environment variables
26
-const (
27
- envLogging = "IPFS_LOGGING"
28
- envLoggingFmt = "IPFS_LOGGING_FMT"
29
-)
30
-
31
-// ErrNoSuchLogger is returned when the util pkg is asked for a non existant logger
32
-var ErrNoSuchLogger = errors.New("Error: No such logger")
33
-
34
-// loggers is the set of loggers in the system
35
-var loggers = map[string]*logging.Logger{}
36
-
37
-// SetupLogging will initialize the logger backend and set the flags.
38
-func SetupLogging() {
39
-
40
- fmt := LogFormats[os.Getenv(envLoggingFmt)]
41
- if fmt == "" {
42
- fmt = LogFormats[defaultLogFormat]
43
- }
44
-
45
- backend := logging.NewLogBackend(os.Stderr, "", 0)
46
- logging.SetBackend(backend)
47
- logging.SetFormatter(logging.MustStringFormatter(fmt))
48
-
49
- lvl := logging.ERROR
50
-
51
- if logenv := os.Getenv(envLogging); logenv != "" {
52
- var err error
53
- lvl, err = logging.LogLevel(logenv)
54
- if err != nil {
55
-
56
- }
57
- }
58
-
59
- SetAllLoggers(lvl)
60
-}
61
-
62
-// SetDebugLogging calls SetAllLoggers with logging.DEBUG
63
-func SetDebugLogging() {
64
- SetAllLoggers(logging.DEBUG)
65
-}
66
-
67
-// SetAllLoggers changes the logging.Level of all loggers to lvl
68
-func SetAllLoggers(lvl logging.Level) {
69
- logging.SetLevel(lvl, "")
70
- for n := range loggers {
71
- logging.SetLevel(lvl, n)
72
- }
73
-}
74
-
75
-// SetLogLevel changes the log level of a specific subsystem
76
-// name=="*" changes all subsystems
77
-func SetLogLevel(name, level string) error {
78
- lvl, err := logging.LogLevel(level)
79
- if err != nil {
80
- return err
81
- }
82
-
83
- // wildcard, change all
84
- if name == "*" {
85
- SetAllLoggers(lvl)
86
- return nil
87
- }
88
-
89
- // Check if we have a logger by that name
90
- if _, ok := loggers[name]; !ok {
91
- return ErrNoSuchLogger
92
- }
93
-
94
- logging.SetLevel(lvl, name)
95
-
96
- return nil
97
-}
98
-
99
-func getLogger(name string) *logging.Logger {
100
- log := logging.MustGetLogger(name)
101
- log.ExtraCalldepth = 1
102
- loggers[name] = log
103
- return log
104
-}
Godeps/_workspace/src/github.com/ipfs/go-log/option.go
deleted
-62
@@ -1,62 +0,0 @@
1
-package log
2
-
3
-import (
4
- "io"
5
- "os"
6
-
7
- logging "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/go-logging"
8
-)
9
-
10
-// init sets up sane defaults
11
-func init() {
12
- Configure(TextFormatter)
13
- Configure(Output(os.Stderr))
14
- // has the effect of disabling logging since we log event entries at Info
15
- // level by convention
16
- Configure(LevelError)
17
-}
18
-
19
-// Global writer group for logs to output to
20
-var WriterGroup = new(MirrorWriter)
21
-
22
-type Option func()
23
-
24
-// Configure applies the provided options sequentially from left to right
25
-func Configure(options ...Option) {
26
- for _, f := range options {
27
- f()
28
- }
29
-}
30
-
31
-// LdJSONFormatter Option formats the event log as line-delimited JSON
32
-var LdJSONFormatter = func() {
33
- logging.SetFormatter(&PoliteJSONFormatter{})
34
-}
35
-
36
-// TextFormatter Option formats the event log as human-readable plain-text
37
-var TextFormatter = func() {
38
- logging.SetFormatter(logging.DefaultFormatter)
39
-}
40
-
41
-func Output(w io.Writer) Option {
42
- return func() {
43
- backend := logging.NewLogBackend(w, "", 0)
44
- logging.SetBackend(backend)
45
- // TODO return previous Output option
46
- }
47
-}
48
-
49
-// LevelDebug Option sets the log level to debug
50
-var LevelDebug = func() {
51
- logging.SetLevel(logging.DEBUG, "")
52
-}
53
-
54
-// LevelError Option sets the log level to error
55
-var LevelError = func() {
56
- logging.SetLevel(logging.ERROR, "")
57
-}
58
-
59
-// LevelInfo Option sets the log level to info
60
-var LevelInfo = func() {
61
- logging.SetLevel(logging.INFO, "")
62
-}
Godeps/_workspace/src/github.com/ipfs/go-log/package.json
deleted
-5
@@ -1,5 +0,0 @@
1
-{
2
- "name": "go-log",
3
- "version": "1.0.0",
4
- "language": "go"
5
-}
\ No newline at end of file
Godeps/_workspace/src/github.com/ipfs/go-log/polite_json_formatter.go
deleted
-28
@@ -1,28 +0,0 @@
1
-package log
2
-
3
-import (
4
- "encoding/json"
5
- "io"
6
-
7
- logging "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/whyrusleeping/go-logging"
8
-)
9
-
10
-// PoliteJSONFormatter marshals entries into JSON encoded slices (without
11
-// overwriting user-provided keys). How polite of it!
12
-type PoliteJSONFormatter struct{}
13
-
14
-func (f *PoliteJSONFormatter) Format(calldepth int, r *logging.Record, w io.Writer) error {
15
- entry := make(map[string]interface{})
16
- entry["id"] = r.Id
17
- entry["level"] = r.Level
18
- entry["time"] = r.Time
19
- entry["module"] = r.Module
20
- entry["message"] = r.Message()
21
- err := json.NewEncoder(w).Encode(entry)
22
- if err != nil {
23
- return err
24
- }
25
-
26
- w.Write([]byte{'\n'})
27
- return nil
28
-}
Godeps/_workspace/src/github.com/ipfs/go-log/writer.go
deleted
-50
@@ -1,50 +0,0 @@
1
-package log
2
-
3
-import (
4
- "io"
5
- "sync"
6
-)
7
-
8
-type MirrorWriter struct {
9
- writers []io.Writer
10
- lk sync.Mutex
11
-}
12
-
13
-func (mw *MirrorWriter) Write(b []byte) (int, error) {
14
- mw.lk.Lock()
15
- // write to all writers, and nil out the broken ones.
16
- var dropped bool
17
- for i, w := range mw.writers {
18
- _, err := w.Write(b)
19
- if err != nil {
20
- mw.writers[i] = nil
21
- dropped = true
22
- }
23
- }
24
-
25
- // consolidate the slice
26
- if dropped {
27
- writers := mw.writers
28
- mw.writers = nil
29
- for _, w := range writers {
30
- if w != nil {
31
- mw.writers = append(mw.writers, w)
32
- }
33
- }
34
- }
35
- mw.lk.Unlock()
36
- return len(b), nil
37
-}
38
-
39
-func (mw *MirrorWriter) AddWriter(w io.Writer) {
40
- mw.lk.Lock()
41
- mw.writers = append(mw.writers, w)
42
- mw.lk.Unlock()
43
-}
44
-
45
-func (mw *MirrorWriter) Active() (active bool) {
46
- mw.lk.Lock()
47
- active = len(mw.writers) > 0
48
- mw.lk.Unlock()
49
- return
50
-}
Godeps/_workspace/src/github.com/jbenet/go-datastore/flatfs/flatfs.go
+1
-1
@@ -12,10 +12,10 @@ import (
12
"strings"
13
"time"
14
15
- logging "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-log"
15
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
16
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/query"
17
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-os-rename"
18
+ logging "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
19
)
20
21
var log = logging.Logger("flatfs")
commands/http/handler.go
+9
@@ -149,6 +149,15 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
149
150
ctx, cancel := context.WithCancel(node.Context())
151
defer cancel()
152
+ if cn, ok := w.(http.CloseNotifier); ok {
153
+ go func() {
154
+ select {
155
+ case <-cn.CloseNotify():
156
+ case <-ctx.Done():
157
+ }
158
+ cancel()
159
+ }()
160
+ }
161
162
err = req.SetRootContext(ctx)
163
if err != nil {
core/commands/log.go
+4
-3
@@ -77,12 +77,13 @@ var logTailCmd = &cmds.Command{
77
},
78
79
Run: func(req cmds.Request, res cmds.Response) {
80
+ ctx := req.Context()
81
r, w := io.Pipe()
81
- logging.WriterGroup.AddWriter(w)
82
go func() {
83
- <-req.Context().Done()
84
- w.Close()
83
+ defer w.Close()
84
+ <-ctx.Done()
85
}()
86
+ logging.WriterGroup.AddWriter(w)
87
res.SetOutput(r)
88
},
89
}
core/corehttp/logs.go
+9
-1
@@ -14,7 +14,7 @@ type writeErrNotifier struct {
14
errs chan error
15
}
16
17
-func newWriteErrNotifier(w io.Writer) (io.Writer, <-chan error) {
17
+func newWriteErrNotifier(w io.Writer) (io.WriteCloser, <-chan error) {
18
ch := make(chan error, 1)
19
return &writeErrNotifier{
20
w: w,
@@ -36,6 +36,14 @@ func (w *writeErrNotifier) Write(b []byte) (int, error) {
36
return n, err
37
}
38
39
+func (w *writeErrNotifier) Close() error {
40
+ select {
41
+ case w.errs <- io.EOF:
42
+ default:
43
+ }
44
+ return nil
45
+}
46
+
47
func LogOption() ServeOption {
48
return func(n *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
49
mux.HandleFunc("/logs", func(w http.ResponseWriter, r *http.Request) {
repo/fsrepo/fsrepo.go
-10
@@ -26,7 +26,6 @@ import (
26
u "github.com/ipfs/go-ipfs/util"
27
util "github.com/ipfs/go-ipfs/util"
28
ds2 "github.com/ipfs/go-ipfs/util/datastore2"
29
- logging "github.com/ipfs/go-ipfs/vendor/QmQg1J6vikuXF9oDvm4wpdeAUvvkVEKW1EYDw9HhTMnP2b/go-log"
29
)
30
31
// version number that we are currently expecting to see
@@ -159,9 +158,6 @@ func open(repoPath string) (repo.Repo, error) {
158
return nil, err
159
}
160
162
- // setup eventlogger
163
- configureEventLoggerAtRepoPath(r.config, r.path)
164
-
161
keepLocked = true
162
return r, nil
163
}
@@ -401,12 +397,6 @@ func (r *FSRepo) openDatastore() error {
397
return nil
398
}
399
404
-func configureEventLoggerAtRepoPath(c *config.Config, repoPath string) {
405
- logging.Configure(logging.LevelInfo)
406
- logging.Configure(logging.LdJSONFormatter)
407
- logging.Configure(logging.Output(logging.WriterGroup))
408
-}
409
-
400
// Close closes the FSRepo, releasing held resources.
401
func (r *FSRepo) Close() error {
402
packageLock.Lock()