-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logger: skip ANSI color commands if output is not a tty #744
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@aviddiviner Open your pull request against |
f263a35
to
70ada0c
Compare
Current coverage is 93.08% (diff: 100%)@@ develop #744 diff @@
==========================================
Files 15 15
Lines 1268 1273 +5
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
+ Hits 1180 1185 +5
Misses 76 76
Partials 12 12
|
@appleboy Sure, done. |
Any news on this? |
LGTM |
appleboy
approved these changes
Nov 30, 2016
tboerger
approved these changes
Nov 30, 2016
Also LGTM |
@aviddiviner Thanks. |
javierprovecho
added a commit
that referenced
this pull request
Dec 3, 2016
This reverts commit 19f271c.
@aviddiviner we reverted this PR since |
appleboy
pushed a commit
that referenced
this pull request
Feb 1, 2017
appleboy
pushed a commit
that referenced
this pull request
May 29, 2017
* Revert "Merge pull request #753 from gin-gonic/bug" This reverts commit 556287f, reversing changes made to 32cab50. * Revert "Merge pull request #744 from aviddiviner/logger-fix" This reverts commit c3bfd69, reversing changes made to 9177f01. * add custom Delims support * add some test for Delims * remove the empty line for import native package * remove unuseful comments
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here's a little improvement to the default logger so that the output isn't colorised if we're not outputting to a terminal. So, if we run with
./server | tee my.log
then instead of my log file looking like this:It looks like this:
The same applies to any pipe. You can see this in action by just running
./server | cat
This does add an extra dependency on
golang.org/x/crypto/ssh/terminal
but it's pretty widely used and stable. I did consider copying over theIsTerminal
function, but there's a bit of tricky syscall magic there and I'd rather they take care of it.The other change I could think you might want to do, is assume that it's not a terminal if it isn't a valid
*os.File
, so change line 50 to:That might be nice for people funnelling their logs off to other random
io.Writer
s that don't want the ANSI code spam. But I've just kinda left it as it is for now.Let me know what you think! Thanks 😄