From 3d46f94ea825928e76567e919a87ec48b36283a1 Mon Sep 17 00:00:00 2001 From: xiyoo812 Date: Sat, 23 Sep 2023 23:32:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91=E5=AD=97=E7=AC=A6=E4=B8=B2co?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/lualog/lualog/logger.cpp | 12 ++++++------ extend/lualog/lualog/logger.h | 6 +++--- extend/lualog/lualog/lualog.cpp | 15 ++++++++------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/extend/lualog/lualog/logger.cpp b/extend/lualog/lualog/logger.cpp index f010dd00..4f1f3581 100644 --- a/extend/lualog/lualog/logger.cpp +++ b/extend/lualog/lualog/logger.cpp @@ -26,14 +26,14 @@ namespace logger { // class log_message // -------------------------------------------------------------------------------- - void log_message::option(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line) { + void log_message::option(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line) { log_time_ = log_time::now(); - feature_ = feature; - source_ = source; + feature_ = std::move(feature); + source_ = std::move(source); + msg_ = std::move(msg); + tag_ = std::move(tag); level_ = level; line_ = line; - msg_ = msg; - tag_ = tag; } // class log_message_pool @@ -367,7 +367,7 @@ namespace logger { } } - void log_service::output(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line) { + void log_service::output(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line) { if (!log_filter_.is_filter(level)) { auto logmsg_ = message_pool_->allocate(); logmsg_->option(level, msg, tag, feature, source, line); diff --git a/extend/lualog/lualog/logger.h b/extend/lualog/lualog/logger.h index c79e4497..dd26c894 100644 --- a/extend/lualog/lualog/logger.h +++ b/extend/lualog/lualog/logger.h @@ -114,7 +114,7 @@ namespace logger { void set_grow(bool grow) { grow_ = grow; } log_level level() const { return level_; } const log_time& get_log_time()const { return log_time_; } - void option(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line); + void option(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line); private: int line_ = 0; @@ -239,7 +239,7 @@ namespace logger { virtual bool add_file_dest(vstring feature, vstring fname) = 0; virtual void set_dest_clean_time(vstring feature, size_t clean_time) = 0; virtual void option(vstring log_path, vstring service, vstring index) = 0; - virtual void output(log_level level, vstring msg, vstring tag, vstring feature = "", vstring source = "", int line = 0) = 0; + virtual void output(log_level level, cstring& msg, cstring& tag, cstring& feature = "", cstring& source = "", int line = 0) = 0; }; class log_service : public logger { @@ -268,7 +268,7 @@ namespace logger { bool is_filter(log_level lv) { return log_filter_.is_filter(lv); } void filter(log_level lv, bool on) { log_filter_.filter(lv, on); } - void output(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line); + void output(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line); protected: path build_path(vstring feature, vstring fpath); diff --git a/extend/lualog/lualog/lualog.cpp b/extend/lualog/lualog/lualog.cpp index 580ccc8d..001b93b0 100644 --- a/extend/lualog/lualog/lualog.cpp +++ b/extend/lualog/lualog/lualog.cpp @@ -32,17 +32,18 @@ namespace logger { return "unsuppert data type"; } - int zformat(lua_State* L, log_level lvl, vstring tag, vstring feature, vstring msg) { - get_logger()->output(lvl, msg, tag, feature); + int zformat(lua_State* L, log_level lvl, cstring& tag, cstring& feature, cstring& msg) { if (lvl == log_level::LOG_LEVEL_FATAL) { - lua_pushlstring(L, msg.data(), msg.size()); + lua_pushlstring(L, msg.c_str(), msg.size()); + get_logger()->output(lvl, msg, tag, feature); return 1; } + get_logger()->output(lvl, msg, tag, feature); return 0; } template - int tformat(lua_State* L, log_level lvl, vstring tag, vstring feature, int flag, vstring vfmt, std::index_sequence&&) { + int tformat(lua_State* L, log_level lvl, cstring& tag, cstring& feature, int flag, cstring& vfmt, std::index_sequence&&) { try { auto msg = fmt::format(vfmt, read_args(L, flag, integers + 6)...); return zformat(L, lvl, tag, feature, msg); @@ -68,9 +69,9 @@ namespace logger { log_level lvl = (log_level)lua_tointeger(L, 1); if (get_logger()->is_filter(lvl)) return 0; size_t flag = lua_tointeger(L, 2); - vstring tag = lua_to_native(L, 3); - vstring feature = lua_to_native(L, 4); - vstring vfmt = lua_to_native(L, 5); + sstring tag = lua_to_native(L, 3); + sstring feature = lua_to_native(L, 4); + sstring vfmt = lua_to_native(L, 5); int arg_num = lua_gettop(L) - 5; switch (arg_num) { case 0: return zformat(L, lvl, tag, feature, vfmt);