Skip to content

Commit

Permalink
Log Rewards errors by default and add a feature flag for verbose logging
Browse files Browse the repository at this point in the history
  • Loading branch information
zenparsing committed Apr 26, 2021
1 parent ae298c6 commit 2b5b7b4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 26 deletions.
4 changes: 4 additions & 0 deletions chromium_src/chrome/browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ using ntp_background_images::features::kBraveNTPSuperReferralWallpaper;
flag_descriptions::kBravePermissionLifetimeName, \
flag_descriptions::kBravePermissionLifetimeDescription, kOsAll, \
FEATURE_VALUE_TYPE(permissions::features::kPermissionLifetime)}, \
{"brave-rewards-verbose-logging", \
flag_descriptions::kBraveRewardsVerboseLoggingName, \
flag_descriptions::kBraveRewardsVerboseLoggingDescription, kOsDesktop, \
FEATURE_VALUE_TYPE(brave_rewards::features::kVerboseLoggingFeature)}, \
{"brave-rewards-bitflyer", \
flag_descriptions::kBraveRewardsBitflyerName, \
flag_descriptions::kBraveRewardsBitflyerDescription, kOsDesktop, \
Expand Down
4 changes: 4 additions & 0 deletions chromium_src/chrome/browser/flag_descriptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const char kBraveSyncDescription[] =
const char kBraveIpfsName[] = "Enable IPFS";
const char kBraveIpfsDescription[] =
"Enable native support of IPFS.";
const char kBraveRewardsVerboseLoggingName[] =
"Enable Brave Rewards verbose logging";
const char kBraveRewardsVerboseLoggingDescription[] =
"Enables detailed logging of Brave Rewards system events to a log file";
const char kBraveRewardsBitflyerName[] = "Enable bitFlyer for Brave Rewards";
const char kBraveRewardsBitflyerDescription[] =
"Enables support for bitFlyer as an external wallet provider for Brave "
Expand Down
2 changes: 2 additions & 0 deletions chromium_src/chrome/browser/flag_descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ extern const char kBraveSyncName[];
extern const char kBraveSyncDescription[];
extern const char kBraveIpfsName[];
extern const char kBraveIpfsDescription[];
extern const char kBraveRewardsVerboseLoggingName[];
extern const char kBraveRewardsVerboseLoggingDescription[];
extern const char kBraveRewardsBitflyerName[];
extern const char kBraveRewardsBitflyerDescription[];
extern const char kNativeBraveWalletName[];
Expand Down
20 changes: 10 additions & 10 deletions components/brave_rewards/browser/rewards_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ RewardsServiceImpl::RewardsServiceImpl(Profile* profile)
content::URLDataSource::Add(profile_,
std::make_unique<BraveRewardsSource>(profile_));
ready_ = std::make_unique<base::OneShotEvent>();

if (base::FeatureList::IsEnabled(features::kVerboseLoggingFeature))
persist_log_level_ = kDiagnosticLogMaxVerboseLevel;
}

RewardsServiceImpl::~RewardsServiceImpl() {
Expand Down Expand Up @@ -2263,15 +2266,12 @@ void RewardsServiceImpl::WriteDiagnosticLog(const std::string& file,
const int line,
const int verbose_level,
const std::string& message) {
if (ledger_for_testing_ || !should_persist_logs_) {
return;
}

if (resetting_rewards_) {
if (ledger_for_testing_ || resetting_rewards_) {
return;
}

if (verbose_level > kDiagnosticLogMaxVerboseLevel) {
if (verbose_level > kDiagnosticLogMaxVerboseLevel ||
verbose_level > persist_log_level_) {
return;
}

Expand Down Expand Up @@ -2414,13 +2414,13 @@ void RewardsServiceImpl::HandleFlags(const std::string& options) {
continue;
}

// The "persist-logs" command-line flag is deprecated and will be removed
// in a future version. Use --enable-features=BraveRewardsVerboseLogging
// instead.
if (name == "persist-logs") {
const std::string lower = base::ToLowerASCII(value);

if (lower == "true" || lower == "1") {
should_persist_logs_ = true;
} else {
should_persist_logs_ = false;
persist_log_level_ = kDiagnosticLogMaxVerboseLevel;
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/brave_rewards/browser/rewards_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ class RewardsServiceImpl : public RewardsService,
bool reset_states_;
bool ledger_for_testing_ = false;
bool resetting_rewards_ = false;
bool should_persist_logs_ = false;
int persist_log_level_ = 0;

GetTestResponseCallback test_response_callback_;

Expand Down
3 changes: 3 additions & 0 deletions components/brave_rewards/common/features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ namespace features {
const base::Feature kBitflyerFeature{"BraveRewardsBitflyer",
base::FEATURE_DISABLED_BY_DEFAULT};

const base::Feature kVerboseLoggingFeature{"BraveRewardsVerboseLogging",
base::FEATURE_DISABLED_BY_DEFAULT};

} // namespace features
} // namespace brave_rewards
1 change: 1 addition & 0 deletions components/brave_rewards/common/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace brave_rewards {
namespace features {

extern const base::Feature kBitflyerFeature;
extern const base::Feature kVerboseLoggingFeature;

} // namespace features
} // namespace brave_rewards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "bat/ledger/internal/logging/logging.h"
#include "url/gurl.h"

namespace ledger {

Expand Down Expand Up @@ -99,12 +100,15 @@ void LogUrlResponse(
const char* func,
const type::UrlResponse& response,
const bool long_response) {
bool is_error = false;
std::string result;
if (!response.error.empty()) {
is_error = true;
result = "Error (" + response.error + ")";
} else if (response.status_code >= 200 && response.status_code < 300) {
result = "Success";
} else {
is_error = true;
result = "Failure";
}

Expand All @@ -115,25 +119,20 @@ void LogUrlResponse(
}

const std::string response_basic = base::StringPrintf(
"\n[ RESPONSE - %s ]\n"
"> Url: %s\n"
"\n[ RESPONSE ]\n"
"> URL: %s\n"
"> Result: %s\n"
"> HTTP Code: %d\n"
"> Body: %s",
func,
response.url.c_str(),
result.c_str(),
response.status_code,
response.body.c_str());
"> HTTP Code: %d",
response.url.c_str(), result.c_str(), response.status_code);

const std::string response_body =
base::StringPrintf("\n[ RESPONSE BODY ]\n%s", response.body.c_str());

const std::string response_headers = base::StringPrintf(
"\n[ RESPONSE HEADERS ]\n"
"> Url: %s\n"
"%s",
response.url.c_str(),
formatted_headers.c_str());
"\n[ RESPONSE HEADERS ]\n%s", formatted_headers.c_str());

BLOG(long_response ? 7 : 6, response_basic);
BLOG(is_error ? 0 : 6, response_basic);
BLOG(long_response ? 7 : 6, response_body);
BLOG(9, response_headers);
}

Expand Down

0 comments on commit 2b5b7b4

Please sign in to comment.