From 3605401e5ef305339b4f62da675e3901efd32e6c Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Mon, 18 Sep 2023 06:46:37 -0700 Subject: [PATCH] FlipperState debug logs improvement Summary: Make it more explicit. What has succeeded, failed, started. Reviewed By: ivanmisuno Differential Revision: D49227799 fbshipit-source-id: fe9e6baaff227cf1db0b3150a3ee8cf194d2b6e6 --- xplat/Flipper/FlipperState.cpp | 31 ++++++++++++++----------------- xplat/Flipper/Log.h | 6 ++++++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/xplat/Flipper/FlipperState.cpp b/xplat/Flipper/FlipperState.cpp index 104b590e9..a21cd90d6 100644 --- a/xplat/Flipper/FlipperState.cpp +++ b/xplat/Flipper/FlipperState.cpp @@ -9,13 +9,10 @@ #include #include "FlipperStateUpdateListener.h" #include "FlipperStep.h" +#include "Log.h" #define FLIPPER_LOGS_CAPACITY 4096 -#if FLIPPER_DEBUG_LOG -#include "Log.h" -#endif - using namespace facebook::flipper; /* Class responsible for collecting state updates and combining them into a @@ -33,9 +30,9 @@ void FlipperState::started(std::string step) { std::shared_ptr localListener; { std::lock_guard lock(mutex); -#if FLIPPER_DEBUG_LOG - log("[started] " + step); -#endif + + DEBUG_LOG("[step] [started] " + step); + if (stateMap.find(step) == stateMap.end()) { insertOrder.push_back(step); } @@ -53,7 +50,7 @@ void FlipperState::ensureLogsCapacity() { if (logs.tellp() > FLIPPER_LOGS_CAPACITY) { logs.str(""); logs.clear(); - logs << "[Truncated]" << std::endl; + logs << "[truncated]" << std::endl; } } @@ -61,10 +58,10 @@ void FlipperState::success(std::string step) { std::shared_ptr localListener; { std::lock_guard lock(mutex); - std::string message = "[Success] " + step; -#if FLIPPER_DEBUG_LOG - log(message); -#endif + std::string message = "[step] [success] " + step; + + DEBUG_LOG(message); + ensureLogsCapacity(); logs << message << std::endl; @@ -82,10 +79,10 @@ void FlipperState::failed(std::string step, std::string errorMessage) { std::shared_ptr localListener; { std::lock_guard lock(mutex); - std::string message = "[Failed] " + step + ": " + errorMessage; -#if FLIPPER_DEBUG_LOG - log(message); -#endif + std::string message = "[step] [failed] " + step + ": " + errorMessage; + + DEBUG_LOG(message); + ensureLogsCapacity(); logs << message << std::endl; stateMap[step] = State::failed; @@ -98,7 +95,7 @@ void FlipperState::failed(std::string step, std::string errorMessage) { } } -// TODO: Currently returns string, but should really provide a better +// Currently returns string, but should really provide a better // representation of the current state so the UI can show it in a more intuitive // way std::string FlipperState::getState() { diff --git a/xplat/Flipper/Log.h b/xplat/Flipper/Log.h index ad898cf2c..e5bf6ca80 100644 --- a/xplat/Flipper/Log.h +++ b/xplat/Flipper/Log.h @@ -22,3 +22,9 @@ void defaultLogHandler(const std::string& message); } // namespace flipper } // namespace facebook + +#if FLIPPER_DEBUG_LOG +#define DEBUG_LOG(...) facebook::flipper::log(__VA_ARGS__) +#else +#define DEBUG_LOG(...) +#endif