Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! src: implement per-process native Debug() printer
  • Loading branch information
joyeecheung committed Feb 25, 2020
commit d86480a65378246dcad3058b5a0aa482a28de03a
14 changes: 14 additions & 0 deletions src/debug_utils-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ inline void FORCE_INLINE Debug(AsyncWrap* async_wrap,
Debug(async_wrap, format.c_str(), std::forward<Args>(args)...);
}

namespace per_process {

template <typename... Args>
inline void FORCE_INLINE Debug(DebugCategory cat,
const char* format,
Args&&... args) {
Debug(&enabled_debug_list, cat, format, std::forward<Args>(args)...);
}

inline void FORCE_INLINE Debug(DebugCategory cat, const char* message) {
Debug(&enabled_debug_list, cat, message);
}

} // namespace per_process
} // namespace node

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
Expand Down
3 changes: 3 additions & 0 deletions src/debug_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#endif // _WIN32

namespace node {
namespace per_process {
EnabledDebugList enabled_debug_list;
}

void EnabledDebugList::Parse(Environment* env) {
std::string cats;
Expand Down
10 changes: 3 additions & 7 deletions src/debug_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,14 @@ void CheckedUvLoopClose(uv_loop_t* loop);
void PrintLibuvHandleInformation(uv_loop_t* loop, FILE* stream);

namespace per_process {
extern std::shared_ptr<EnabledDebugList> enabled_debug_list;
extern EnabledDebugList enabled_debug_list;

template <typename... Args>
inline void FORCE_INLINE Debug(DebugCategory cat,
const char* format,
Args&&... args) {
Debug(enabled_debug_list.get(), cat, format, std::forward<Args>(args)...);
}
Args&&... args);

inline void FORCE_INLINE Debug(DebugCategory cat, const char* message) {
Debug(enabled_debug_list.get(), cat, message);
}
inline void FORCE_INLINE Debug(DebugCategory cat, const char* message);
} // namespace per_process
} // namespace node

Expand Down
4 changes: 4 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,10 @@ void Init(int* argc,
}

InitializationResult InitializeOncePerProcess(int argc, char** argv) {
// Initialized the enabled list for Debug() calls with system
// environment variables.
per_process::enabled_debug_list.Parse(nullptr);

atexit(ResetStdio);
PlatformInit();

Expand Down
2 changes: 0 additions & 2 deletions src/node_env_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class MapKVStore final : public KVStore {
namespace per_process {
Mutex env_var_mutex;
std::shared_ptr<KVStore> system_environment = std::make_shared<RealEnvStore>();
std::shared_ptr<EnabledDebugList> enabled_debug_list =
std::make_shared<EnabledDebugList>(nullptr);
} // namespace per_process

template <typename T>
Expand Down