Skip to content

Commit

Permalink
Merge pull request #154 from sungam3r/nocolor
Browse files Browse the repository at this point in the history
Support NO_COLOR environment variable
  • Loading branch information
nblumhardt authored Mar 17, 2024
2 parents 1f0919e + cf2c80d commit 1c35ad9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public static LoggerConfiguration Console(
if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (outputTemplate is null) throw new ArgumentNullException(nameof(outputTemplate));

var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) ?
// see https://no-color.org/
var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) || !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NO_COLOR")) ?
ConsoleTheme.None :
theme ?? SystemConsoleThemes.Literate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ public static LoggerConfiguration Console(
IFormatProvider? formatProvider = null,
LoggingLevelSwitch? levelSwitch = null,
LogEventLevel? standardErrorFromLevel = null,
ConsoleTheme? theme = null,
ConsoleTheme? theme = null,
bool applyThemeToRedirectedOutput = false,
object? syncRoot = null)
{
if (sinkConfiguration is null) throw new ArgumentNullException(nameof(sinkConfiguration));
if (outputTemplate is null) throw new ArgumentNullException(nameof(outputTemplate));

var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) ?
// see https://no-color.org/
var appliedTheme = !applyThemeToRedirectedOutput && (System.Console.IsOutputRedirected || System.Console.IsErrorRedirected) || !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NO_COLOR")) ?
ConsoleTheme.None :
theme ?? SystemConsoleThemes.Literate;

Expand Down

0 comments on commit 1c35ad9

Please sign in to comment.