From 9d0cd25897fb92bbf16cb99d4e822f3b3976dae6 Mon Sep 17 00:00:00 2001 From: Jason Webster Date: Thu, 19 Jul 2018 12:24:39 -0400 Subject: [PATCH] Do not colorize output destined for configured logger This changes the predicate supplied to the #colorize method to ensure that if a logger is set, the colorizing ANSI escape codes are not applied. This definitely appears to have been the intention behind the original implementation, but the tests didn't reflect how .log_internal was actually called. In reality, it is always supplied with an `out:` argument, not nil. This caused all logger bound output to also be colorized. --- lib/stripe/util.rb | 2 +- test/stripe/util_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stripe/util.rb b/lib/stripe/util.rb index e959f6de7..3d5f4d734 100644 --- a/lib/stripe/util.rb +++ b/lib/stripe/util.rb @@ -396,7 +396,7 @@ def self.level_name(level) def self.log_internal(message, data = {}, color: nil, level: nil, logger: nil, out: nil) data_str = data.reject { |_k, v| v.nil? } .map do |(k, v)| - format("%s=%s", colorize(k, color, !out.nil? && out.isatty), wrap_logfmt_value(v)) + format("%s=%s", colorize(k, color, logger.nil? && !out.nil? && out.isatty), wrap_logfmt_value(v)) end.join(" ") if !logger.nil? diff --git a/test/stripe/util_test.rb b/test/stripe/util_test.rb index a36ea1ede..d694dad7e 100644 --- a/test/stripe/util_test.rb +++ b/test/stripe/util_test.rb @@ -396,7 +396,7 @@ def isatty } Util.send(:log_internal, "message", { foo: "bar" }, - color: :green, level: Stripe::LEVEL_DEBUG, logger: logger, out: nil) + color: :green, level: Stripe::LEVEL_DEBUG, logger: logger, out: $stdout) assert_equal "message=message foo=bar", out.string end