summaryrefslogtreecommitdiff
path: root/src/format.hpp
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-03-07 18:02:11 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-03-20 23:44:57 +0800
commit7a56113d69c5a56ea333f87c5d67cd5a371aa090 (patch)
tree7b3873aabf9d35abeac7e4970935cb9f185ccaa7 /src/format.hpp
parent3972c5f76483bf5f64bcf19685ee391c4d6b1a9b (diff)
fix: session not disconnected properly
perf: use server sockfd directly instead of a dupe of it
Diffstat (limited to 'src/format.hpp')
-rw-r--r--src/format.hpp38
1 files changed, 25 insertions, 13 deletions
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 <typename... Args>
std::string fmt(eFormatType type, std::format_string<Args...> fmt, Args &&...args) {
- return NFormatter::fmt(type, std::format(fmt, std::forward<Args>(args)...));
+ return NFormatter::fmt(type, std::format(fmt, std::forward<Args>(args)...));
}
} // namespace NFormatter