From 756aafd0f865dd5a4f05d80895d68d095c909062 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Fri, 19 Apr 2024 01:48:43 -0700 Subject: [PATCH 01/27] added initial json logging format --- include/triton/common/logging.h | 51 ++++++++- src/logging.cc | 194 ++++++++++++++++++++------------ 2 files changed, 172 insertions(+), 73 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 0be8df4..8ffbe50 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -32,6 +32,17 @@ #include #include #include +#ifdef _WIN32 +// suppress the min and max definitions in Windef.h. +#define NOMINMAX +#include +#else +#include +#include +#include +#include +#endif + namespace triton { namespace common { @@ -41,20 +52,52 @@ class LogMessage { // Log levels. enum Level { kERROR = 0, kWARNING = 1, kINFO = 2 }; - LogMessage(const char* file, int line, uint32_t level); + LogMessage(const char* file, int line, uint32_t level) + : path_(file), line_(line), + level_(std::min(level, (uint32_t)Level::kINFO)), pid_(GetProcessId()) + { + SetTimestamp(); + size_t path_start = path_.rfind('/'); + if (path_start != std::string::npos) { + path_ = path_.substr(path_start + 1, std::string::npos); + } + } + + ~LogMessage(); - std::stringstream& stream() { return stream_; } + std::stringstream& stream() { return message_; } private: + static const std::array LEVEL_NAMES_; static const std::vector level_name_; - std::stringstream stream_; + std::string path_; + const int line_; + const uint32_t level_; + const uint32_t pid_; + void LogPreamble(std::stringstream& stream); + void LogTimestamp(std::stringstream& stream); + +#ifdef _WIN32 + SYSTEMTIME timestamp_; + void SetTimestamp() { GetSystemTime(×tamp_); } + static uint32_t GetProcessId() + { + return static_cast(GetCurrentProcessId()); + }; +#else + struct timeval timestamp_; + void SetTimestamp() { gettimeofday(×tamp_, NULL); } + static uint32_t GetProcessId() { return static_cast(getpid()); }; +#endif + + std::stringstream message_; }; // Global logger for messages. Controls how log messages are reported. class Logger { public: - enum class Format { kDEFAULT, kISO8601 }; + enum class Format { kDEFAULT, kISO8601, kJSONL }; Logger(); diff --git a/src/logging.cc b/src/logging.cc index 67b01ba..a1000b6 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -26,20 +26,28 @@ #include "triton/common/logging.h" -#ifdef _WIN32 -// suppress the min and max definitions in Windef.h. -#define NOMINMAX -#include -#else -#include -#include -#include -#include -#endif #include #include #include +#include "triton/common/error.h" + +static const uint8_t INTERNAL_ERROR = + static_cast(triton::common::Error::Code::INTERNAL); + +static const uint8_t SUCCESS = + static_cast(triton::common::Error::Code::SUCCESS); + +#define TRITONJSON_STATUSTYPE uint8_t +#define TRITONJSON_STATUSRETURN(M) \ + do { \ + LOG_ERROR << (M) << ": " << INTERNAL_ERROR; \ + return INTERNAL_ERROR; \ + } while (false) + +#define TRITONJSON_STATUSSUCCESS SUCCESS +#include "triton/common/triton_json.h" + namespace triton { namespace common { Logger gLogger_; @@ -66,82 +74,130 @@ Logger::Flush() std::cerr << std::flush; } - +const std::array + LogMessage::LEVEL_NAMES_{"Error", "Warning", "Info"}; const std::vector LogMessage::level_name_{'E', 'W', 'I'}; -LogMessage::LogMessage(const char* file, int line, uint32_t level) +#ifdef _WIN32 + +void +LogMessage::LogTimestamp(std::stringstream& stream) { - std::string path(file); - size_t pos = path.rfind('/'); - if (pos != std::string::npos) { - path = path.substr(pos + 1, std::string::npos); + switch (gLogger_.LogFormat()) { + case Logger::Format::kDEFAULT: { + stream << std::setfill('0') << std::setw(2) << timestamp_.wMonth + << std::setw(2) << timestamp_.wDay << ' ' << std::setw(2) + << timestamp_.wHour << ':' << std::setw(2) << timestamp_.wMinute + << ':' << std::setw(2) << timestamp_.wSecond << '.' << std::setw(6) + << timestamp_.wMilliseconds * 1000; + break; + } + case Logger::Format::kISO8601: { + stream << timestamp_.wYear << '-' << std::setfill('0') << std::setw(2) + << timestamp_.wMonth << '-' << std::setw(2) << timestamp_.wDay + << 'T' << std::setw(2) << timestamp_.wHour << ':' << std::setw(2) + << timestamp_.wMinute << ':' << std::setw(2) << timestamp_.wSecond + << "Z"; + break; + } + case Logger::Format::JSONL: { + stream << timestamp_.wYear << '-' << std::setfill('0') << std::setw(2) + << timestamp_.wMonth << '-' << std::setw(2) << timestamp_.wDay + << 'T' << std::setw(2) << timestamp_.wHour << ':' << std::setw(2) + << timestamp_.wMinute << ':' << std::setw(2) << timestamp_.wSecond + << '.' << std::setw(6) << timestamp_.wMilliseconds * 1000 << "Z"; + break; + } } +} +#else +void +LogMessage::LogTimestamp(std::stringstream& stream) +{ + struct tm tm_time; + gmtime_r(((time_t*)&(timestamp_.tv_sec)), &tm_time); - // 'L' below is placeholder for showing log level switch (gLogger_.LogFormat()) { case Logger::Format::kDEFAULT: { - // LMMDD hh:mm:ss.ssssss -#ifdef _WIN32 - SYSTEMTIME system_time; - GetSystemTime(&system_time); - stream_ << level_name_[std::min(level, (uint32_t)Level::kINFO)] - << std::setfill('0') << std::setw(2) << system_time.wMonth - << std::setw(2) << system_time.wDay << ' ' << std::setw(2) - << system_time.wHour << ':' << std::setw(2) << system_time.wMinute - << ':' << std::setw(2) << system_time.wSecond << '.' - << std::setw(6) << system_time.wMilliseconds * 1000 << ' ' - << static_cast(GetCurrentProcessId()) << ' ' << path - << ':' << line << "] "; -#else - struct timeval tv; - gettimeofday(&tv, NULL); - struct tm tm_time; - gmtime_r(((time_t*)&(tv.tv_sec)), &tm_time); - stream_ << level_name_[std::min(level, (uint32_t)Level::kINFO)] - << std::setfill('0') << std::setw(2) << (tm_time.tm_mon + 1) - << std::setw(2) << tm_time.tm_mday << ' ' << std::setw(2) - << tm_time.tm_hour << ':' << std::setw(2) << tm_time.tm_min << ':' - << std::setw(2) << tm_time.tm_sec << '.' << std::setw(6) - << tv.tv_usec << ' ' << static_cast(getpid()) << ' ' - << path << ':' << line << "] "; -#endif + stream << std::setfill('0') << std::setw(2) << (tm_time.tm_mon + 1) + << std::setw(2) << tm_time.tm_mday << ' ' << std::setw(2) + << tm_time.tm_hour << ':' << std::setw(2) << tm_time.tm_min << ':' + << std::setw(2) << tm_time.tm_sec << '.' << std::setw(6) + << timestamp_.tv_usec; break; } case Logger::Format::kISO8601: { - // YYYY-MM-DDThh:mm:ssZ L -#ifdef _WIN32 - SYSTEMTIME system_time; - GetSystemTime(&system_time); - stream_ << system_time.wYear << '-' << std::setfill('0') << std::setw(2) - << system_time.wMonth << '-' << std::setw(2) << system_time.wDay - << 'T' << std::setw(2) << system_time.wHour << ':' << std::setw(2) - << system_time.wMinute << ':' << std::setw(2) - << system_time.wSecond << "Z " - << level_name_[std::min(level, (uint32_t)Level::kINFO)] << ' ' - << static_cast(GetCurrentProcessId()) << ' ' << path - << ':' << line << "] "; -#else - struct timeval tv; - gettimeofday(&tv, NULL); - struct tm tm_time; - gmtime_r(((time_t*)&(tv.tv_sec)), &tm_time); - stream_ << (tm_time.tm_year + 1900) << '-' << std::setfill('0') - << std::setw(2) << (tm_time.tm_mon + 1) << '-' << std::setw(2) - << tm_time.tm_mday << 'T' << std::setw(2) << tm_time.tm_hour - << ':' << std::setw(2) << tm_time.tm_min << ':' << std::setw(2) - << tm_time.tm_sec << "Z " - << level_name_[std::min(level, (uint32_t)Level::kINFO)] << ' ' - << static_cast(getpid()) << ' ' << path << ':' << line - << "] "; + stream << (tm_time.tm_year + 1900) << '-' << std::setfill('0') + << std::setw(2) << (tm_time.tm_mon + 1) << '-' << std::setw(2) + << tm_time.tm_mday << 'T' << std::setw(2) << tm_time.tm_hour << ':' + << std::setw(2) << tm_time.tm_min << ':' << std::setw(2) + << tm_time.tm_sec << "Z"; + break; + } + case Logger::Format::kJSONL: { + stream << (tm_time.tm_year + 1900) << '-' << std::setfill('0') + << std::setw(2) << (tm_time.tm_mon + 1) << '-' << std::setw(2) + << tm_time.tm_mday << 'T' << std::setw(2) << tm_time.tm_hour << ':' + << std::setw(2) << tm_time.tm_min << ':' << std::setw(2) + << tm_time.tm_sec << '.' << std::setw(6) << timestamp_.tv_usec + << "Z"; + break; + } + } +} + #endif + +void +LogMessage::LogPreamble(std::stringstream& stream) +{ + switch (gLogger_.LogFormat()) { + case Logger::Format::kDEFAULT: { + stream << LEVEL_NAMES_[level_][0]; + LogTimestamp(stream); + stream << ' ' << pid_ << ' ' << path_ << ':' << line_ << "] "; + + break; + } + case Logger::Format::kISO8601: { + LogTimestamp(stream); + stream << " " << LEVEL_NAMES_[level_][0] << ' ' << pid_ << ' ' << path_ + << ':' << line_ << "] "; + break; + } + case Logger::Format::kJSONL: { break; } } } + LogMessage::~LogMessage() { - gLogger_.Log(stream_.str()); -} + gLogger_.SetLogFormat(Logger::Format::kJSONL); + switch (gLogger_.LogFormat()) { + case Logger::Format::kDEFAULT: + case Logger::Format::kISO8601: { + std::stringstream preamble; + LogPreamble(preamble); + preamble << message_.rdbuf(); + message_.str(""); + gLogger_.Log(preamble.str()); + break; + } + case Logger::Format::kJSONL: { + TritonJson::Value logMessage(TritonJson::ValueType::OBJECT); + TritonJson::WriteBuffer buffer; + logMessage.AddString("file", path_); + logMessage.AddInt("line", line_); + logMessage.AddString("level", LEVEL_NAMES_[level_]); + logMessage.AddInt("pid", pid_); + logMessage.AddString("message", message_.str()); + logMessage.Write(&buffer); + gLogger_.Log(buffer.Contents()); + break; + } + } +} }} // namespace triton::common From c5eb21f81d86809dd1e3b9efcd5921760b4d6de3 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Fri, 19 Apr 2024 01:49:03 -0700 Subject: [PATCH 02/27] force error to be uint8_t storage type --- include/triton/common/error.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/triton/common/error.h b/include/triton/common/error.h index 5c22c19..45841a7 100644 --- a/include/triton/common/error.h +++ b/include/triton/common/error.h @@ -36,7 +36,7 @@ namespace triton { namespace common { // class Error { public: - enum class Code { + enum class Code : uint8_t { SUCCESS, UNKNOWN, INTERNAL, From e5a682ea637caf861689f2e04c9eb9b5e93e1f8a Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Fri, 19 Apr 2024 07:34:21 -0700 Subject: [PATCH 03/27] updated --- include/triton/common/logging.h | 1 - src/logging.cc | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 8ffbe50..2b59e55 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -70,7 +70,6 @@ class LogMessage { private: static const std::array LEVEL_NAMES_; - static const std::vector level_name_; std::string path_; const int line_; const uint32_t level_; diff --git a/src/logging.cc b/src/logging.cc index a1000b6..bad4d5a 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -75,7 +75,7 @@ Logger::Flush() } const std::array - LogMessage::LEVEL_NAMES_{"Error", "Warning", "Info"}; + LogMessage::LEVEL_NAMES_{"ERROR", "WARNING", "INFO"}; const std::vector LogMessage::level_name_{'E', 'W', 'I'}; #ifdef _WIN32 @@ -189,11 +189,14 @@ LogMessage::~LogMessage() case Logger::Format::kJSONL: { TritonJson::Value logMessage(TritonJson::ValueType::OBJECT); TritonJson::WriteBuffer buffer; + std::stringstream timestamp; + LogTimestamp(timestamp); logMessage.AddString("file", path_); logMessage.AddInt("line", line_); logMessage.AddString("level", LEVEL_NAMES_[level_]); - logMessage.AddInt("pid", pid_); + logMessage.AddInt("process_id", pid_); logMessage.AddString("message", message_.str()); + logMessage.AddString("timestamp", timestamp.str()); logMessage.Write(&buffer); gLogger_.Log(buffer.Contents()); break; From 16ecd882d9f5dfe277d206541d368939ea988685 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Fri, 19 Apr 2024 17:08:16 -0700 Subject: [PATCH 04/27] updating to allow escaping in current log formats --- include/triton/common/triton_json.h | 14 ++++++++++++++ src/logging.cc | 8 ++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/triton/common/triton_json.h b/include/triton/common/triton_json.h index 7a1b052..855ea39 100644 --- a/include/triton/common/triton_json.h +++ b/include/triton/common/triton_json.h @@ -25,6 +25,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once + #ifdef _WIN32 // Remove GetObject definition from windows.h, which prevents calls to // RapidJSON's GetObject. @@ -109,6 +110,19 @@ class TritonJson { std::string buffer_; }; + static std::string EscapeString(const std::string& input) + { + WriteBuffer writebuffer; + const unsigned int writeFlags = rapidjson::kWriteNanAndInfFlag; + // Provide default template arguments to pass writeFlags + rapidjson::Writer< + WriteBuffer, rapidjson::UTF8<>, rapidjson::UTF8<>, + rapidjson::CrtAllocator, writeFlags> + writer(writebuffer); + writer.String(input.c_str()); + return writebuffer.Contents(); + } + // // Value representing the entire document or an element within a // document. diff --git a/src/logging.cc b/src/logging.cc index bad4d5a..03ef238 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -76,7 +76,6 @@ Logger::Flush() const std::array LogMessage::LEVEL_NAMES_{"ERROR", "WARNING", "INFO"}; -const std::vector LogMessage::level_name_{'E', 'W', 'I'}; #ifdef _WIN32 @@ -174,15 +173,16 @@ LogMessage::LogPreamble(std::stringstream& stream) LogMessage::~LogMessage() { - gLogger_.SetLogFormat(Logger::Format::kJSONL); + // gLogger_.SetLogFormat(Logger::Format::kJSONL); switch (gLogger_.LogFormat()) { case Logger::Format::kDEFAULT: case Logger::Format::kISO8601: { std::stringstream preamble; LogPreamble(preamble); - preamble << message_.rdbuf(); - message_.str(""); + // std::string escaped(message_.str()); + std::string escaped = TritonJson::EscapeString(message_.str()); + preamble << escaped; gLogger_.Log(preamble.str()); break; } From f812f8ea067bad49c396178ea43872267674f920 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Sat, 11 May 2024 08:40:42 -0700 Subject: [PATCH 05/27] adding support for escaping log messages --- include/triton/common/logging.h | 190 ++++++++++++++++------------ include/triton/common/triton_json.h | 9 +- src/logging.cc | 86 +++---------- 3 files changed, 139 insertions(+), 146 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 2b59e55..5e80f6b 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -32,6 +32,8 @@ #include #include #include + +#include "table_printer.h" #ifdef _WIN32 // suppress the min and max definitions in Windef.h. #define NOMINMAX @@ -46,68 +48,22 @@ namespace triton { namespace common { -// A log message. -class LogMessage { - public: - // Log levels. - enum Level { kERROR = 0, kWARNING = 1, kINFO = 2 }; - - LogMessage(const char* file, int line, uint32_t level) - : path_(file), line_(line), - level_(std::min(level, (uint32_t)Level::kINFO)), pid_(GetProcessId()) - { - SetTimestamp(); - size_t path_start = path_.rfind('/'); - if (path_start != std::string::npos) { - path_ = path_.substr(path_start + 1, std::string::npos); - } - } - - - ~LogMessage(); - - std::stringstream& stream() { return message_; } - - private: - static const std::array LEVEL_NAMES_; - std::string path_; - const int line_; - const uint32_t level_; - const uint32_t pid_; - void LogPreamble(std::stringstream& stream); - void LogTimestamp(std::stringstream& stream); - -#ifdef _WIN32 - SYSTEMTIME timestamp_; - void SetTimestamp() { GetSystemTime(×tamp_); } - static uint32_t GetProcessId() - { - return static_cast(GetCurrentProcessId()); - }; -#else - struct timeval timestamp_; - void SetTimestamp() { gettimeofday(×tamp_, NULL); } - static uint32_t GetProcessId() { return static_cast(getpid()); }; -#endif - - std::stringstream message_; -}; - // Global logger for messages. Controls how log messages are reported. class Logger { public: - enum class Format { kDEFAULT, kISO8601, kJSONL }; + // Log Formats. + enum class Format { kDEFAULT, kISO8601 }; + + // Log levels. + enum Level { kERROR = 0, kWARNING = 1, kINFO = 2 }; Logger(); // Is a log level enabled. - bool IsEnabled(LogMessage::Level level) const { return enables_[level]; } + bool IsEnabled(Level level) const { return enables_[level]; } // Set enable for a log Level. - void SetEnabled(LogMessage::Level level, bool enable) - { - enables_[level] = enable; - } + void SetEnabled(Level level, bool enable) { enables_[level] = enable; } // Get the current verbose logging level. uint32_t VerboseLevel() const { return vlevel_; } @@ -115,6 +71,12 @@ class Logger { // Set the current verbose logging level. void SetVerboseLevel(uint32_t vlevel) { vlevel_ = vlevel; } + // Whether to escape log messages + // using JSON string escaping rules. + // Default is true but can be disabled via an environment variable + // TRITONSERVER_ESCAPE_LOG_MESSAGES + bool EscapeLogMessages() const { return escape_log_messages_; }; + // Get the logging format. Format LogFormat() { return format_; } @@ -167,7 +129,10 @@ class Logger { // Flush the log. void Flush(); + static const std::array LEVEL_NAMES; + private: + bool escape_log_messages_; std::vector enables_; uint32_t vlevel_; Format format_; @@ -178,15 +143,64 @@ class Logger { extern Logger gLogger_; -#define LOG_ENABLE_INFO(E) \ - triton::common::gLogger_.SetEnabled( \ - triton::common::LogMessage::Level::kINFO, (E)) +// A log message. +class LogMessage { + public: + LogMessage(const char* file, int line, uint32_t level) + : path_(file), line_(line), + level_(std::min(level, (uint32_t)Logger::Level::kINFO)), + pid_(GetProcessId()), escape_log_messages_(gLogger_.EscapeLogMessages()) + { + SetTimestamp(); + size_t path_start = path_.rfind('/'); + if (path_start != std::string::npos) { + path_ = path_.substr(path_start + 1, std::string::npos); + } + } + + LogMessage( + const char* file, int line, uint32_t level, bool escape_log_messages) + : LogMessage(file, line, level) + { + escape_log_messages_ = escape_log_messages; + } + + ~LogMessage(); + + std::stringstream& stream() { return message_; } + + private: + std::string path_; + const int line_; + const uint32_t level_; + const uint32_t pid_; + void LogPreamble(std::stringstream& stream); + void LogTimestamp(std::stringstream& stream); + +#ifdef _WIN32 + SYSTEMTIME timestamp_; + void SetTimestamp() { GetSystemTime(×tamp_); } + static uint32_t GetProcessId() + { + return static_cast(GetCurrentProcessId()); + }; +#else + struct timeval timestamp_; + void SetTimestamp() { gettimeofday(×tamp_, NULL); } + static uint32_t GetProcessId() { return static_cast(getpid()); }; +#endif + std::stringstream message_; + bool escape_log_messages_; +}; + +#define LOG_ENABLE_INFO(E) \ + triton::common::gLogger_.SetEnabled(triton::common::Logger::Level::kINFO, (E)) #define LOG_ENABLE_WARNING(E) \ triton::common::gLogger_.SetEnabled( \ - triton::common::LogMessage::Level::kWARNING, (E)) + triton::common::Logger::Level::kWARNING, (E)) #define LOG_ENABLE_ERROR(E) \ triton::common::gLogger_.SetEnabled( \ - triton::common::LogMessage::Level::kERROR, (E)) + triton::common::Logger::Level::kERROR, (E)) #define LOG_SET_VERBOSE(L) \ triton::common::gLogger_.SetVerboseLevel( \ static_cast(std::max(0, (L)))) @@ -201,12 +215,11 @@ extern Logger gLogger_; #ifdef TRITON_ENABLE_LOGGING #define LOG_INFO_IS_ON \ - triton::common::gLogger_.IsEnabled(triton::common::LogMessage::Level::kINFO) -#define LOG_WARNING_IS_ON \ - triton::common::gLogger_.IsEnabled( \ - triton::common::LogMessage::Level::kWARNING) + triton::common::gLogger_.IsEnabled(triton::common::Logger::Level::kINFO) +#define LOG_WARNING_IS_ON \ + triton::common::gLogger_.IsEnabled(triton::common::Logger::Level::kWARNING) #define LOG_ERROR_IS_ON \ - triton::common::gLogger_.IsEnabled(triton::common::LogMessage::Level::kERROR) + triton::common::gLogger_.IsEnabled(triton::common::Logger::Level::kERROR) #define LOG_VERBOSE_IS_ON(L) (triton::common::gLogger_.VerboseLevel() >= (L)) #else @@ -220,25 +233,25 @@ extern Logger gLogger_; #endif // TRITON_ENABLE_LOGGING // Macros that use explicitly given filename and line number. -#define LOG_INFO_FL(FN, LN) \ - if (LOG_INFO_IS_ON) \ - triton::common::LogMessage( \ - (char*)(FN), LN, triton::common::LogMessage::Level::kINFO) \ +#define LOG_INFO_FL(FN, LN) \ + if (LOG_INFO_IS_ON) \ + triton::common::LogMessage( \ + (char*)(FN), LN, triton::common::Logger::Level::kINFO) \ .stream() -#define LOG_WARNING_FL(FN, LN) \ - if (LOG_WARNING_IS_ON) \ - triton::common::LogMessage( \ - (char*)(FN), LN, triton::common::LogMessage::Level::kWARNING) \ +#define LOG_WARNING_FL(FN, LN) \ + if (LOG_WARNING_IS_ON) \ + triton::common::LogMessage( \ + (char*)(FN), LN, triton::common::Logger::Level::kWARNING) \ .stream() -#define LOG_ERROR_FL(FN, LN) \ - if (LOG_ERROR_IS_ON) \ - triton::common::LogMessage( \ - (char*)(FN), LN, triton::common::LogMessage::Level::kERROR) \ +#define LOG_ERROR_FL(FN, LN) \ + if (LOG_ERROR_IS_ON) \ + triton::common::LogMessage( \ + (char*)(FN), LN, triton::common::Logger::Level::kERROR) \ .stream() -#define LOG_VERBOSE_FL(L, FN, LN) \ - if (LOG_VERBOSE_IS_ON(L)) \ - triton::common::LogMessage( \ - (char*)(FN), LN, triton::common::LogMessage::Level::kINFO) \ +#define LOG_VERBOSE_FL(L, FN, LN) \ + if (LOG_VERBOSE_IS_ON(L)) \ + triton::common::LogMessage( \ + (char*)(FN), LN, triton::common::Logger::Level::kINFO) \ .stream() // Macros that use current filename and line number. @@ -247,6 +260,25 @@ extern Logger gLogger_; #define LOG_ERROR LOG_ERROR_FL(__FILE__, __LINE__) #define LOG_VERBOSE(L) LOG_VERBOSE_FL(L, __FILE__, __LINE__) +#define LOG_TABLE_VERBOSE(L, TABLE) \ + \ + do { \ + if (LOG_VERBOSE_IS_ON(L)) \ + triton::common::LogMessage( \ + __FILE__, __LINE__, triton::common::Logger::Level::kINFO, false) \ + .stream() \ + << TABLE.PrintTable(); \ + } while (false) + + +#define LOG_TABLE_INFO(TABLE) \ + do { \ + if (LOG_INFO_IS_ON) \ + triton::common::LogMessage( \ + __FILE__, __LINE__, triton::common::Logger::Level::kINFO, false) \ + .stream() \ + << TABLE.PrintTable(); \ + } while (false) #define LOG_STATUS_ERROR(X, MSG) \ do { \ diff --git a/include/triton/common/triton_json.h b/include/triton/common/triton_json.h index 855ea39..9680b7a 100644 --- a/include/triton/common/triton_json.h +++ b/include/triton/common/triton_json.h @@ -110,6 +110,11 @@ class TritonJson { std::string buffer_; }; + // + // Utility to return an escaped version of the + // input string + // + static std::string EscapeString(const std::string& input) { WriteBuffer writebuffer; @@ -119,7 +124,9 @@ class TritonJson { WriteBuffer, rapidjson::UTF8<>, rapidjson::UTF8<>, rapidjson::CrtAllocator, writeFlags> writer(writebuffer); - writer.String(input.c_str()); + if (RAPIDJSON_UNLIKELY(!writer.String(input.c_str()))) { + return "Error Escaping String"; + } return writebuffer.Contents(); } diff --git a/src/logging.cc b/src/logging.cc index 03ef238..9c67138 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -32,20 +32,11 @@ #include "triton/common/error.h" -static const uint8_t INTERNAL_ERROR = - static_cast(triton::common::Error::Code::INTERNAL); - -static const uint8_t SUCCESS = - static_cast(triton::common::Error::Code::SUCCESS); - +// Defined but not used #define TRITONJSON_STATUSTYPE uint8_t -#define TRITONJSON_STATUSRETURN(M) \ - do { \ - LOG_ERROR << (M) << ": " << INTERNAL_ERROR; \ - return INTERNAL_ERROR; \ - } while (false) +#define TRITONJSON_STATUSRETURN(M) +#define TRITONJSON_STATUSSUCCESS 0 -#define TRITONJSON_STATUSSUCCESS SUCCESS #include "triton/common/triton_json.h" namespace triton { namespace common { @@ -55,6 +46,9 @@ Logger gLogger_; Logger::Logger() : enables_{true, true, true}, vlevel_(0), format_(Format::kDEFAULT) { + const char* value = std::getenv("TRITONSERVER_ESCAPE_LOG_MESSAGES"); + escape_log_messages_ = + (value && std::strcmp(value, "FALSE") == 0) ? false : true; } void @@ -74,8 +68,8 @@ Logger::Flush() std::cerr << std::flush; } -const std::array - LogMessage::LEVEL_NAMES_{"ERROR", "WARNING", "INFO"}; +const std::array Logger::LEVEL_NAMES{ + "E", "W", "I"}; #ifdef _WIN32 @@ -92,14 +86,6 @@ LogMessage::LogTimestamp(std::stringstream& stream) break; } case Logger::Format::kISO8601: { - stream << timestamp_.wYear << '-' << std::setfill('0') << std::setw(2) - << timestamp_.wMonth << '-' << std::setw(2) << timestamp_.wDay - << 'T' << std::setw(2) << timestamp_.wHour << ':' << std::setw(2) - << timestamp_.wMinute << ':' << std::setw(2) << timestamp_.wSecond - << "Z"; - break; - } - case Logger::Format::JSONL: { stream << timestamp_.wYear << '-' << std::setfill('0') << std::setw(2) << timestamp_.wMonth << '-' << std::setw(2) << timestamp_.wDay << 'T' << std::setw(2) << timestamp_.wHour << ':' << std::setw(2) @@ -126,14 +112,6 @@ LogMessage::LogTimestamp(std::stringstream& stream) break; } case Logger::Format::kISO8601: { - stream << (tm_time.tm_year + 1900) << '-' << std::setfill('0') - << std::setw(2) << (tm_time.tm_mon + 1) << '-' << std::setw(2) - << tm_time.tm_mday << 'T' << std::setw(2) << tm_time.tm_hour << ':' - << std::setw(2) << tm_time.tm_min << ':' << std::setw(2) - << tm_time.tm_sec << "Z"; - break; - } - case Logger::Format::kJSONL: { stream << (tm_time.tm_year + 1900) << '-' << std::setfill('0') << std::setw(2) << (tm_time.tm_mon + 1) << '-' << std::setw(2) << tm_time.tm_mday << 'T' << std::setw(2) << tm_time.tm_hour << ':' @@ -152,19 +130,16 @@ LogMessage::LogPreamble(std::stringstream& stream) { switch (gLogger_.LogFormat()) { case Logger::Format::kDEFAULT: { - stream << LEVEL_NAMES_[level_][0]; + stream << Logger::LEVEL_NAMES[level_]; LogTimestamp(stream); - stream << ' ' << pid_ << ' ' << path_ << ':' << line_ << "] "; + stream << ' ' << pid_ << " [" << path_ << ':' << line_ << "] "; break; } case Logger::Format::kISO8601: { LogTimestamp(stream); - stream << " " << LEVEL_NAMES_[level_][0] << ' ' << pid_ << ' ' << path_ - << ':' << line_ << "] "; - break; - } - case Logger::Format::kJSONL: { + stream << " " << Logger::LEVEL_NAMES[level_] << ' ' << pid_ << " [" + << path_ << ':' << line_ << "] "; break; } } @@ -173,34 +148,13 @@ LogMessage::LogPreamble(std::stringstream& stream) LogMessage::~LogMessage() { - // gLogger_.SetLogFormat(Logger::Format::kJSONL); - - switch (gLogger_.LogFormat()) { - case Logger::Format::kDEFAULT: - case Logger::Format::kISO8601: { - std::stringstream preamble; - LogPreamble(preamble); - // std::string escaped(message_.str()); - std::string escaped = TritonJson::EscapeString(message_.str()); - preamble << escaped; - gLogger_.Log(preamble.str()); - break; - } - case Logger::Format::kJSONL: { - TritonJson::Value logMessage(TritonJson::ValueType::OBJECT); - TritonJson::WriteBuffer buffer; - std::stringstream timestamp; - LogTimestamp(timestamp); - logMessage.AddString("file", path_); - logMessage.AddInt("line", line_); - logMessage.AddString("level", LEVEL_NAMES_[level_]); - logMessage.AddInt("process_id", pid_); - logMessage.AddString("message", message_.str()); - logMessage.AddString("timestamp", timestamp.str()); - logMessage.Write(&buffer); - gLogger_.Log(buffer.Contents()); - break; - } - } + std::stringstream preamble; + LogPreamble(preamble); + std::string escaped_message = escape_log_messages_ + ? TritonJson::EscapeString(message_.str()) + : message_.str(); + preamble << escaped_message; + gLogger_.Log(preamble.str()); } + }} // namespace triton::common From 1714c903a8e17a0300fd1b184fa09c9f02778cfc Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Tue, 14 May 2024 16:14:19 -0700 Subject: [PATCH 06/27] adding logging macros for JSON --- include/triton/common/logging.h | 57 ++++++++++++++++++++++++++++++++- src/logging.cc | 4 +-- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 5e80f6b..e5907ad 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -55,7 +55,7 @@ class Logger { enum class Format { kDEFAULT, kISO8601 }; // Log levels. - enum Level { kERROR = 0, kWARNING = 1, kINFO = 2 }; + enum Level { kERROR = 0, kWARNING = 1, kINFO = 2, kEND }; Logger(); @@ -254,6 +254,51 @@ class LogMessage { (char*)(FN), LN, triton::common::Logger::Level::kINFO) \ .stream() +#define LOG_JSON_INFO_FL(FN, LN, PREAMBLE, JSON_CHAR_PTR, SIZE) \ + \ + do { \ + if (LOG_INFO_IS_ON) \ + triton::common::LogMessage( \ + (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ + .stream() \ + << PREAMBLE << '\n' \ + << std::string({JSON_CHAR_PTR, SIZE}); \ + } while (false) + +#define LOG_JSON_WARNING_FL(FN, LN, PREAMBLE, JSON_CHAR_PTR, SIZE) \ + \ + do { \ + if (LOG_WARNING_IS_ON) \ + triton::common::LogMessage( \ + (char*)(FN), LN, triton::common::Logger::Level::kWARNING, false) \ + .stream() \ + << PREAMBLE << '\n' \ + << std::string({JSON_CHAR_PTR, SIZE}); \ + } while (false) + +#define LOG_JSON_ERROR_FL(FN, LN, PREAMBLE, JSON_CHAR_PTR, SIZE) \ + \ + do { \ + if (LOG_ERROR_IS_ON) \ + triton::common::LogMessage( \ + (char*)(FN), LN, triton::common::Logger::Level::kERROR, false) \ + .stream() \ + << PREAMBLE << '\n' \ + << std::string({JSON_CHAR_PTR, SIZE}); \ + } while (false) + +#define LOG_JSON_VERBOSE_FL(L, FN, LN, PREAMBLE, JSON_CHAR_PTR, SIZE) \ + \ + do { \ + if (LOG_VERBOSE_IS_ON(L)) \ + triton::common::LogMessage( \ + (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ + .stream() \ + << PREAMBLE << '\n' \ + << std::string({JSON_CHAR_PTR, SIZE}); \ + } while (false) + + // Macros that use current filename and line number. #define LOG_INFO LOG_INFO_FL(__FILE__, __LINE__) #define LOG_WARNING LOG_WARNING_FL(__FILE__, __LINE__) @@ -270,6 +315,16 @@ class LogMessage { << TABLE.PrintTable(); \ } while (false) +#define LOG_PROTOBUF_VERBOSE(L, PREAMBLE, PB_MESSAGE) \ + \ + do { \ + if (LOG_VERBOSE_IS_ON(L)) \ + triton::common::LogMessage( \ + __FILE__, __LINE__, triton::common::Logger::Level::kINFO, false) \ + .stream() \ + << PREAMBLE << '\n' \ + << PB_MESSAGE.DebugString(); \ + } while (false) #define LOG_TABLE_INFO(TABLE) \ do { \ diff --git a/src/logging.cc b/src/logging.cc index 9c67138..df1fa27 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -46,7 +46,7 @@ Logger gLogger_; Logger::Logger() : enables_{true, true, true}, vlevel_(0), format_(Format::kDEFAULT) { - const char* value = std::getenv("TRITONSERVER_ESCAPE_LOG_MESSAGES"); + const char* value = std::getenv("TRITON_SERVER_ESCAPE_LOG_MESSAGES"); escape_log_messages_ = (value && std::strcmp(value, "FALSE") == 0) ? false : true; } @@ -68,7 +68,7 @@ Logger::Flush() std::cerr << std::flush; } -const std::array Logger::LEVEL_NAMES{ +const std::array Logger::LEVEL_NAMES{ "E", "W", "I"}; #ifdef _WIN32 From c75d8a6d9b5fcea9a24fb66229c2d7fb4f880c73 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Tue, 14 May 2024 16:21:23 -0700 Subject: [PATCH 07/27] updated comment --- include/triton/common/logging.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index e5907ad..43ffa51 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -74,7 +74,7 @@ class Logger { // Whether to escape log messages // using JSON string escaping rules. // Default is true but can be disabled via an environment variable - // TRITONSERVER_ESCAPE_LOG_MESSAGES + // TRITON_SERVER_ESCAPE_LOG_MESSAGES bool EscapeLogMessages() const { return escape_log_messages_; }; // Get the logging format. From fc3ef22ffbba75dc2bce30be4b11bb23b431b3d2 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Wed, 15 May 2024 11:22:18 -0700 Subject: [PATCH 08/27] reverting format changes (usec and bracket) --- src/logging.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/logging.cc b/src/logging.cc index df1fa27..685ae06 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -90,7 +90,7 @@ LogMessage::LogTimestamp(std::stringstream& stream) << timestamp_.wMonth << '-' << std::setw(2) << timestamp_.wDay << 'T' << std::setw(2) << timestamp_.wHour << ':' << std::setw(2) << timestamp_.wMinute << ':' << std::setw(2) << timestamp_.wSecond - << '.' << std::setw(6) << timestamp_.wMilliseconds * 1000 << "Z"; + << "Z"; break; } } @@ -116,8 +116,7 @@ LogMessage::LogTimestamp(std::stringstream& stream) << std::setw(2) << (tm_time.tm_mon + 1) << '-' << std::setw(2) << tm_time.tm_mday << 'T' << std::setw(2) << tm_time.tm_hour << ':' << std::setw(2) << tm_time.tm_min << ':' << std::setw(2) - << tm_time.tm_sec << '.' << std::setw(6) << timestamp_.tv_usec - << "Z"; + << tm_time.tm_sec << "Z"; break; } } @@ -132,13 +131,13 @@ LogMessage::LogPreamble(std::stringstream& stream) case Logger::Format::kDEFAULT: { stream << Logger::LEVEL_NAMES[level_]; LogTimestamp(stream); - stream << ' ' << pid_ << " [" << path_ << ':' << line_ << "] "; + stream << ' ' << pid_ << ' ' << path_ << ':' << line_ << "] "; break; } case Logger::Format::kISO8601: { LogTimestamp(stream); - stream << " " << Logger::LEVEL_NAMES[level_] << ' ' << pid_ << " [" + stream << " " << Logger::LEVEL_NAMES[level_] << ' ' << pid_ << ' ' << path_ << ':' << line_ << "] "; break; } From 18e70558ea5194df3e2448033db1d9414870713d Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Wed, 15 May 2024 13:43:49 -0700 Subject: [PATCH 09/27] update based on review comments --- include/triton/common/logging.h | 86 ++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 33 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 43ffa51..f82a709 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -254,57 +254,70 @@ class LogMessage { (char*)(FN), LN, triton::common::Logger::Level::kINFO) \ .stream() -#define LOG_JSON_INFO_FL(FN, LN, PREAMBLE, JSON_CHAR_PTR, SIZE) \ - \ - do { \ - if (LOG_INFO_IS_ON) \ - triton::common::LogMessage( \ - (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ - .stream() \ - << PREAMBLE << '\n' \ - << std::string({JSON_CHAR_PTR, SIZE}); \ +// Macros for use with TRITONSERVER_Message objects +// +// Data is assumed to be serialized and escaped already +// Message objects are logged without further escaping + +#define LOG_SERVER_MESSAGE_INFO_FL(FN, LN, HEADING, SERVER_MESSAGE_PTR, SIZE) \ + \ + do { \ + if (LOG_INFO_IS_ON) \ + triton::common::LogMessage( \ + (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ + .stream() \ + << HEADING << '\n' \ + << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) -#define LOG_JSON_WARNING_FL(FN, LN, PREAMBLE, JSON_CHAR_PTR, SIZE) \ +#define LOG_SERVER_MESSAGE_WARNING_FL( \ + FN, LN, HEADINER, SERVER_MESSAGE_PTR, SIZE) \ \ do { \ if (LOG_WARNING_IS_ON) \ triton::common::LogMessage( \ (char*)(FN), LN, triton::common::Logger::Level::kWARNING, false) \ .stream() \ - << PREAMBLE << '\n' \ - << std::string({JSON_CHAR_PTR, SIZE}); \ + << HEADING << '\n' \ + << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) -#define LOG_JSON_ERROR_FL(FN, LN, PREAMBLE, JSON_CHAR_PTR, SIZE) \ - \ - do { \ - if (LOG_ERROR_IS_ON) \ - triton::common::LogMessage( \ - (char*)(FN), LN, triton::common::Logger::Level::kERROR, false) \ - .stream() \ - << PREAMBLE << '\n' \ - << std::string({JSON_CHAR_PTR, SIZE}); \ +#define LOG_SERVER_MESSAGE_ERROR_FL(FN, LN, HEADING, SERVER_MESSAGE_PTR, SIZE) \ + \ + do { \ + if (LOG_ERROR_IS_ON) \ + triton::common::LogMessage( \ + (char*)(FN), LN, triton::common::Logger::Level::kERROR, false) \ + .stream() \ + << HEADING << '\n' \ + << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) -#define LOG_JSON_VERBOSE_FL(L, FN, LN, PREAMBLE, JSON_CHAR_PTR, SIZE) \ +#define LOG_SERVER_MESSAGE_VERBOSE_FL( \ + L, FN, LN, HEADING, SERVER_MESSAGE_PTR, SIZE) \ \ do { \ if (LOG_VERBOSE_IS_ON(L)) \ triton::common::LogMessage( \ (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ .stream() \ - << PREAMBLE << '\n' \ - << std::string({JSON_CHAR_PTR, SIZE}); \ + << HEADING << '\n' \ + << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) - // Macros that use current filename and line number. #define LOG_INFO LOG_INFO_FL(__FILE__, __LINE__) #define LOG_WARNING LOG_WARNING_FL(__FILE__, __LINE__) #define LOG_ERROR LOG_ERROR_FL(__FILE__, __LINE__) #define LOG_VERBOSE(L) LOG_VERBOSE_FL(L, __FILE__, __LINE__) +// Macros for use with triton::common::table_printer objects +// +// Data is assumed to be server / backend generated +// and not for use with client input. +// +// Tables are printed without escaping + #define LOG_TABLE_VERBOSE(L, TABLE) \ \ do { \ @@ -315,24 +328,31 @@ class LogMessage { << TABLE.PrintTable(); \ } while (false) -#define LOG_PROTOBUF_VERBOSE(L, PREAMBLE, PB_MESSAGE) \ - \ +#define LOG_TABLE_INFO(TABLE) \ do { \ - if (LOG_VERBOSE_IS_ON(L)) \ + if (LOG_INFO_IS_ON) \ triton::common::LogMessage( \ __FILE__, __LINE__, triton::common::Logger::Level::kINFO, false) \ .stream() \ - << PREAMBLE << '\n' \ - << PB_MESSAGE.DebugString(); \ + << TABLE.PrintTable(); \ } while (false) -#define LOG_TABLE_INFO(TABLE) \ + +// Macros for use with protobuf messages +// +// Data is serialized via DebugString() +// +// Data is printed without further escaping + +#define LOG_PROTOBUF_VERBOSE(L, HEADING, PB_MESSAGE) \ + \ do { \ - if (LOG_INFO_IS_ON) \ + if (LOG_VERBOSE_IS_ON(L)) \ triton::common::LogMessage( \ __FILE__, __LINE__, triton::common::Logger::Level::kINFO, false) \ .stream() \ - << TABLE.PrintTable(); \ + << HEADING << '\n' \ + << PB_MESSAGE.DebugString(); \ } while (false) #define LOG_STATUS_ERROR(X, MSG) \ From b018f4b7a2cff7c4f117e272f0f9f53c7d70bcbc Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Wed, 15 May 2024 14:07:41 -0700 Subject: [PATCH 10/27] updated based on review comments --- include/triton/common/logging.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index f82a709..53f7f04 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -271,7 +271,7 @@ class LogMessage { } while (false) #define LOG_SERVER_MESSAGE_WARNING_FL( \ - FN, LN, HEADINER, SERVER_MESSAGE_PTR, SIZE) \ + FN, LN, HEADING, SERVER_MESSAGE_PTR, SIZE) \ \ do { \ if (LOG_WARNING_IS_ON) \ From e808c04ab84b4bae6ccc90382e4c037c7d40931c Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Wed, 15 May 2024 14:26:17 -0700 Subject: [PATCH 11/27] updated based on review comment --- include/triton/common/logging.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 53f7f04..e7b7545 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -129,7 +129,7 @@ class Logger { // Flush the log. void Flush(); - static const std::array LEVEL_NAMES; + static const std::array LEVEL_NAMES; private: bool escape_log_messages_; From b9a037ff0c5e7045d15927c75e63cb68d9a3fcbe Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Wed, 15 May 2024 14:30:20 -0700 Subject: [PATCH 12/27] remove blank line --- include/triton/common/triton_json.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/triton/common/triton_json.h b/include/triton/common/triton_json.h index 9680b7a..8c7e1c5 100644 --- a/include/triton/common/triton_json.h +++ b/include/triton/common/triton_json.h @@ -25,7 +25,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once - #ifdef _WIN32 // Remove GetObject definition from windows.h, which prevents calls to // RapidJSON's GetObject. From 8eb29df7fc8655fb955c0dbaca3c8e3aa2e62b77 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Wed, 15 May 2024 15:17:30 -0700 Subject: [PATCH 13/27] escape heading for uniformity --- include/triton/common/logging.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index e7b7545..28b8b72 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -266,7 +266,7 @@ class LogMessage { triton::common::LogMessage( \ (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ .stream() \ - << HEADING << '\n' \ + << triton::common::TritonJson::EscapeString(HEADING) << '\n' \ << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) @@ -278,7 +278,7 @@ class LogMessage { triton::common::LogMessage( \ (char*)(FN), LN, triton::common::Logger::Level::kWARNING, false) \ .stream() \ - << HEADING << '\n' \ + << triton::common::TritonJson::EscapeString(HEADING) << '\n' \ << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) @@ -289,7 +289,7 @@ class LogMessage { triton::common::LogMessage( \ (char*)(FN), LN, triton::common::Logger::Level::kERROR, false) \ .stream() \ - << HEADING << '\n' \ + << triton::common::TritonJson::EscapeString(HEADING) << '\n' \ << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) @@ -301,7 +301,7 @@ class LogMessage { triton::common::LogMessage( \ (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ .stream() \ - << HEADING << '\n' \ + << triton::common::TritonJson::EscapeString(HEADING) << '\n' \ << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) @@ -351,7 +351,7 @@ class LogMessage { triton::common::LogMessage( \ __FILE__, __LINE__, triton::common::Logger::Level::kINFO, false) \ .stream() \ - << HEADING << '\n' \ + << triton::common::TritonJson::EscapeString(HEADING) << '\n' \ << PB_MESSAGE.DebugString(); \ } while (false) From 9fe0e4c6dacd33606676014dfc0f83eaed6b62ea Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Thu, 16 May 2024 04:23:56 -0700 Subject: [PATCH 14/27] reverting - for proper handling need to move to LogMessage class --- include/triton/common/logging.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 28b8b72..e7b7545 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -266,7 +266,7 @@ class LogMessage { triton::common::LogMessage( \ (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ .stream() \ - << triton::common::TritonJson::EscapeString(HEADING) << '\n' \ + << HEADING << '\n' \ << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) @@ -278,7 +278,7 @@ class LogMessage { triton::common::LogMessage( \ (char*)(FN), LN, triton::common::Logger::Level::kWARNING, false) \ .stream() \ - << triton::common::TritonJson::EscapeString(HEADING) << '\n' \ + << HEADING << '\n' \ << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) @@ -289,7 +289,7 @@ class LogMessage { triton::common::LogMessage( \ (char*)(FN), LN, triton::common::Logger::Level::kERROR, false) \ .stream() \ - << triton::common::TritonJson::EscapeString(HEADING) << '\n' \ + << HEADING << '\n' \ << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) @@ -301,7 +301,7 @@ class LogMessage { triton::common::LogMessage( \ (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ .stream() \ - << triton::common::TritonJson::EscapeString(HEADING) << '\n' \ + << HEADING << '\n' \ << std::string({SERVER_MESSAGE_PTR, SIZE}); \ } while (false) @@ -351,7 +351,7 @@ class LogMessage { triton::common::LogMessage( \ __FILE__, __LINE__, triton::common::Logger::Level::kINFO, false) \ .stream() \ - << triton::common::TritonJson::EscapeString(HEADING) << '\n' \ + << HEADING << '\n' \ << PB_MESSAGE.DebugString(); \ } while (false) From 353b9048bba0386ab3de5e1bf03148ecc5323a60 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Thu, 16 May 2024 12:36:27 -0700 Subject: [PATCH 15/27] removing macros for logging JSON messages - will addd as seperate PR --- include/triton/common/logging.h | 54 +-------------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index e7b7545..c06b414 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -254,57 +254,6 @@ class LogMessage { (char*)(FN), LN, triton::common::Logger::Level::kINFO) \ .stream() -// Macros for use with TRITONSERVER_Message objects -// -// Data is assumed to be serialized and escaped already -// Message objects are logged without further escaping - -#define LOG_SERVER_MESSAGE_INFO_FL(FN, LN, HEADING, SERVER_MESSAGE_PTR, SIZE) \ - \ - do { \ - if (LOG_INFO_IS_ON) \ - triton::common::LogMessage( \ - (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ - .stream() \ - << HEADING << '\n' \ - << std::string({SERVER_MESSAGE_PTR, SIZE}); \ - } while (false) - -#define LOG_SERVER_MESSAGE_WARNING_FL( \ - FN, LN, HEADING, SERVER_MESSAGE_PTR, SIZE) \ - \ - do { \ - if (LOG_WARNING_IS_ON) \ - triton::common::LogMessage( \ - (char*)(FN), LN, triton::common::Logger::Level::kWARNING, false) \ - .stream() \ - << HEADING << '\n' \ - << std::string({SERVER_MESSAGE_PTR, SIZE}); \ - } while (false) - -#define LOG_SERVER_MESSAGE_ERROR_FL(FN, LN, HEADING, SERVER_MESSAGE_PTR, SIZE) \ - \ - do { \ - if (LOG_ERROR_IS_ON) \ - triton::common::LogMessage( \ - (char*)(FN), LN, triton::common::Logger::Level::kERROR, false) \ - .stream() \ - << HEADING << '\n' \ - << std::string({SERVER_MESSAGE_PTR, SIZE}); \ - } while (false) - -#define LOG_SERVER_MESSAGE_VERBOSE_FL( \ - L, FN, LN, HEADING, SERVER_MESSAGE_PTR, SIZE) \ - \ - do { \ - if (LOG_VERBOSE_IS_ON(L)) \ - triton::common::LogMessage( \ - (char*)(FN), LN, triton::common::Logger::Level::kINFO, false) \ - .stream() \ - << HEADING << '\n' \ - << std::string({SERVER_MESSAGE_PTR, SIZE}); \ - } while (false) - // Macros that use current filename and line number. #define LOG_INFO LOG_INFO_FL(__FILE__, __LINE__) #define LOG_WARNING LOG_WARNING_FL(__FILE__, __LINE__) @@ -317,7 +266,6 @@ class LogMessage { // and not for use with client input. // // Tables are printed without escaping - #define LOG_TABLE_VERBOSE(L, TABLE) \ \ do { \ @@ -343,7 +291,6 @@ class LogMessage { // Data is serialized via DebugString() // // Data is printed without further escaping - #define LOG_PROTOBUF_VERBOSE(L, HEADING, PB_MESSAGE) \ \ do { \ @@ -355,6 +302,7 @@ class LogMessage { << PB_MESSAGE.DebugString(); \ } while (false) +// Macros for loggine errors #define LOG_STATUS_ERROR(X, MSG) \ do { \ const Status& status__ = (X); \ From 6d57a839653e94026105f50c791b42e6dd822b8e Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Thu, 16 May 2024 12:41:37 -0700 Subject: [PATCH 16/27] updated for typo --- include/triton/common/logging.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index c06b414..5287635 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -302,7 +302,7 @@ class LogMessage { << PB_MESSAGE.DebugString(); \ } while (false) -// Macros for loggine errors +// Macros for logging errors #define LOG_STATUS_ERROR(X, MSG) \ do { \ const Status& status__ = (X); \ From e3d721d4d4ed61c8a81a809a8f25e360e4c2b5c6 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Thu, 16 May 2024 13:17:40 -0700 Subject: [PATCH 17/27] updated --- include/triton/common/logging.h | 8 +++++++- src/logging.cc | 5 +---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 5287635..6e0bc7d 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -48,6 +48,7 @@ namespace triton { namespace common { + // Global logger for messages. Controls how log messages are reported. class Logger { public: @@ -57,6 +58,9 @@ class Logger { // Log levels. enum Level { kERROR = 0, kWARNING = 1, kINFO = 2, kEND }; + inline static const std::array LEVEL_NAMES{ + "E", "W", "I"}; + Logger(); // Is a log level enabled. @@ -129,9 +133,11 @@ class Logger { // Flush the log. void Flush(); - static const std::array LEVEL_NAMES; private: + inline static const char* ESCAPE_ENVIRONMENT_VARIABLE = + "TRITON_SERVER_ESCAPE_LOG_MESSAGES"; + bool escape_log_messages_; std::vector enables_; uint32_t vlevel_; diff --git a/src/logging.cc b/src/logging.cc index 685ae06..846577d 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -46,7 +46,7 @@ Logger gLogger_; Logger::Logger() : enables_{true, true, true}, vlevel_(0), format_(Format::kDEFAULT) { - const char* value = std::getenv("TRITON_SERVER_ESCAPE_LOG_MESSAGES"); + const char* value = std::getenv(Logger::ESCAPE_ENVIRONMENT_VARIABLE); escape_log_messages_ = (value && std::strcmp(value, "FALSE") == 0) ? false : true; } @@ -68,9 +68,6 @@ Logger::Flush() std::cerr << std::flush; } -const std::array Logger::LEVEL_NAMES{ - "E", "W", "I"}; - #ifdef _WIN32 void From 1b159ba716a0e0f27917a0436632b5264ff09048 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Thu, 16 May 2024 13:19:56 -0700 Subject: [PATCH 18/27] update remove blank lines --- include/triton/common/logging.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 6e0bc7d..af5aac5 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -133,11 +133,9 @@ class Logger { // Flush the log. void Flush(); - private: inline static const char* ESCAPE_ENVIRONMENT_VARIABLE = "TRITON_SERVER_ESCAPE_LOG_MESSAGES"; - bool escape_log_messages_; std::vector enables_; uint32_t vlevel_; From b0cd3c9ca7156bb756aadf0aacc22779f23e8191 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Thu, 16 May 2024 16:03:26 -0700 Subject: [PATCH 19/27] updated based on comments --- include/triton/common/logging.h | 8 ++++++-- src/logging.cc | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index af5aac5..9923dcf 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -77,8 +77,12 @@ class Logger { // Whether to escape log messages // using JSON string escaping rules. - // Default is true but can be disabled via an environment variable - // TRITON_SERVER_ESCAPE_LOG_MESSAGES + // Default is true but can be disabled by setting + // the following environment variable to '0'. + // If the variable is unset or set to any value !='0' + // log messages will be escaped + // + // TRITON_SERVER_ESCAPE_LOG_MESSAGES=0 bool EscapeLogMessages() const { return escape_log_messages_; }; // Get the logging format. diff --git a/src/logging.cc b/src/logging.cc index 846577d..80d3507 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -47,8 +47,7 @@ Logger::Logger() : enables_{true, true, true}, vlevel_(0), format_(Format::kDEFAULT) { const char* value = std::getenv(Logger::ESCAPE_ENVIRONMENT_VARIABLE); - escape_log_messages_ = - (value && std::strcmp(value, "FALSE") == 0) ? false : true; + escape_log_messages_ = (value && std::strcmp(value, "0") == 0) ? false : true; } void From 0d98b63eb2bfe1a86cfad457ef0af62f473f277f Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Thu, 16 May 2024 18:03:56 -0700 Subject: [PATCH 20/27] update based on review comments --- include/triton/common/logging.h | 82 ++++++++++++++++++--------------- src/logging.cc | 12 +++-- 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 9923dcf..d77f566 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -56,18 +56,24 @@ class Logger { enum class Format { kDEFAULT, kISO8601 }; // Log levels. - enum Level { kERROR = 0, kWARNING = 1, kINFO = 2, kEND }; + enum class Level : uint8_t { kERROR = 0, kWARNING = 1, kINFO = 2, kEND }; - inline static const std::array LEVEL_NAMES{ - "E", "W", "I"}; + inline static const std::array(Level::kEND)> + LEVEL_NAMES{"E", "W", "I"}; Logger(); // Is a log level enabled. - bool IsEnabled(Level level) const { return enables_[level]; } + bool IsEnabled(Level level) const + { + return enables_[static_cast(level)]; + } // Set enable for a log Level. - void SetEnabled(Level level, bool enable) { enables_[level] = enable; } + void SetEnabled(Level level, bool enable) + { + enables_[static_cast(level)] = enable; + } // Get the current verbose logging level. uint32_t VerboseLevel() const { return vlevel_; } @@ -141,7 +147,7 @@ class Logger { inline static const char* ESCAPE_ENVIRONMENT_VARIABLE = "TRITON_SERVER_ESCAPE_LOG_MESSAGES"; bool escape_log_messages_; - std::vector enables_; + std::array(Level::kEND)> enables_; uint32_t vlevel_; Format format_; std::mutex mutex_; @@ -154,10 +160,9 @@ extern Logger gLogger_; // A log message. class LogMessage { public: - LogMessage(const char* file, int line, uint32_t level) - : path_(file), line_(line), - level_(std::min(level, (uint32_t)Logger::Level::kINFO)), - pid_(GetProcessId()), escape_log_messages_(gLogger_.EscapeLogMessages()) + LogMessage(const char* file, int line, Logger::Level level) + : path_(file), line_(line), level_(level), pid_(GetProcessId()), + heading_(nullptr), escape_log_messages_(gLogger_.EscapeLogMessages()) { SetTimestamp(); size_t path_start = path_.rfind('/'); @@ -167,10 +172,12 @@ class LogMessage { } LogMessage( - const char* file, int line, uint32_t level, bool escape_log_messages) + const char* file, int line, Logger::Level level, const char* heading, + bool escape_log_messages) : LogMessage(file, line, level) { escape_log_messages_ = escape_log_messages; + heading_ = heading; } ~LogMessage(); @@ -180,7 +187,7 @@ class LogMessage { private: std::string path_; const int line_; - const uint32_t level_; + const Logger::Level level_; const uint32_t pid_; void LogPreamble(std::stringstream& stream); void LogTimestamp(std::stringstream& stream); @@ -198,6 +205,7 @@ class LogMessage { static uint32_t GetProcessId() { return static_cast(getpid()); }; #endif std::stringstream message_; + const char* heading_; bool escape_log_messages_; }; @@ -274,23 +282,25 @@ class LogMessage { // and not for use with client input. // // Tables are printed without escaping -#define LOG_TABLE_VERBOSE(L, TABLE) \ - \ - do { \ - if (LOG_VERBOSE_IS_ON(L)) \ - triton::common::LogMessage( \ - __FILE__, __LINE__, triton::common::Logger::Level::kINFO, false) \ - .stream() \ - << TABLE.PrintTable(); \ +#define LOG_TABLE_VERBOSE(L, TABLE) \ + \ + do { \ + if (LOG_VERBOSE_IS_ON(L)) \ + triton::common::LogMessage( \ + __FILE__, __LINE__, triton::common::Logger::Level::kINFO, nullptr, \ + false) \ + .stream() \ + << TABLE.PrintTable(); \ } while (false) -#define LOG_TABLE_INFO(TABLE) \ - do { \ - if (LOG_INFO_IS_ON) \ - triton::common::LogMessage( \ - __FILE__, __LINE__, triton::common::Logger::Level::kINFO, false) \ - .stream() \ - << TABLE.PrintTable(); \ +#define LOG_TABLE_INFO(TABLE) \ + do { \ + if (LOG_INFO_IS_ON) \ + triton::common::LogMessage( \ + __FILE__, __LINE__, triton::common::Logger::Level::kINFO, nullptr, \ + false) \ + .stream() \ + << TABLE.PrintTable(); \ } while (false) @@ -299,15 +309,15 @@ class LogMessage { // Data is serialized via DebugString() // // Data is printed without further escaping -#define LOG_PROTOBUF_VERBOSE(L, HEADING, PB_MESSAGE) \ - \ - do { \ - if (LOG_VERBOSE_IS_ON(L)) \ - triton::common::LogMessage( \ - __FILE__, __LINE__, triton::common::Logger::Level::kINFO, false) \ - .stream() \ - << HEADING << '\n' \ - << PB_MESSAGE.DebugString(); \ +#define LOG_PROTOBUF_VERBOSE(L, HEADING, PB_MESSAGE) \ + \ + do { \ + if (LOG_VERBOSE_IS_ON(L)) \ + triton::common::LogMessage( \ + __FILE__, __LINE__, triton::common::Logger::Level::kINFO, HEADING, \ + false) \ + .stream() \ + << PB_MESSAGE.DebugString(); \ } while (false) // Macros for logging errors diff --git a/src/logging.cc b/src/logging.cc index 80d3507..06254ca 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -125,7 +125,7 @@ LogMessage::LogPreamble(std::stringstream& stream) { switch (gLogger_.LogFormat()) { case Logger::Format::kDEFAULT: { - stream << Logger::LEVEL_NAMES[level_]; + stream << Logger::LEVEL_NAMES[static_cast(level_)]; LogTimestamp(stream); stream << ' ' << pid_ << ' ' << path_ << ':' << line_ << "] "; @@ -133,8 +133,8 @@ LogMessage::LogPreamble(std::stringstream& stream) } case Logger::Format::kISO8601: { LogTimestamp(stream); - stream << " " << Logger::LEVEL_NAMES[level_] << ' ' << pid_ << ' ' - << path_ << ':' << line_ << "] "; + stream << " " << Logger::LEVEL_NAMES[static_cast(level_)] << ' ' + << pid_ << ' ' << path_ << ':' << line_ << "] "; break; } } @@ -148,6 +148,12 @@ LogMessage::~LogMessage() std::string escaped_message = escape_log_messages_ ? TritonJson::EscapeString(message_.str()) : message_.str(); + if (heading_ != nullptr) { + std::string escaped_heading = gLogger_.EscapeLogMessages() + ? TritonJson::EscapeString(heading_) + : heading_; + preamble << escaped_heading << '\n'; + } preamble << escaped_message; gLogger_.Log(preamble.str()); } From 17c4e661aef6a0a40817f36de34a3fbe19d5d590 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Sat, 18 May 2024 05:57:25 -0700 Subject: [PATCH 21/27] update to test include directive --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 85ebda6..4c98094 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,6 +66,7 @@ target_include_directories( $ $ PRIVATE + ${RAPIDJSON_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ) From 547ff4b0a14f174b72314d1ad4eaff6a40d2f263 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Mon, 20 May 2024 11:50:09 -0700 Subject: [PATCH 22/27] updated variable name based on review --- src/logging.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/logging.cc b/src/logging.cc index 06254ca..93a82c5 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -143,8 +143,8 @@ LogMessage::LogPreamble(std::stringstream& stream) LogMessage::~LogMessage() { - std::stringstream preamble; - LogPreamble(preamble); + std::stringstream log_record; + LogPreamble(log_record); std::string escaped_message = escape_log_messages_ ? TritonJson::EscapeString(message_.str()) : message_.str(); @@ -152,10 +152,10 @@ LogMessage::~LogMessage() std::string escaped_heading = gLogger_.EscapeLogMessages() ? TritonJson::EscapeString(heading_) : heading_; - preamble << escaped_heading << '\n'; + log_record << escaped_heading << '\n'; } - preamble << escaped_message; - gLogger_.Log(preamble.str()); + log_record << escaped_message; + gLogger_.Log(log_record.str()); } }} // namespace triton::common From f808c64c4eb07baccfc0dc96899618d9641aa52e Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Mon, 20 May 2024 12:06:20 -0700 Subject: [PATCH 23/27] update naming to be clear --- include/triton/common/triton_json.h | 7 +++---- src/logging.cc | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/triton/common/triton_json.h b/include/triton/common/triton_json.h index 8c7e1c5..3f6e19a 100644 --- a/include/triton/common/triton_json.h +++ b/include/triton/common/triton_json.h @@ -110,11 +110,10 @@ class TritonJson { }; // - // Utility to return an escaped version of the - // input string - // + // Utility to serialize input string + // as a JSON string value - static std::string EscapeString(const std::string& input) + static std::string SerializeString(const std::string& input) { WriteBuffer writebuffer; const unsigned int writeFlags = rapidjson::kWriteNanAndInfFlag; diff --git a/src/logging.cc b/src/logging.cc index 93a82c5..b7a856a 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -145,12 +145,12 @@ LogMessage::~LogMessage() { std::stringstream log_record; LogPreamble(log_record); - std::string escaped_message = escape_log_messages_ - ? TritonJson::EscapeString(message_.str()) - : message_.str(); + std::string escaped_message = + escape_log_messages_ ? TritonJson::SerializeString(message_.str()) + : message_.str(); if (heading_ != nullptr) { std::string escaped_heading = gLogger_.EscapeLogMessages() - ? TritonJson::EscapeString(heading_) + ? TritonJson::SerializeString(heading_) : heading_; log_record << escaped_heading << '\n'; } From ac5e206f975d4564a789aacb49b803c7dcc0cbdc Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Mon, 20 May 2024 12:12:58 -0700 Subject: [PATCH 24/27] removing empty line --- include/triton/common/logging.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index d77f566..41c4905 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -310,7 +310,6 @@ class LogMessage { // // Data is printed without further escaping #define LOG_PROTOBUF_VERBOSE(L, HEADING, PB_MESSAGE) \ - \ do { \ if (LOG_VERBOSE_IS_ON(L)) \ triton::common::LogMessage( \ From bc0c7f5a1794d60f769cf93b410ee9c836f2c863 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Mon, 20 May 2024 12:25:07 -0700 Subject: [PATCH 25/27] update include order --- src/logging.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/logging.cc b/src/logging.cc index b7a856a..978c1e5 100644 --- a/src/logging.cc +++ b/src/logging.cc @@ -24,19 +24,16 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "triton/common/logging.h" - #include #include #include -#include "triton/common/error.h" - // Defined but not used #define TRITONJSON_STATUSTYPE uint8_t #define TRITONJSON_STATUSRETURN(M) #define TRITONJSON_STATUSSUCCESS 0 +#include "triton/common/logging.h" #include "triton/common/triton_json.h" namespace triton { namespace common { From e6d3fb2c2dbccb2924dea3643b1f5956351bc658 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Mon, 20 May 2024 12:56:59 -0700 Subject: [PATCH 26/27] updated to have single constructor --- include/triton/common/logging.h | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/include/triton/common/logging.h b/include/triton/common/logging.h index 41c4905..203e942 100644 --- a/include/triton/common/logging.h +++ b/include/triton/common/logging.h @@ -160,9 +160,12 @@ extern Logger gLogger_; // A log message. class LogMessage { public: - LogMessage(const char* file, int line, Logger::Level level) + LogMessage( + const char* file, int line, Logger::Level level, + const char* heading = nullptr, + bool escape_log_messages = gLogger_.EscapeLogMessages()) : path_(file), line_(line), level_(level), pid_(GetProcessId()), - heading_(nullptr), escape_log_messages_(gLogger_.EscapeLogMessages()) + heading_(heading), escape_log_messages_(escape_log_messages) { SetTimestamp(); size_t path_start = path_.rfind('/'); @@ -171,15 +174,6 @@ class LogMessage { } } - LogMessage( - const char* file, int line, Logger::Level level, const char* heading, - bool escape_log_messages) - : LogMessage(file, line, level) - { - escape_log_messages_ = escape_log_messages; - heading_ = heading; - } - ~LogMessage(); std::stringstream& stream() { return message_; } From a4c5a7d7688885bc0b3a10ab460cba221159b6b2 Mon Sep 17 00:00:00 2001 From: nnshah1 Date: Mon, 20 May 2024 13:26:27 -0700 Subject: [PATCH 27/27] updating error message --- include/triton/common/triton_json.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/triton/common/triton_json.h b/include/triton/common/triton_json.h index 3f6e19a..d57ff6e 100644 --- a/include/triton/common/triton_json.h +++ b/include/triton/common/triton_json.h @@ -123,7 +123,7 @@ class TritonJson { rapidjson::CrtAllocator, writeFlags> writer(writebuffer); if (RAPIDJSON_UNLIKELY(!writer.String(input.c_str()))) { - return "Error Escaping String"; + return "Error Serializing String"; } return writebuffer.Contents(); }