FlipperState debug logs improvement

Summary: Make it more explicit. What has succeeded, failed, started.

Reviewed By: ivanmisuno

Differential Revision: D49227799

fbshipit-source-id: fe9e6baaff227cf1db0b3150a3ee8cf194d2b6e6
This commit is contained in:
Lorenzo Blasa
2023-09-18 06:46:37 -07:00
committed by Facebook GitHub Bot
parent 25e187bf41
commit 3605401e5e
2 changed files with 20 additions and 17 deletions

View File

@@ -9,13 +9,10 @@
#include <vector> #include <vector>
#include "FlipperStateUpdateListener.h" #include "FlipperStateUpdateListener.h"
#include "FlipperStep.h" #include "FlipperStep.h"
#include "Log.h"
#define FLIPPER_LOGS_CAPACITY 4096 #define FLIPPER_LOGS_CAPACITY 4096
#if FLIPPER_DEBUG_LOG
#include "Log.h"
#endif
using namespace facebook::flipper; using namespace facebook::flipper;
/* Class responsible for collecting state updates and combining them into a /* Class responsible for collecting state updates and combining them into a
@@ -33,9 +30,9 @@ void FlipperState::started(std::string step) {
std::shared_ptr<FlipperStateUpdateListener> localListener; std::shared_ptr<FlipperStateUpdateListener> localListener;
{ {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
#if FLIPPER_DEBUG_LOG
log("[started] " + step); DEBUG_LOG("[step] [started] " + step);
#endif
if (stateMap.find(step) == stateMap.end()) { if (stateMap.find(step) == stateMap.end()) {
insertOrder.push_back(step); insertOrder.push_back(step);
} }
@@ -53,7 +50,7 @@ void FlipperState::ensureLogsCapacity() {
if (logs.tellp() > FLIPPER_LOGS_CAPACITY) { if (logs.tellp() > FLIPPER_LOGS_CAPACITY) {
logs.str(""); logs.str("");
logs.clear(); logs.clear();
logs << "[Truncated]" << std::endl; logs << "[truncated]" << std::endl;
} }
} }
@@ -61,10 +58,10 @@ void FlipperState::success(std::string step) {
std::shared_ptr<FlipperStateUpdateListener> localListener; std::shared_ptr<FlipperStateUpdateListener> localListener;
{ {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
std::string message = "[Success] " + step; std::string message = "[step] [success] " + step;
#if FLIPPER_DEBUG_LOG
log(message); DEBUG_LOG(message);
#endif
ensureLogsCapacity(); ensureLogsCapacity();
logs << message << std::endl; logs << message << std::endl;
@@ -82,10 +79,10 @@ void FlipperState::failed(std::string step, std::string errorMessage) {
std::shared_ptr<FlipperStateUpdateListener> localListener; std::shared_ptr<FlipperStateUpdateListener> localListener;
{ {
std::lock_guard<std::mutex> lock(mutex); std::lock_guard<std::mutex> lock(mutex);
std::string message = "[Failed] " + step + ": " + errorMessage; std::string message = "[step] [failed] " + step + ": " + errorMessage;
#if FLIPPER_DEBUG_LOG
log(message); DEBUG_LOG(message);
#endif
ensureLogsCapacity(); ensureLogsCapacity();
logs << message << std::endl; logs << message << std::endl;
stateMap[step] = State::failed; 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 // representation of the current state so the UI can show it in a more intuitive
// way // way
std::string FlipperState::getState() { std::string FlipperState::getState() {

View File

@@ -22,3 +22,9 @@ void defaultLogHandler(const std::string& message);
} // namespace flipper } // namespace flipper
} // namespace facebook } // namespace facebook
#if FLIPPER_DEBUG_LOG
#define DEBUG_LOG(...) facebook::flipper::log(__VA_ARGS__)
#else
#define DEBUG_LOG(...)
#endif