Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2602068

Browse files
committedJul 29, 2015
fix log tail command
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent 681da0a commit 2602068

File tree

1 file changed

+6
-57
lines changed

1 file changed

+6
-57
lines changed
 

‎core/commands/log.go

+6-57
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ package commands
33
import (
44
"fmt"
55
"io"
6-
"strings"
76

87
cmds "github.com/ipfs/go-ipfs/commands"
8+
"github.com/ipfs/go-ipfs/thirdparty/eventlog"
99
u "github.com/ipfs/go-ipfs/util"
10-
11-
tail "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ActiveState/tail"
1210
)
1311

1412
// Golang os.Args overrides * and replaces the character argument with
@@ -80,61 +78,12 @@ var logTailCmd = &cmds.Command{
8078
},
8179

8280
Run: func(req cmds.Request, res cmds.Response) {
83-
path := fmt.Sprintf("%s/logs/events.log", req.InvocContext().ConfigRoot)
84-
85-
outChan := make(chan interface{})
86-
81+
r, w := io.Pipe()
82+
eventlog.WriterGroup.AddWriter(w)
8783
go func() {
88-
defer close(outChan)
89-
90-
t, err := tail.TailFile(path, tail.Config{
91-
Location: &tail.SeekInfo{0, 2},
92-
Follow: true,
93-
MustExist: true,
94-
Logger: tail.DiscardingLogger,
95-
})
96-
if err != nil {
97-
fmt.Println(err.Error())
98-
return
99-
}
100-
defer t.Stop()
101-
102-
done := req.Context().Done()
103-
104-
for line := range t.Lines {
105-
// return when context closes
106-
select {
107-
case <-done:
108-
return
109-
default:
110-
}
111-
112-
if line.Err != nil {
113-
fmt.Println(err.Error())
114-
return
115-
}
116-
// TODO: unpack the line text into a struct and output that
117-
outChan <- &MessageOutput{line.Text}
118-
}
84+
<-req.Context().Done()
85+
w.Close()
11986
}()
120-
121-
res.SetOutput((<-chan interface{})(outChan))
122-
},
123-
Marshalers: cmds.MarshalerMap{
124-
cmds.Text: func(res cmds.Response) (io.Reader, error) {
125-
outChan, ok := res.Output().(<-chan interface{})
126-
if !ok {
127-
return nil, u.ErrCast()
128-
}
129-
130-
return &cmds.ChannelMarshaler{
131-
Channel: outChan,
132-
Marshaler: func(v interface{}) (io.Reader, error) {
133-
output := v.(*MessageOutput)
134-
return strings.NewReader(output.Message + "\n"), nil
135-
},
136-
}, nil
137-
},
87+
res.SetOutput(r)
13888
},
139-
Type: MessageOutput{},
14089
}

0 commit comments

Comments
 (0)
Please sign in to comment.