Skip to content
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

IsTerm flag should not be affected by DisableConsoleColor method. #1802

Merged
merged 4 commits into from Mar 18, 2019

Conversation

sairoutine
Copy link
Contributor

@sairoutine sairoutine commented Mar 8, 2019

It is strange behavior that DisableConsoleColor turns the IsTerm flag false.

This PR contains the following changes.

  • IsTerm represents whether is the output destination console.
  • Default logger distinguishes color by using new method IsOutputColor.
  • If ForceConsoleColor and DisableConsoleColor are called together, Later one is valid.

Note
This change breaks backward compability, but LogFormatterParams and ForceConsoleColor is not released yet. This change affects only the user which is using master branch.

magenta = string([]byte{27, 91, 57, 55, 59, 52, 53, 109})
cyan = string([]byte{27, 91, 57, 55, 59, 52, 54, 109})
reset = string([]byte{27, 91, 48, 109})
consoleColorMode = autoColor
Copy link
Contributor Author

@sairoutine sairoutine Mar 8, 2019

Choose a reason for hiding this comment

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

What happens if ForceConsoleColor would be called after DisableConsoleColor?
This change makes the behavior easy understanding and the source code readable.

@codecov
Copy link

codecov bot commented Mar 8, 2019

Codecov Report

Merging #1802 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1802      +/-   ##
==========================================
+ Coverage   98.64%   98.64%   +<.01%     
==========================================
  Files          41       41              
  Lines        2145     2146       +1     
==========================================
+ Hits         2116     2117       +1     
  Misses         18       18              
  Partials       11       11
Impacted Files Coverage Δ
logger.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c16bfa7...6fb6e0b. Read the comment docs.

@thinkerou
Copy link
Member

About color I think that have only two case:

  1. Not use color, even isTerm=true.
  2. Use color, need isTerm=true.
    so we only need one switch to indicate whether use color.
    Default use color when isTerm=true, or not use.

@sairoutine
Copy link
Contributor Author

@thinkerou
Your suggested usecases are true. Therefore, the following usecases are seldom occured.

  • If ForceConsoleColor and DisableConsoleColor are called together, Later one is valid.

This PR's purposes are two things.

  • It is strange behavior that DisableConsoleColor turns the IsTerm flag false.
  • disableColor and forceColor are redundant variables. To consolidate into consoleColorMode makes gin's code more readable.

@thinkerou
Copy link
Member

@sairoutine I hope simple.
gin default use color on Term mode.
If user calls gin.DisableConsoleColor(), not use color.

@sairoutine
Copy link
Contributor Author

@thinkerou

gin default use color on Term mode.
If user calls gin.DisableConsoleColor(), not use color.

This PR does not change this behavior.

If the user does not call gin.DisableConsoleColor() or gin.ForceConsoleColor(), gin decides to use color by Term mode.

If the user calls gin.DisableConsoleColor(), gin does not use color whatever isTerm=true or isTerm=false.

@thinkerou
Copy link
Member

@sairoutine

This PR does not change this behavior.

Yes, I know. So I hope change it release gin1.4 before. do you think? thanks!

@thinkerou thinkerou added this to the 1.4 milestone Mar 15, 2019
@sairoutine
Copy link
Contributor Author

@thinkerou
Thanks! I also think this PR should be merged before gin 1.4 release.

@thinkerou
Copy link
Member

@sairoutine I hope the pull request change to:

gin default use color on Term mode.
If user calls gin.DisableConsoleColor(), not use color.
can you recommit one patch? thanks!

@sairoutine
Copy link
Contributor Author

@thinkerou
It seems that this PR is according to this. Could you tell me what should I do?

gin default use color on Term mode.
If user calls gin.DisableConsoleColor(), not use color.
can you recommit one patch? thanks!

@thinkerou
Copy link
Member

@sairoutine OK, I see #1724 content about forceConsoleColor, you not need to do what. Thanks!

thinkerou
thinkerou previously approved these changes Mar 15, 2019
@sairoutine
Copy link
Contributor Author

sairoutine commented Mar 15, 2019

Thank your for your reviewing! Yes, This PR is related to #1724.

logger.go Outdated Show resolved Hide resolved
@thinkerou thinkerou merged commit b40d4c1 into gin-gonic:master Mar 18, 2019
@sairoutine sairoutine deleted the change_isterm_method branch March 18, 2019 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants