From c27066706280cd3f28ae6dd9a3b91a552cb85693 Mon Sep 17 00:00:00 2001 From: hkernbach Date: Tue, 4 Apr 2017 12:06:44 +0200 Subject: [PATCH] added log topic attribute to /_admin/log api --- CHANGELOG | 2 ++ arangod/RestHandler/RestAdminLogHandler.cpp | 8 ++++++++ lib/Logger/LogBuffer.cpp | 1 + lib/Logger/LogBuffer.h | 1 + lib/Logger/LogTopic.cpp | 12 ++++++++++++ lib/Logger/LogTopic.h | 1 + 6 files changed, 25 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index c5b65e3154..00d8b22f30 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ devel ----- +* added log topic attribute to /_admin/log api + * removed internal build option `USE_DEV_TIMERS` Enabling this option activated some proprietary timers for only selected diff --git a/arangod/RestHandler/RestAdminLogHandler.cpp b/arangod/RestHandler/RestAdminLogHandler.cpp index 38c5435a32..3b571929df 100644 --- a/arangod/RestHandler/RestAdminLogHandler.cpp +++ b/arangod/RestHandler/RestAdminLogHandler.cpp @@ -192,6 +192,14 @@ void RestAdminLogHandler::reportLogs() { result.close(); + result.add("topic", VPackValue(VPackValueType::Array)); + + for (size_t i = 0; i < length; ++i) { + auto& buf = clean.at(i + static_cast(offset)); + result.add(VPackValue(LogTopic::lookup(buf._topicId))); + } + result.close(); + // second level result.add("level", VPackValue(VPackValueType::Array)); diff --git a/lib/Logger/LogBuffer.cpp b/lib/Logger/LogBuffer.cpp index 8cb95a65c2..4907c2f5b4 100644 --- a/lib/Logger/LogBuffer.cpp +++ b/lib/Logger/LogBuffer.cpp @@ -47,6 +47,7 @@ static void logEntry(LogMessage* message) { ptr->_timestamp = timestamp; TRI_CopyString(ptr->_message, message->_message.c_str() + message->_offset, sizeof(ptr->_message) - 1); + ptr->_topicId = message->_topicId; } std::vector LogBuffer::entries(LogLevel level, uint64_t start, diff --git a/lib/Logger/LogBuffer.h b/lib/Logger/LogBuffer.h index b317023c33..e9cdd3c3fe 100644 --- a/lib/Logger/LogBuffer.h +++ b/lib/Logger/LogBuffer.h @@ -44,6 +44,7 @@ struct LogBuffer { LogLevel _level; time_t _timestamp; char _message[256]; + size_t _topicId; }; } diff --git a/lib/Logger/LogTopic.cpp b/lib/Logger/LogTopic.cpp index 782d5ccb20..c14e4ce4ad 100644 --- a/lib/Logger/LogTopic.cpp +++ b/lib/Logger/LogTopic.cpp @@ -115,6 +115,18 @@ LogTopic* LogTopic::lookup(std::string const& name) { return it->second; } + +std::string LogTopic::lookup(size_t topicId) { + MUTEX_LOCKER(guard, _namesLock); + + for (auto const& it : _names) { + if (it.second->_id == topicId) { + return it.second->_name; + } + } + + return std::string("UNKNOWN"); +} LogTopic::LogTopic(std::string const& name) : LogTopic(name, LogLevel::DEFAULT) {} diff --git a/lib/Logger/LogTopic.h b/lib/Logger/LogTopic.h index 648d64e476..383fc894d1 100644 --- a/lib/Logger/LogTopic.h +++ b/lib/Logger/LogTopic.h @@ -40,6 +40,7 @@ class LogTopic { static std::vector> logLevelTopics(); static void setLogLevel(std::string const&, LogLevel); static LogTopic* lookup(std::string const&); + static std::string lookup(size_t topicId); public: explicit LogTopic(std::string const& name);