From 7a56113d69c5a56ea333f87c5d67cd5a371aa090 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Fri, 7 Mar 2025 18:02:11 +0800 Subject: fix: session not disconnected properly perf: use server sockfd directly instead of a dupe of it --- src/format.hpp | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'src/format.hpp') diff --git a/src/format.hpp b/src/format.hpp index 6dc5e4d..cb9ca17 100644 --- a/src/format.hpp +++ b/src/format.hpp @@ -13,22 +13,34 @@ enum eFormatType : int8_t { namespace NFormatter { inline std::string fmt(eFormatType type, std::string str) { - std::string prefix; - switch (type) { - case LOG: prefix = "[LOG] "; break; - case WARN: prefix = "[WARN] "; break; - case ERR: prefix = "[ERROR] "; break; - case SYS: prefix = "[SYSTEM] "; break; - case CHAT: prefix = "[CHAT] "; break; - default: prefix = ""; break; - } - if (!str.empty() && str.back() != '\n' && !prefix.empty()) - str += '\n'; - return prefix + str; + std::string prefix; + switch (type) { + case LOG: + prefix = "[LOG] "; + break; + case WARN: + prefix = "[WARN] "; + break; + case ERR: + prefix = "[ERROR] "; + break; + case SYS: + prefix = "[SYSTEM] "; + break; + case CHAT: + prefix = "[CHAT] "; + break; + default: + prefix = ""; + break; + } + if (!str.empty() && str.back() != '\n' && !prefix.empty()) + str += '\n'; + return prefix + str; } template std::string fmt(eFormatType type, std::format_string fmt, Args &&...args) { - return NFormatter::fmt(type, std::format(fmt, std::forward(args)...)); + return NFormatter::fmt(type, std::format(fmt, std::forward(args)...)); } } // namespace NFormatter -- cgit v1.2.3