From 1be54ebee13cf21bfcc36b0e2da1d72839fdf9d2 Mon Sep 17 00:00:00 2001 From: John Knox Date: Thu, 25 Oct 2018 04:12:54 -0700 Subject: [PATCH] Add optional debug log switch Summary: This won't affect runtime, but is useful when debugging issues with flipper itself. Setting this flag means all state changes will be output in logcat. Reviewed By: passy Differential Revision: D10231148 fbshipit-source-id: 7ddd490290ad973fc339b2f5f93a6f9a1fab4577 --- xplat/Flipper/FlipperState.cpp | 22 +++++++++++++++++----- xplat/Flipper/FlipperState.h | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/xplat/Flipper/FlipperState.cpp b/xplat/Flipper/FlipperState.cpp index df4240741..408e6d2ca 100644 --- a/xplat/Flipper/FlipperState.cpp +++ b/xplat/Flipper/FlipperState.cpp @@ -10,19 +10,25 @@ #include "FlipperStep.h" #include +#if FLIPPER_DEBUG_LOG +#include "Log.h" +#endif + using namespace facebook::flipper; /* Class responsible for collecting state updates and combining them into a * view of the current state of the flipper client. */ - -FlipperState::FlipperState(): log("") {} +FlipperState::FlipperState() : logs("") {} void FlipperState::setUpdateListener( std::shared_ptr listener) { mListener = listener; } void FlipperState::started(std::string step) { +#if FLIPPER_DEBUG_LOG + log("[started] " + step); +#endif if (stateMap.find(step) == stateMap.end()) { insertOrder.push_back(step); } @@ -33,7 +39,10 @@ void FlipperState::started(std::string step) { } void FlipperState::success(std::string step) { - log = log + "[Success] " + step + "\n"; +#if FLIPPER_DEBUG_LOG + log("[finished] " + step); +#endif + logs = logs + "[Success] " + step + "\n"; stateMap[step] = State::success; if (mListener) { mListener->onUpdate(); @@ -41,7 +50,10 @@ void FlipperState::success(std::string step) { } void FlipperState::failed(std::string step, std::string errorMessage) { - log = log + "[Failed] " + step + ": " + errorMessage + "\n"; +#if FLIPPER_DEBUG_LOG + log("[failed] " + step); +#endif + logs = logs + "[Failed] " + step + ": " + errorMessage + "\n"; stateMap[step] = State::failed; if (mListener) { mListener->onUpdate(); @@ -52,7 +64,7 @@ void FlipperState::failed(std::string step, std::string errorMessage) { // representation of the current state so the UI can show it in a more intuitive // way std::string FlipperState::getState() { - return log; + return logs; } std::vector FlipperState::getStateElements() { diff --git a/xplat/Flipper/FlipperState.h b/xplat/Flipper/FlipperState.h index e9797dd98..82c832758 100644 --- a/xplat/Flipper/FlipperState.h +++ b/xplat/Flipper/FlipperState.h @@ -52,7 +52,7 @@ class FlipperState { void started(std::string); std::shared_ptr mListener = nullptr; - std::string log; + std::string logs; std::vector insertOrder; std::map stateMap; };