From a867522b16bfde5ae869e3d2442dc3209601e333 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Fri, 31 Jan 2020 15:04:40 +0300 Subject: [PATCH] logs: implement logs::get_channels() --- Utilities/Log.cpp | 18 ++++++++++++++++++ Utilities/Log.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 87b72068a5..37deb3c5bd 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -202,6 +202,24 @@ namespace logs } } + std::vector get_channels() + { + std::vector result; + + std::lock_guard lock(g_mutex); + + for (auto&& p : get_logger()->channels) + { + // Copy names removing duplicates + if (result.empty() || result.back() != p.first) + { + result.push_back(p.first); + } + } + + return result; + } + // Must be called in main() to stop accumulating messages in g_messages void set_init() { diff --git a/Utilities/Log.h b/Utilities/Log.h index 1892be4fdb..29ae28667e 100644 --- a/Utilities/Log.h +++ b/Utilities/Log.h @@ -95,6 +95,9 @@ namespace logs // Log level control: get channel level level get_level(const std::string&); + + // Get all registered log channels + std::vector get_channels(); } #define LOG_CHANNEL(ch, ...) inline ::logs::channel ch(#ch, ##__VA_ARGS__)