Skip to content

Comments

Allow IsTerminal passthrough for SyncLogger#482

Closed
ereOn wants to merge 1 commit intogo-kit:masterfrom
ereOn:isterminal_passthrough
Closed

Allow IsTerminal passthrough for SyncLogger#482
ereOn wants to merge 1 commit intogo-kit:masterfrom
ereOn:isterminal_passthrough

Conversation

@ereOn
Copy link

@ereOn ereOn commented Mar 6, 2017

The current implementation of IsTerminal does not properly work when stdout or stderr are used through a SyncLogger.

This PR adresses that by defining and implementing a new interface for the SyncWriter that exposes the encapsulated io.Writer. This new interface is then used inside term.go which now performs the IsTerminal check on the deepest io.Writer instead.

This ensures transivity of the IsTerminal attribute.

There is no API break, tests are passing and a new test was added to cover the new interface.

ChildWriter() io.Writer
}

func resolveWriter(w io.Writer) io.Writer {
Copy link
Author

@ereOn ereOn Mar 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This method is a pass-through for all io.Writer instances that do not implement the parentWriter interface, thus not breaking the existing behavior.

@ereOn ereOn force-pushed the isterminal_passthrough branch from c3518d9 to 20900b3 Compare March 7, 2017 00:25
@ChrisHines
Copy link
Member

Sorry it has taken me a few days to get back to this.

The solution here seems straightforward at first glance. However ... it points out the more general issue that passing any decorated io.Writer to IsTerminal causes it to return false. For example bufio.NewWriter(os.Stdout) also tricks IsTerminal. So even if we merge this PR there is still a problem with IsTerminal(log.NewSyncWriter(bufio.NewWriter(os.Stdout))). I'm not sure how I feel about this being only a partial fix.

Aside from the above I'm not crazy about the method name ChildWriter. I like WrappedWriter slightly better, but I'm not sold on that either. Suggestions anyone?

@ereOn
Copy link
Author

ereOn commented Mar 11, 2017

@ChrisHines No problem about the delay !

I agree that the proposed solution does not account for all cases but I would still distinguish external types and types provided by go-kit.

For the first ones, it's harder (impossible ?) to make any guarantee on their exposed interface. For instance, in your example there is just no way to get the underlying io.Writer even if we detect the correct instance type: bufio.Writer just doesn't offer that possibility.

For the go-kit provided types, I'd say it's another deal because we do control exactly how they behave and what they expose.

I agree that added the support for any Writer is a nice ultimate goal, but this scoped change still has some consistency in its own I believe.

As for the name, I'm not too fond of ChildWriter either to be honest. What do you think of:

  • WriterWrapper - It is indeed, after all, an interface for all Writer instances that wrap another one.
  • CompositeWrapper
  • NestedWrapper

@ereOn
Copy link
Author

ereOn commented Mar 15, 2017

@ChrisHines ping ?

@ChrisHines
Copy link
Member

Ping received, server overloaded at the moment. ;)

I haven't forgotten about this, just too busy this week.

@ereOn
Copy link
Author

ereOn commented Mar 15, 2017

@ChrisHines No worries. I just wanted to make sure my PR had not fallen into a crack. :D

I understand being busy, trust me ;)

@ereOn
Copy link
Author

ereOn commented Mar 22, 2017

Closing in favor or #501 which addresses the problem in a less intrusive manner.

@ereOn ereOn closed this Mar 22, 2017
@ereOn ereOn deleted the isterminal_passthrough branch March 22, 2017 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants