mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fix debug logger output (#458)
our dear friend mr. funclogger was bypassing calls to our multi writer since we were embedding a *bytes.Buffer, it was using ReadFrom and WriteString which would never call the stderr logger's Write method (or, as I learned, other things trying to wrap that buffer's Write method...). the tl;dr is many times DEBUG lines don't get spat out, from async tasks especially (few people using this). I think the final solution is probably to make funclogger a 'more robust' interface that we understand instead of trying to minimize it to an io.ReaderWriterCloser, much like how bytes.Buffer has all kinds of methods implemented on it, we can implement things like ReadFrom and WriteString most likely. not a big fan of how things are now (and it's my own doing) with the readerwritercloser coming from multiple places but meh, will get to it some day soon, the log stuff will be a pretty hot path.
This commit is contained in:
committed by
Travis Reeder
parent
6e2b711676
commit
7ba2dc005e
@@ -48,15 +48,20 @@ func setupLogger(logger logrus.FieldLogger) io.ReadWriteCloser {
|
|||||||
return &rwc{mw, dbuf}
|
return &rwc{mw, dbuf}
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements io.ReadWriteCloser, keeps the buffer for all its handy methods
|
// implements io.ReadWriteCloser, fmt.Stringer and Bytes()
|
||||||
|
// TODO WriteString and ReadFrom would be handy to implement,
|
||||||
|
// ReadFrom is a little involved.
|
||||||
type rwc struct {
|
type rwc struct {
|
||||||
io.WriteCloser
|
io.WriteCloser
|
||||||
*bytes.Buffer
|
|
||||||
|
// buffer is not embedded since it would bypass calls to WriteCloser.Write
|
||||||
|
// in cases such as WriteString and ReadFrom
|
||||||
|
b *bytes.Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
// these are explicit to override the *bytes.Buffer's methods
|
func (r *rwc) Read(b []byte) (int, error) { return r.b.Read(b) }
|
||||||
func (r *rwc) Write(b []byte) (int, error) { return r.WriteCloser.Write(b) }
|
func (r *rwc) String() string { return r.b.String() }
|
||||||
func (r *rwc) Close() error { return r.WriteCloser.Close() }
|
func (r *rwc) Bytes() []byte { return r.b.Bytes() }
|
||||||
|
|
||||||
// implements passthrough Write & closure call in Close
|
// implements passthrough Write & closure call in Close
|
||||||
type fCloser struct {
|
type fCloser struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user