diff --git a/.luacheckrc b/.luacheckrc index 6ffdf425..56186448 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -14,24 +14,20 @@ max_cyclomatic_complexity = 13 max_code_line_length = 160 max_comment_line_length = 160 exclude_files = { - "script/luabt/*.*", - "script/luaoop/*.*", - "script/luabt/luaoop/*.*", - "script/luabt/LICENSE", - "script/luaoop/LICENSE", - "script/luabt/luaoop/LICENSE", - "server/robot/accord/page/*", - "extend/lmake/share.lua" + "extend/lmake/share.lua", + "server/robot/accord/page/*" } include_files = { - "script/*", - "server/*", - "worker/*", - "bin/proto/*.lua", - "tools/encrypt/*", - "tools/excel2lua/*", + "script/*.lua", + "server/*.lua", + "script/*/*.lua", + "server/*/*.lua", + "script/*/*/*.lua", + "server/*/*/*.lua", + "script/*/*/*/*.lua", + "server/*/*/*/*.lua", "extend/lmake/*.lua", - "extend/lmake/ltemplate/*.lua", + "tools/*/*.lua", } ignore = {"212", "213", "512"} diff --git a/bin/database.conf b/bin/database.conf index 2c7dd418..3ca8bf7f 100644 --- a/bin/database.conf +++ b/bin/database.conf @@ -19,7 +19,7 @@ set_env("QUANTA_MONGO_URLS", [[ ]]) --redis set_env("QUANTA_REDIS_URLS", [[ - redis://root:123456@127.0.0.1:6379; + redis://root:123456@10.96.8.100:6379; ]]) --mysql set_env("QUANTA_MYSQL_URLS", [[ diff --git a/bin/share.conf b/bin/share.conf index 526f5fe2..94db4188 100644 --- a/bin/share.conf +++ b/bin/share.conf @@ -137,12 +137,15 @@ set_env("QUANTA_DB_CACHE_MAX", "4096") --每帧落地最大数量 set_env("QUANTA_DB_CACHE_FLUSH", "10") ---webhook日志等级 +--webhook设置 ----------------------------------------------------- -set_env("QUANTA_WEBHOOK_LVL", "6") +--log: 日志采集 +--http:http发送 +set_env("QUANTA_WEBHOOK_MODE", "log") +--webhook地址设置 --set_env("QUANTA_LARK_URL", "https://open.feishu.cn/open-apis/bot/v2/hook/9a6565bf-51b4-48ab-80f0-64caf4d58ab8") --set_env("QUANTA_DING_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a4c64781-adad-4ddc-a615-6bc232ce71ef") ---set_env("QUANTA_WECHAT_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ee6d97c5-477d-436f-83db-dd5361a5e8bd") +set_env("QUANTA_WECHAT_URL", "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d7cd918c-f608-4762-87af-bb8c7fc51074") --graylog配置 ----------------------------------------------------- diff --git a/core/luabus/luabus.mak b/core/luabus/luabus.mak index f8740e03..9dceceab 100644 --- a/core/luabus/luabus.mak +++ b/core/luabus/luabus.mak @@ -19,6 +19,7 @@ MYCFLAGS += -Wsign-compare MYCFLAGS += -Wno-sign-compare MYCFLAGS += -Wno-unused-variable MYCFLAGS += -Wno-unused-parameter +MYCFLAGS += -Wno-unused-but-set-variable MYCFLAGS += -Wno-unused-but-set-parameter MYCFLAGS += -Wno-unknown-pragmas diff --git a/core/luabus/luabus.vcxproj b/core/luabus/luabus.vcxproj index 028c8cc6..d031f10f 100644 --- a/core/luabus/luabus.vcxproj +++ b/core/luabus/luabus.vcxproj @@ -64,7 +64,7 @@ - Disabled + MaxSpeed ..\..\extend\lua\lua;..\..\extend\ltimer\ltimer;..\..\extend\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/core/quanta/quanta.vcxproj b/core/quanta/quanta.vcxproj index c3755442..dbcf164b 100644 --- a/core/quanta/quanta.vcxproj +++ b/core/quanta/quanta.vcxproj @@ -44,7 +44,7 @@ - Disabled + MaxSpeed ..\..\extend\lua\lua;..\..\extend\fmt\include;..\..\extend\luakit\include;..\..\extend\lualog\lualog;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;FMT_HEADER_ONLY;%(PreprocessorDefinitions) Default diff --git a/extend/laoi/laoi.vcxproj b/extend/laoi/laoi.vcxproj index 775a2d32..8246b446 100644 --- a/extend/laoi/laoi.vcxproj +++ b/extend/laoi/laoi.vcxproj @@ -42,7 +42,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/lbson/lbson.vcxproj b/extend/lbson/lbson.vcxproj index c1186ba3..5e4d2e03 100644 --- a/extend/lbson/lbson.vcxproj +++ b/extend/lbson/lbson.vcxproj @@ -42,7 +42,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/lcodec/lcodec.vcxproj b/extend/lcodec/lcodec.vcxproj index b6f1b79d..aa18d164 100644 --- a/extend/lcodec/lcodec.vcxproj +++ b/extend/lcodec/lcodec.vcxproj @@ -50,7 +50,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/lcrypt/lcrypt.vcxproj b/extend/lcrypt/lcrypt.vcxproj index 1ea4e959..73886436 100644 --- a/extend/lcrypt/lcrypt.vcxproj +++ b/extend/lcrypt/lcrypt.vcxproj @@ -60,7 +60,7 @@ - Disabled + MaxSpeed ..\lua\lua;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LCRYPT_EXPORT;%(PreprocessorDefinitions) Default diff --git a/extend/lcurl/lcurl.vcxproj b/extend/lcurl/lcurl.vcxproj index c3946a41..0e59c6cf 100644 --- a/extend/lcurl/lcurl.vcxproj +++ b/extend/lcurl/lcurl.vcxproj @@ -42,7 +42,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\luakit\include;.\;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/ldetour/ldetour.vcxproj b/extend/ldetour/ldetour.vcxproj index 04173ad3..6d7ee34d 100644 --- a/extend/ldetour/ldetour.vcxproj +++ b/extend/ldetour/ldetour.vcxproj @@ -59,7 +59,7 @@ - Disabled + MaxSpeed src\detour;..\lua\lua;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/ljson/ljson.vcxproj b/extend/ljson/ljson.vcxproj index 3307f58a..145db785 100644 --- a/extend/ljson/ljson.vcxproj +++ b/extend/ljson/ljson.vcxproj @@ -44,7 +44,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\luakit\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/lmake/ltemplate.lua b/extend/lmake/ltemplate.lua index d4082680..4a9b82ab 100644 --- a/extend/lmake/ltemplate.lua +++ b/extend/lmake/ltemplate.lua @@ -164,12 +164,11 @@ local function render(content, env) return nil, chunk end ---导出文件模板 +--根据配置导出文件模板 --tpl_f: 文件模板 --tpl_out_f: 输出文件 --tpl_env: 环境变量 ---tpl_var_f: 环境变量文件 -local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f) +local function render_file(tpl_f, tpl_out_f, tpl_env) if not tpl_f or not tpl_out_f or not tpl_env then error("render template file params error!") return @@ -182,19 +181,6 @@ local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f) tpl_env.NAME = tpl_f local content = template_file:read("*all") template_file:close() - if tpl_var_f then - setmetatable(tpl_env, { __index = function(t, k) return _G[k] end }) - local func, err = loadfile(tpl_var_f, "bt", tpl_env) - if not func then - error(sformat("open template variable file %s failed :%s", tpl_var_f, err)) - return - end - local ok, res = pcall(func) - if not ok then - error(sformat("load template variable file %s failed :%s", tpl_var_f, res)) - return - end - end local out_file = iopen(tpl_out_f, "w") if not out_file then error(sformat("open template out file %s failed!", tpl_out_f)) @@ -214,13 +200,52 @@ local function render_file(tpl_f, tpl_out_f, tpl_env, tpl_var_f) print(sformat("render template file %s to %s success!", tpl_f, tpl_out_f)) end +--输入参数 +local arg_num = select("#", ...) + --工具用法 --tpl_f: 模板文件路径 --tpl_out_f:输出文件路径 --tpl_var_f:环境变量配置文件 -if select("#", ...) == 3 then +if arg_num == 3 then + local tpl_env = {} local tpl_f, tpl_out_f, tpl_var_f = select(1, ...) - render_file(tpl_f, tpl_out_f, {}, tpl_var_f) + if tpl_var_f then + setmetatable(tpl_env, { __index = function(t, k) return _G[k] end }) + local func, err = loadfile(tpl_var_f, "bt", tpl_env) + if not func then + error(sformat("open template variable file %s failed :%s", tpl_var_f, err)) + return + end + local ok, res = pcall(func) + if not ok then + error(sformat("load template variable file %s failed :%s", tpl_var_f, res)) + return + end + end + render_file(tpl_f, tpl_out_f, tpl_env) +end + +--工具用法 +--tpl_f: 模板文件路径 +--tpl_out_f:输出文件路径 +--key:文件索引, filename:文件名, ... +if arg_num > 3 then + local tpl_env = {} + local args = { ... } + local filenum = (arg_num - 2) // 2 + for i = 1, filenum do + local key = args[2 + i * 2 - 1] + local filename = args[2 + i * 2] + local args_file = iopen(filename, "r") + if not args_file then + error(sformat("open args file %s failed!", filename)) + return + end + tpl_env[key] = args_file:read("*all") + args_file:close() + end + render_file(args[1], args[2], tpl_env) end return { diff --git a/extend/lmake/tmpl/vcxproj.tpl b/extend/lmake/tmpl/vcxproj.tpl index 1f1bb383..14a0927c 100644 --- a/extend/lmake/tmpl/vcxproj.tpl +++ b/extend/lmake/tmpl/vcxproj.tpl @@ -103,7 +103,7 @@ - Disabled + MaxSpeed {{%= FMT_INCLUDES %}};%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;{{%= FMT_DEFINES %}};%(PreprocessorDefinitions) Default diff --git a/extend/lstdfs/lstdfs.vcxproj b/extend/lstdfs/lstdfs.vcxproj index 62b77ffc..97e7e735 100644 --- a/extend/lstdfs/lstdfs.vcxproj +++ b/extend/lstdfs/lstdfs.vcxproj @@ -41,7 +41,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/ltimer/ltimer.vcxproj b/extend/ltimer/ltimer.vcxproj index 6679a6a1..d87e93b2 100644 --- a/extend/ltimer/ltimer.vcxproj +++ b/extend/ltimer/ltimer.vcxproj @@ -42,7 +42,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/lua/lua.vcxproj b/extend/lua/lua.vcxproj index 754e8db6..aeca5e87 100644 --- a/extend/lua/lua.vcxproj +++ b/extend/lua/lua.vcxproj @@ -172,7 +172,7 @@ - Disabled + MaxSpeed .\lua;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;MAKE_LUA;%(PreprocessorDefinitions) Default diff --git a/extend/lua/luac.vcxproj b/extend/lua/luac.vcxproj index 6c2c678d..bfccc4ee 100644 --- a/extend/lua/luac.vcxproj +++ b/extend/lua/luac.vcxproj @@ -172,7 +172,7 @@ - Disabled + MaxSpeed .\lua;.\luac;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;MAKE_LUAC;%(PreprocessorDefinitions) Default diff --git a/extend/lua/lualib.vcxproj b/extend/lua/lualib.vcxproj index 2826b1f3..3fe55d72 100644 --- a/extend/lua/lualib.vcxproj +++ b/extend/lua/lualib.vcxproj @@ -171,7 +171,7 @@ - Disabled + MaxSpeed .\lua;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/lualog/lualog.vcxproj b/extend/lualog/lualog.vcxproj index 8acc3011..a7ef60fa 100644 --- a/extend/lualog/lualog.vcxproj +++ b/extend/lualog/lualog.vcxproj @@ -43,7 +43,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\fmt\include;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;FMT_HEADER_ONLY;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default 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 eafebae5..6a2a68c1 100644 --- a/extend/lualog/lualog/lualog.cpp +++ b/extend/lualog/lualog/lualog.cpp @@ -1,8 +1,58 @@ #define LUA_LIB #include "logger.h" +using namespace std; +using namespace luakit; + namespace logger { + thread_local luabuf buf; + string read_args(lua_State* L, int flag, int index) { + switch (lua_type(L, index)) { + case LUA_TNIL: return "nil"; + case LUA_TTHREAD: return "thread"; + case LUA_TFUNCTION: return "function"; + case LUA_TUSERDATA: return "userdata"; + case LUA_TLIGHTUSERDATA: return "userdata"; + case LUA_TSTRING: return lua_tostring(L, index); + case LUA_TBOOLEAN: return (lua_tointeger(L, index) == 1) ? "true" : "false"; + case LUA_TTABLE: + if ((flag & 0x01) == 0x01) { + buf.clean(); + serialize_one(L, &buf, index, 1, (flag & 0x02) == 0x02); + return string((char*)buf.head(), buf.size()); + } + return luaL_tolstring(L, index, nullptr); + case LUA_TNUMBER: + if (lua_isinteger(L, index)) { + return fmt::format("{}", lua_tointeger(L, index)); + } + return fmt::format("{}", lua_tonumber(L, index)); + } + return "unsuppert data type"; + } + + 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.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, cstring& tag, cstring& feature, int flag, vstring vfmt, std::index_sequence&&) { + try { + auto msg = fmt::format(vfmt, read_args(L, flag, integers + 6)...); + return zformat(L, lvl, tag, feature, msg); + } catch (const exception& e) { + luaL_error(L, "log format failed: %s!", e.what()); + } + return 0; + } + luakit::lua_table open_lualog(lua_State* L) { luakit::kit_state kit_state(L); auto lualog = kit_state.new_table(); @@ -14,6 +64,30 @@ namespace logger { "ERROR", log_level::LOG_LEVEL_ERROR, "FATAL", log_level::LOG_LEVEL_FATAL ); + + lualog.set_function("print", [](lua_State* L) { + log_level lvl = (log_level)lua_tointeger(L, 1); + if (get_logger()->is_filter(lvl)) return 0; + size_t flag = lua_tointeger(L, 2); + sstring tag = lua_to_native(L, 3); + sstring feature = lua_to_native(L, 4); + vstring vfmt = lua_to_native(L, 5); + int arg_num = lua_gettop(L) - 5; + switch (arg_num) { + case 0: return zformat(L, lvl, tag, feature, string(vfmt.data(), vfmt.size())); + case 1: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<1>{}); + case 2: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<2>{}); + case 3: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<3>{}); + case 4: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<4>{}); + case 5: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<5>{}); + case 6: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<6>{}); + case 7: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<7>{}); + case 8: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<8>{}); + default: luaL_error(L, "log format args is more than 8!"); break; + } + return 0; + }); + lualog.set_function("daemon", [](bool status) { get_logger()->daemon(status); }); lualog.set_function("set_max_line", [](size_t line) { get_logger()->set_max_line(line); }); lualog.set_function("set_clean_time", [](size_t time) { get_logger()->set_clean_time(time); }); @@ -28,12 +102,6 @@ namespace logger { lualog.set_function("add_dest", [](vstring feature, vstring log_path) { return get_logger()->add_dest(feature, log_path); }); lualog.set_function("add_file_dest", [](vstring feature, vstring fname) { return get_logger()->add_file_dest(feature, fname); }); lualog.set_function("set_dest_clean_time", [](vstring feature, size_t time) { get_logger()->set_dest_clean_time(feature, time); }); - lualog.set_function("info", [](vstring msg, vstring tag, vstring feature) { get_logger()->output(log_level::LOG_LEVEL_INFO, msg, tag, feature); }); - lualog.set_function("warn", [](vstring msg, vstring tag, vstring feature) { get_logger()->output(log_level::LOG_LEVEL_WARN, msg, tag, feature); }); - lualog.set_function("dump", [](vstring msg, vstring tag, vstring feature) { get_logger()->output(log_level::LOG_LEVEL_DUMP, msg, tag, feature); }); - lualog.set_function("debug", [](vstring msg, vstring tag, vstring feature) { get_logger()->output(log_level::LOG_LEVEL_DEBUG, msg, tag, feature); }); - lualog.set_function("error", [](vstring msg, vstring tag, vstring feature) { get_logger()->output(log_level::LOG_LEVEL_ERROR, msg, tag, feature); }); - lualog.set_function("fatal", [](vstring msg, vstring tag, vstring feature) { get_logger()->output(log_level::LOG_LEVEL_FATAL, msg, tag, feature); }); lualog.set_function("option", [](vstring log_path, vstring service, vstring index) { get_logger()->option(log_path, service, index); }); return lualog; } diff --git a/extend/luapb/luapb.vcxproj b/extend/luapb/luapb.vcxproj index f6d50c6f..3c9aaae4 100644 --- a/extend/luapb/luapb.vcxproj +++ b/extend/luapb/luapb.vcxproj @@ -45,7 +45,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/luapb/src/luapb.cpp b/extend/luapb/src/luapb.cpp index 1cb7b861..5af4d20d 100644 --- a/extend/luapb/src/luapb.cpp +++ b/extend/luapb/src/luapb.cpp @@ -35,8 +35,9 @@ namespace luapb { pb_header* header =(pb_header*)m_slice->peek(sizeof(pb_header)); if (!header) return 0; m_packet_len = header->len; + if (m_packet_len < sizeof(pb_header)) return -1; + if (m_packet_len >= 0xffff) return -1; if (!m_slice->peek(m_packet_len)) return 0; - if (m_packet_len > 0xffff) return -1; if (m_packet_len > data_len) return 0; return m_packet_len; } diff --git a/extend/luaxlsx/luaxlsx.vcxproj b/extend/luaxlsx/luaxlsx.vcxproj index 45c283bd..773b3917 100644 --- a/extend/luaxlsx/luaxlsx.vcxproj +++ b/extend/luaxlsx/luaxlsx.vcxproj @@ -46,7 +46,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/lworker/lworker.vcxproj b/extend/lworker/lworker.vcxproj index c6e5a871..edf70980 100644 --- a/extend/lworker/lworker.vcxproj +++ b/extend/lworker/lworker.vcxproj @@ -43,7 +43,7 @@ - Disabled + MaxSpeed ..\lua\lua;..\fmt\include;..\ltimer\ltimer;..\luakit\include;$(SolutionDir)extend\mimalloc\mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;FMT_HEADER_ONLY;LUA_BUILD_AS_DLL;%(PreprocessorDefinitions) Default diff --git a/extend/mimalloc/mimalloc.vcxproj b/extend/mimalloc/mimalloc.vcxproj index 482dc488..f201a895 100644 --- a/extend/mimalloc/mimalloc.vcxproj +++ b/extend/mimalloc/mimalloc.vcxproj @@ -65,7 +65,7 @@ - Disabled + MaxSpeed mimalloc\include;%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;MI_SHARED_LIB;MI_SHARED_LIB_EXPORT;MI_MALLOC_OVERRIDE;NDEBUG;%(PreprocessorDefinitions) Default diff --git a/script/agent/cache_agent.lua b/script/agent/cache_agent.lua index 5efb1bb9..44b76542 100644 --- a/script/agent/cache_agent.lua +++ b/script/agent/cache_agent.lua @@ -15,7 +15,7 @@ end function CacheAgent:load(primary_id, sheet_name) local ok, code, row_data = router_mgr:call_cache_hash(primary_id, "rpc_cache_load", primary_id, sheet_name) if qfailed(code, ok) then - log_err("[CacheAgent][load] code=%s, pkey=%s, sheet_name=%s", code, primary_id, sheet_name) + log_err("[CacheAgent][load] code={}, pkey={}, sheet_name={}", code, primary_id, sheet_name) return ok and code or RPC_FAILED end return code, row_data @@ -25,7 +25,7 @@ end function CacheAgent:update_field(primary_id, sheet_name, field, field_data) local ok, code = router_mgr:call_cache_hash(primary_id, "rpc_cache_update_field", primary_id, sheet_name, field, field_data) if qfailed(code, ok) then - log_err("[CacheAgent][update_field] faild: code=%s, sheet_name=%s, primary_id=%s", code, sheet_name, primary_id) + log_err("[CacheAgent][update_field] faild: code={}, sheet_name={}, primary_id={}", code, sheet_name, primary_id) return ok and code or RPC_FAILED end return code @@ -35,7 +35,7 @@ end function CacheAgent:remove_field(primary_id, sheet_name, field) local ok, code = router_mgr:call_cache_hash(primary_id, "rpc_cache_remove_field", primary_id, sheet_name, field) if qfailed(code, ok) then - log_err("[CacheAgent][remove_field] faild: code=%s, sheet_name=%s, primary_id=%s", code, sheet_name, primary_id) + log_err("[CacheAgent][remove_field] faild: code={}, sheet_name={}, primary_id={}", code, sheet_name, primary_id) return ok and code or RPC_FAILED end return code @@ -45,7 +45,7 @@ end function CacheAgent:delete(primary_id, sheet_name) local ok, code = router_mgr:call_cache_hash(primary_id, "rpc_cache_delete", primary_id, sheet_name) if qfailed(code, ok) then - log_err("[CacheAgent][delete] faild: code=%s, sheet_name=%s, primary_id=%s", code, sheet_name, primary_id) + log_err("[CacheAgent][delete] faild: code={}, sheet_name={}, primary_id={}", code, sheet_name, primary_id) return ok and code or RPC_FAILED end return code diff --git a/script/agent/gm_agent.lua b/script/agent/gm_agent.lua index 8ea0c9f5..42bf4f01 100644 --- a/script/agent/gm_agent.lua +++ b/script/agent/gm_agent.lua @@ -70,14 +70,14 @@ end -- 通知执行GM指令 function GMAgent:rpc_command_execute(cmd_name, ...) - log_info("[GMAgent][rpc_command_execute]->cmd_name:%s", cmd_name) + log_info("[GMAgent][rpc_command_execute]->cmd_name:{}", cmd_name) local ok, res = tunpack(self:notify_listener(cmd_name, ...)) return ok and SUCCESS or LOGIC_FAILED, res end -- GM服务已经ready function GMAgent:on_service_ready(id, service_name) - log_info("[GMAgent][on_service_ready]->id:%s, service_name:%s", id, service_name) + log_info("[GMAgent][on_service_ready]->id:{}, service_name:{}", id, service_name) -- 上报gm列表 thread_mgr:success_call(2000, function() return self:report_command(id) diff --git a/script/agent/monitor_agent.lua b/script/agent/monitor_agent.lua index 028b91e5..6251f768 100644 --- a/script/agent/monitor_agent.lua +++ b/script/agent/monitor_agent.lua @@ -1,7 +1,6 @@ --monitor_agent.lua local RpcClient = import("network/rpc_client.lua") -local odate = os.date local tunpack = table.unpack local signal_quit = signal.quit local env_addr = environ.addr @@ -12,25 +11,16 @@ local log_debug = logger.debug local log_filter = logger.filter local qfailed = quanta.failed -local sfind = string.find -local sformat = string.format -local ssplit = qstring.split local shotfix = signal.hotfix -local event_mgr = quanta.get("event_mgr") -local update_mgr = quanta.get("update_mgr") -local thread_mgr = quanta.get("thread_mgr") +local event_mgr = quanta.get("event_mgr") -local PULL_CNT_MAX = 10 -local ROUTER = quanta.enum("QuantaMode", "ROUTER") -local SUCCESS = quanta.enum("KernCode", "SUCCESS") -local RPC_FAILED = quanta.enum("KernCode", "RPC_FAILED") -local RECONNECT_TIME = quanta.enum("NetwkTime", "RECONNECT_TIME") +local ROUTER = quanta.enum("QuantaMode", "ROUTER") +local RPC_FAILED = quanta.enum("KernCode", "RPC_FAILED") local MonitorAgent = singleton() local prop = property(MonitorAgent) prop:reader("client", nil) -prop:reader("sessions", {}) prop:reader("ready_watchers", {}) prop:reader("close_watchers", {}) @@ -39,7 +29,6 @@ function MonitorAgent:__init() local ip, port = env_addr("QUANTA_MONITOR_ADDR") self.client = RpcClient(self, ip, port) --注册事件 - event_mgr:add_listener(self, "rpc_remote_log") event_mgr:add_listener(self, "rpc_remote_message") event_mgr:add_listener(self, "rpc_service_changed") event_mgr:add_listener(self, "rpc_service_hotfix") @@ -47,18 +36,6 @@ function MonitorAgent:__init() event_mgr:add_listener(self, "rpc_set_logger_level") --消息 event_mgr:add_trigger(self, "on_router_connected") - --心跳定时器 - update_mgr:attach_second5(self) -end - -function MonitorAgent:on_second5() - local now = quanta.now - for session_id, session in pairs(self.sessions) do - if now - session.active_time > RECONNECT_TIME then - log_debug("[RemoteLog][on_timer]->overdue->session_id:%s", session_id) - self:close_session(session_id) - end - end end function MonitorAgent:on_router_connected() @@ -99,7 +76,7 @@ end function MonitorAgent:rpc_server_shutdown(reason) -- 关闭会话连接 event_mgr:fire_frame(function() - log_warn("[MonitorAgent][rpc_server_shutdown]->service:%s", quanta.name) + log_warn("[MonitorAgent][rpc_server_shutdown]->service:{}", quanta.name) self.client:close() signal_quit() end) @@ -113,7 +90,7 @@ function MonitorAgent:rpc_remote_message(message, data) end local ok, code, res = tunpack(event_mgr:notify_listener(message, data)) if qfailed(code, ok) then - log_err("[MonitorAgent][rpc_remote_message] web_rpc faild: ok=%s, ec=%s", ok, code) + log_err("[MonitorAgent][rpc_remote_message] web_rpc faild: ok={}, ec={}", ok, code) return { code = ok and code or RPC_FAILED, msg = ok and "" or code} end return { code = 0, msg = res} @@ -142,84 +119,10 @@ function MonitorAgent:rpc_service_hotfix() end function MonitorAgent:rpc_set_logger_level(level) - log_debug("[MonitorAgent][rpc_set_logger_level] level: %s", level) + log_debug("[MonitorAgent][rpc_set_logger_level] level: {}", level) log_filter(level) end ---日志监控 ----------------------------------------------- -function MonitorAgent:open_session(data) - local session_id = data.session_id - if not session_id then - session_id = thread_mgr:build_session_id() - end - local session = self.sessions[session_id] - if not session then - session = { - pull_index = 0, - cache_logs = {}, - filters = {}, - session_id = session_id, - } - self.sessions[session_id] = session - end - if data.filters then - session.filters = ssplit(data.filters, " ") - end - session.active_time = quanta.now - return session -end - -function MonitorAgent:close_session(session_id) - self.sessions[session_id] = nil - if not next(self.sessions) then - logger.remove_monitor(self) - end -end - -function MonitorAgent:dispatch_log(content, lvl_name) - for _, session in pairs(self.sessions) do - local cache = false - if #session.filters == 0 then - cache = true - goto docache - end - for _, filter in pairs(session.filters) do - if sfind(content, filter) then - cache = true - goto docache - end - end - :: docache :: - if cache then - local cache_logs = session.cache_logs - cache_logs[#cache_logs + 1] = sformat("[%s][%s]%s", odate("%Y-%m-%d %H:%M:%S"), lvl_name, content) - end - end -end - -function MonitorAgent:rpc_remote_log(data) - if not next(self.sessions) then - logger.add_monitor(self) - end - local show_logs = {} - local session = self:open_session(data) - local log_size = #(session.cache_logs) - local log_cnt = log_size - session.pull_index - if log_cnt > 0 then - local count = log_cnt > PULL_CNT_MAX and PULL_CNT_MAX or log_cnt - for idx = 1, count do - show_logs[#show_logs + 1] = session.cache_logs[session.pull_index + idx] - end - session.pull_index = session.pull_index + count - if session.pull_index >= log_size then - session.cache_logs = {} - session.pull_index = 0 - end - end - return SUCCESS, { logs = show_logs, session_id = session.session_id } -end - quanta.monitor = MonitorAgent() return MonitorAgent diff --git a/script/agent/proxy_agent.lua b/script/agent/proxy_agent.lua deleted file mode 100644 index a6951320..00000000 --- a/script/agent/proxy_agent.lua +++ /dev/null @@ -1,97 +0,0 @@ ---proxy_agent.lua -local sformat = string.format -local tunpack = table.unpack -local send_worker = quanta.send_worker -local call_worker = quanta.call_worker - -local TITLE = quanta.title -local HOST_IP = environ.get("QUANTA_HOST_IP") - -local event_mgr = quanta.get("event_mgr") -local scheduler = quanta.load("scheduler") - -local ProxyAgent = singleton() -local prop = property(ProxyAgent) -prop:reader("ignore_statistics", {}) - -function ProxyAgent:__init() - if scheduler then - --启动代理线程 - scheduler:startup("proxy", "worker.proxy") - end - --添加忽略的rpc统计事件 - self:ignore_statis("rpc_heartbeat") - - local wlvl = environ.number("QUANTA_WEBHOOK_LVL") - if wlvl then - --添加webhook功能 - logger.add_monitor(self, wlvl) - end -end - ---dispatch_log -function ProxyAgent:dispatch_log(content, lvl_name) - self:fire_webhook(content, lvl_name) -end - ---webhook -function ProxyAgent:fire_webhook(content, lvl_name) - local title = sformat("%s | %s | %s", HOST_IP, quanta.service_name, lvl_name) - self:send("rpc_fire_webhook", title, content) -end - ---http_get -function ProxyAgent:http_get(url, querys, headers) - return self:call("rpc_http_get", url, querys, headers) -end - ---http_post -function ProxyAgent:http_post(url, post_data, headers, querys) - return self:call("rpc_http_post", url, post_data, headers, querys) -end - ---http_put -function ProxyAgent:http_put(url, put_data, headers, querys) - return self:call("rpc_http_put", url, put_data, headers, querys) -end - ---http_del -function ProxyAgent:http_del(url, querys, headers) - return self:call("rpc_http_del", url, querys, headers) -end - -function ProxyAgent:ignore_statis(name) - self.ignore_statistics[name] = true -end - -function ProxyAgent:statistics(event, name, ...) - if self.ignore_statistics[name] then - return - end - self:send(event, name, ...) -end - -function ProxyAgent:send(rpc, ...) - if scheduler then - return scheduler:send("proxy", rpc, ...) - end - if TITLE ~= "proxy" then - return send_worker("proxy", rpc, ...) - end - event_mgr:notify_listener(rpc, ...) -end - -function ProxyAgent:call(rpc, ...) - if scheduler then - return scheduler:call("proxy", rpc, ...) - end - if TITLE ~= "proxy" then - return call_worker("proxy", rpc, ...) - end - local rpc_datas = event_mgr:notify_listener(rpc, ...) - return tunpack(rpc_datas) -end - -quanta.proxy_agent = ProxyAgent() - -return ProxyAgent diff --git a/script/basic/cmdline.lua b/script/basic/cmdline.lua index 24df718d..5b1232fe 100644 --- a/script/basic/cmdline.lua +++ b/script/basic/cmdline.lua @@ -99,7 +99,7 @@ end --command = "player_id|integer aa|table bb|string dd|number" function Cmdline:register_command(name, command, desc, cmd_type, group, tip, example, service) if self.commands[name] then - log_warn("[Cmdline][register_command] command (%s) repeat registered!", name) + log_warn("[Cmdline][register_command] command ({}) repeat registered!", name) return false end local def_args = {} @@ -112,7 +112,7 @@ function Cmdline:register_command(name, command, desc, cmd_type, group, tip, exa --组织显示结构 local nodes = self:find_group(group) tinsert(nodes, { text = desc, name = name, command = command, tip = tip, example = example, tag = "gm" }) - log_info("[Cmdline][register_command] command (%s) registered!", name) + log_info("[Cmdline][register_command] command ({}) registered!", name) return true end @@ -123,7 +123,7 @@ function Cmdline:parser_data(cmd_data) local cmd_name = cmd_data.name local cmd_define = self.commands[cmd_name] if not cmd_define then - log_err("[Cmdline][parser_data] invalid command (%s): isn't registered!", cmd_name) + log_err("[Cmdline][parser_data] invalid command ({}): isn't registered!", cmd_name) return nil, "invalid command: isn't registered" end local define_args = cmd_define.args @@ -132,7 +132,7 @@ function Cmdline:parser_data(cmd_data) local arg = cmd_data[def_arg.name] if not arg then local err = sformat("invalid command: argument %s is not exist", def_arg.name) - log_err("[Cmdline][parser_data] (%s) %s!", cmd_name, err) + log_err("[Cmdline][parser_data] ({}) {}!", cmd_name, err) return nil, err end tinsert(fmtinfos, def_arg.name) @@ -154,12 +154,12 @@ function Cmdline:parser_command(argument) local pattern = "([%a%d%_]+)" local cmd_name = smatch(argument, pattern) if not cmd_name then - log_err("[Cmdline][parser_command] invalid command (%s): name parse error!", argument) + log_err("[Cmdline][parser_command] invalid command ({}): name parse error!", argument) return nil, "invalid command: name parse error" end local cmd_define = self.commands[cmd_name] if not cmd_define then - log_err("[Cmdline][parser_command] invalid command (%s): isn't registered!", argument) + log_err("[Cmdline][parser_command] invalid command ({}): isn't registered!", argument) return nil, "invalid command: isn't registered" end local define_args = cmd_define.args @@ -168,13 +168,13 @@ function Cmdline:parser_command(argument) end local argsfunc = sgmatch(argument .. " ", pattern .. blank) if not argsfunc then - log_err("[Cmdline][parser_command] invalid command (%s): format error!", argument) + log_err("[Cmdline][parser_command] invalid command ({}): format error!", argument) return nil, "invalid command: format error" end local args = tpack(argsfunc()) if #args ~= (#define_args + 1) then local err = sformat("invalid command: argument need %d but get %d", #define_args, #args) - log_err("[Cmdline][parser_command] (%s): %s!", argument, err) + log_err("[Cmdline][parser_command] ({}): {}!", argument, err) return nil, err end return convert_args(args, cmd_define) diff --git a/script/basic/library.lua b/script/basic/library.lua index 89d4a401..9fdaee15 100644 --- a/script/basic/library.lua +++ b/script/basic/library.lua @@ -1,5 +1,4 @@ --library.lua -local sformat = string.format local qgetenv = quanta.getenv --加载全局扩展库,使用顶级域名 @@ -48,7 +47,7 @@ end --newindex local function _glib_newindex(o, k, v) if librarys[k] then - log.warn(sformat("[quanta][library] try modify quanta library [%s] namespace", k)) + logger.warn("[quanta][library] try modify quanta library [{}] namespace", k) return end rawset(o, k, v) diff --git a/script/basic/listener.lua b/script/basic/listener.lua index 98f7739c..007baa7d 100644 --- a/script/basic/listener.lua +++ b/script/basic/listener.lua @@ -19,7 +19,7 @@ function Listener:add_trigger(trigger, event, handler) local func_name = handler or event local callback_func = trigger[func_name] if not callback_func or type(callback_func) ~= "function" then - log_warn("[Listener][add_trigger] event(%s) handler not define", event) + log_warn("[Listener][add_trigger] event({}) handler not define", event) return end local trigger_map = self._triggers[event] @@ -39,13 +39,13 @@ end function Listener:add_listener(listener, event, handler) if self._listeners[event] then - log_warn("[Listener][add_listener] event(%s) repeat!", event) + log_warn("[Listener][add_listener] event({}) repeat!", event) return end local func_name = handler or event local callback_func = listener[func_name] if not callback_func or type(callback_func) ~= "function" then - log_warn("[Listener][add_listener] event(%s) callback not define!", event) + log_warn("[Listener][add_listener] event({}) callback not define!", event) return end self._listeners[event] = qtweak({ [listener] = func_name }) @@ -57,13 +57,13 @@ end function Listener:add_cmd_listener(listener, cmd, handler) if self._commands[cmd] then - log_warn("[Listener][add_cmd_listener] cmd(%s) repeat!", cmd) + log_warn("[Listener][add_cmd_listener] cmd({}) repeat!", cmd) return end local func_name = handler local callback_func = listener[func_name] if not callback_func or type(callback_func) ~= "function" then - log_warn("[Listener][add_cmd_listener] cmd(%s) handler not define!", cmd) + log_warn("[Listener][add_cmd_listener] cmd({}) handler not define!", cmd) return end self._commands[cmd] = qtweak({ [listener] = func_name }) @@ -79,7 +79,7 @@ function Listener:notify_trigger(event, ...) local callback_func = trigger[func_name] local ok, ret = xpcall(callback_func, dtraceback, trigger, ...) if not ok then - log_fatal("[Listener][notify_trigger] xpcall [%s:%s] failed: %s!", trigger:source(), func_name, ret) + log_fatal("[Listener][notify_trigger] xpcall [{}:{}] failed: {}!", trigger:source(), func_name, ret) end end end @@ -90,14 +90,14 @@ function Listener:notify_listener(event, ...) local callback_func = listener[func_name] local result = tpack(xpcall(callback_func, dtraceback, listener, ...)) if not result[1] then - log_fatal("[Listener][notify_listener] xpcall [%s:%s] failed: %s", listener:source(), func_name, result[2]) + log_fatal("[Listener][notify_listener] xpcall [{}:{}] failed: {}", listener:source(), func_name, result[2]) result[2] = sformat("event %s execute failed!", event) end return result end if not self._ignores[event] then self._ignores[event] = true - log_warn("[Listener][notify_listener] event (%s-%s) handler is nil! ", event, {...}) + log_warn("[Listener][notify_listener] event ({}-{}) handler is nil! ", event, {...}) end return tpack(false, "event handler is nil") end @@ -109,13 +109,13 @@ function Listener:notify_command(cmd, ...) local callback_func = listener[func_name] local result = tpack(xpcall(callback_func, dtraceback, listener, ...)) if not result[1] then - log_fatal("[Listener][notify_command] xpcall [%s:%s] failed: %s!", listener:source(), func_name, result[2]) + log_fatal("[Listener][notify_command] xpcall [{}:{}] failed: {}!", listener:source(), func_name, result[2]) result[2] = sformat("cmd %s execute failed!", cmd) end return result end if not self._ignores[cmd] then - log_warn("[Listener][notify_command] command %s handler is nil!", cmd) + log_warn("[Listener][notify_command] command {} handler is nil!", cmd) self._ignores[cmd] = true end return tpack(false, "command handler is nil") diff --git a/script/basic/logger.lua b/script/basic/logger.lua index f93d93ae..aa461690 100644 --- a/script/basic/logger.lua +++ b/script/basic/logger.lua @@ -3,18 +3,14 @@ local pcall = pcall local pairs = pairs -local tpack = table.pack local tunpack = table.unpack local dgetinfo = debug.getinfo local sformat = string.format -local lwarn = log.warn +local lprint = log.print local lfilter = log.filter -local lis_filter = log.is_filter -local serialize = luakit.serialize local LOG_LEVEL = log.LOG_LEVEL -local dispatching = false local title = quanta.title local monitors = _ENV.monitors or {} @@ -39,8 +35,8 @@ function logger.daemon(daemon) log.daemon(daemon) end -function logger.add_monitor(monitor, lvl) - monitors[monitor] = lvl +function logger.add_monitor(monitor) + monitors[monitor] = true end function logger.remove_monitor(monitor) @@ -54,59 +50,53 @@ function logger.filter(level) end end -local function logger_output(feature, notify, lvl, lvl_name, fmt, log_conf, ...) - if lis_filter(lvl) then +local function logger_format(flag, feature, lvl, lvl_name, fmt, ...) + local ok, msg = pcall(sformat, fmt, ...) + if not ok then + local info = dgetinfo(4, "S") + local wfmt = "[logger][{}] format failed: {}, source({}:{})" + lprint(LOG_LEVEL.WARN, 0, title, feature, wfmt, lvl_name, msg, info.short_src, info.linedefined) return end - local content - local lvl_func, extend, swline = tunpack(log_conf) - if extend then - local args = tpack(...) - for i, arg in pairs(args) do - if type(arg) == "table" then - args[i] = serialize(arg, swline and 1 or 0) - end - end - content = sformat(fmt, tunpack(args, 1, args.n)) - else - content = sformat(fmt, ...) + lprint(lvl, flag, title, feature, msg) +end + +local function logger_output(flag, feature, lvl, lvl_name, fmt, ...) + if not fmt:find("{") then + return logger_format(flag, feature, lvl, lvl_name, fmt, ...) end - lvl_func(content, title, feature) - if notify and not dispatching then - --防止重入 - dispatching = true - for monitor, mlvl in pairs(monitors) do - if lvl >= mlvl then - monitor:dispatch_log(content, lvl_name) - end + local ok, msg = pcall(lprint, lvl, flag, title, feature, fmt, ...) + if not ok then + local info = dgetinfo(3, "S") + local wfmt = "[logger][{}] format failed: {}, source({}:{})" + lprint(LOG_LEVEL.WARN, 0, title, feature, wfmt, lvl_name, msg, info.short_src, info.linedefined) + return + end + if msg then + for monitor in pairs(monitors) do + monitor:dispatch_log(msg, lvl_name) end - dispatching = false end end local LOG_LEVEL_OPTIONS = { - [LOG_LEVEL.INFO] = { "info", { log.info, false, false } }, - [LOG_LEVEL.WARN] = { "warn", { log.warn, true, false } }, - [LOG_LEVEL.DUMP] = { "dump", { log.dump, true, true } }, - [LOG_LEVEL.DEBUG] = { "debug", { log.debug, true, false } }, - [LOG_LEVEL.ERROR] = { "err", { log.error, true, false } }, - [LOG_LEVEL.FATAL] = { "fatal", { log.fatal, true, false } } + [LOG_LEVEL.INFO] = { "info", 0x00 }, + [LOG_LEVEL.WARN] = { "warn", 0x01 }, + [LOG_LEVEL.DEBUG] = { "debug", 0x01 }, + [LOG_LEVEL.ERROR] = { "err", 0x01 }, + [LOG_LEVEL.FATAL] = { "fatal", 0x01 }, + [LOG_LEVEL.DUMP] = { "dump", 0x01 | 0x02 }, } + for lvl, conf in pairs(LOG_LEVEL_OPTIONS) do - local lvl_name, log_conf = tunpack(conf) + local lvl_name, flag = tunpack(conf) logger[lvl_name] = function(fmt, ...) - local ok, res = pcall(logger_output, "", true, lvl, lvl_name, fmt, log_conf, ...) - if not ok then - local info = dgetinfo(2, "S") - lwarn(sformat("[logger][%s] format failed: %s, source(%s:%s)", lvl_name, res, info.short_src, info.linedefined)) - return false - end - return res + logger_output(flag, "", lvl, lvl_name, fmt, ...) end end for lvl, conf in pairs(LOG_LEVEL_OPTIONS) do - local lvl_name, log_conf = tunpack(conf) + local lvl_name, flag = tunpack(conf) logfeature[lvl_name] = function(feature, path, prefix, clean_time) log.add_dest(feature, path) log.ignore_prefix(feature, prefix) @@ -114,13 +104,7 @@ for lvl, conf in pairs(LOG_LEVEL_OPTIONS) do log.set_dest_clean_time(feature, clean_time) end return function(fmt, ...) - local ok, res = pcall(logger_output, feature, false, lvl, lvl_name, fmt, log_conf, ...) - if not ok then - local info = dgetinfo(2, "S") - lwarn(sformat("[logfeature][%s] format failed: %s, source(%s:%s)", lvl_name, res, info.short_src, info.linedefined)) - return false - end - return res + logger_output(flag, feature, lvl, lvl_name, fmt, ...) end end end \ No newline at end of file diff --git a/script/constant.lua b/script/constant.lua index c91a473a..32e93a3a 100644 --- a/script/constant.lua +++ b/script/constant.lua @@ -4,8 +4,8 @@ local KernCode = enum("KernCode", 0) KernCode.SUCCESS = 0 --成功 KernCode.FAILED = 1 --系统错误,请重试 -KernCode.PARAM_ERROR = 2 --业务参数错误 -KernCode.TOO_FAST = 3 --操作太快 +KernCode.TOO_FAST = 2 --操作太快 +KernCode.PARAM_ERROR = 3 --业务参数错误 KernCode.UPHOLD = 4 --服务维护 KernCode.RPC_FAILED = 5 --RPC调用失败 KernCode.OPERATOR_SELF = 6 --不能对自己操作 diff --git a/script/driver/graylog.lua b/script/driver/graylog.lua index 25e916b8..74143c5b 100644 --- a/script/driver/graylog.lua +++ b/script/driver/graylog.lua @@ -32,7 +32,7 @@ function GrayLog:__init() self.proto = proto if proto == "http" then self.addr = sformat("http://%s:%s/gelf", ip, port) - log_info("[GrayLog][setup] setup http (%s) success!", self.addr) + log_info("[GrayLog][setup] setup http ({}) success!", self.addr) return end self.ip = ip @@ -40,11 +40,11 @@ function GrayLog:__init() if proto == "tcp" then self.tcp = Socket(self) update_mgr:attach_second(self) - log_info("[GrayLog][setup] setup tcp (%s:%s) success!", self.ip, self.port) + log_info("[GrayLog][setup] setup tcp ({}:{}) success!", self.ip, self.port) return end self.udp = luabus.udp() - log_info("[GrayLog][setup] setup udp (%s:%s) success!", self.ip, self.port) + log_info("[GrayLog][setup] setup udp ({}:{}) success!", self.ip, self.port) end function GrayLog:close() @@ -56,10 +56,10 @@ end function GrayLog:on_second() if not self.tcp:is_alive() then if not self.tcp:connect(self.ip, self.port) then - log_err("[GrayLog][on_second] connect (%s:%s) failed!", self.ip, self.port, self.name) + log_err("[GrayLog][on_second] connect ({}:{}) failed!", self.ip, self.port, self.name) return end - log_info("[GrayLog][on_second] connect (%s:%s) success!", self.ip, self.port, self.name) + log_info("[GrayLog][on_second] connect ({}:{}) success!", self.ip, self.port, self.name) end end diff --git a/script/driver/influx.lua b/script/driver/influx.lua index 5974dd29..afef4f69 100644 --- a/script/driver/influx.lua +++ b/script/driver/influx.lua @@ -31,7 +31,7 @@ function Influx:__init(ip, port, org, bucket, token) self.query_addr = sformat("http://%s:%s/api/v2/query", ip, port) self.bucket_addr = sformat("http://%s:%s/api/v2/buckets", ip, port) self.common_headers = { ["Authorization"] = sformat("Token %s", token), ["Content-type"] = "application/json" } - log_info("[Influx] influx driver(%s:%s) setup success!", ip, port) + log_info("[Influx] influx driver({}:{}) setup success!", ip, port) end --line protocol @@ -83,7 +83,7 @@ function Influx:find_bucket(bucket_name) local querys = { name = bucket_name } local ok, status, res = http_client:call_get(self.bucket_addr, querys, self.common_headers) if not ok or status >= 300 then - log_err("[Influx][find_bucket] failed! status: %s, err: %s", status, ok and res or status) + log_err("[Influx][find_bucket] failed! status: {}, err: {}", status, ok and res or status) return false, ok and res or status end local response = json_decode(res) @@ -104,7 +104,7 @@ function Influx:find_org(org_name) local querys = { org = org_name } local ok, status, res = http_client:call_get(self.org_addr, querys, self.common_headers) if not ok or status >= 300 then - log_err("[Influx][find_org] failed! status: %s, err: %s", status, ok and res or status) + log_err("[Influx][find_org] failed! status: {}, err: {}", status, ok and res or status) return false, ok and res or status end local response = json_decode(res) @@ -124,7 +124,7 @@ end function Influx:create_bucket(name, expire_time, description) local cur_org = self:find_org(self.org_name) if not cur_org then - log_err("[Influx][create_bucket] org(%s) config error", self.org_name) + log_err("[Influx][create_bucket] org({}) config error", self.org_name) return false, "org config error" end local data = { @@ -140,7 +140,7 @@ function Influx:create_bucket(name, expire_time, description) } local ok, status, res = http_client:call_post(self.bucket_addr, data, self.common_headers) if not ok or status >= 300 then - log_err("[Influx][create_bucket] failed! status: %s, err: %s", status, ok and res or status) + log_err("[Influx][create_bucket] failed! status: {}, err: {}", status, ok and res or status) return false, ok and res or status end return true, json_decode(res) @@ -151,7 +151,7 @@ function Influx:delete_bucket_by_id(bucket_id) local url = sformat("%s/%s", self.bucket_addr, bucket_id) local ok, status, res = http_client:call_del(url, {}, self.common_headers) if not ok or status >= 300 then - log_err("[Influx][delete_bucket_by_id] failed! status: %s, err: %s", status, ok and res or status) + log_err("[Influx][delete_bucket_by_id] failed! status: {}, err: {}", status, ok and res or status) return false, ok and res or status end return true @@ -161,13 +161,13 @@ end function Influx:delete_bucket(bucket_name) local bucket = self:find_bucket(bucket_name) if not bucket then - log_err("[Influx][delete_bucket] failed! bucket: %s not exist", bucket_name) + log_err("[Influx][delete_bucket] failed! bucket: {} not exist", bucket_name) return false, "bucket not exist" end local url = sformat("%s/%s", self.bucket_addr, bucket.id) local ok, status, res = http_client:call_del(url, {}, self.common_headers) if not ok or status >= 300 then - log_err("[Influx][delete_bucket] failed! status: %s, err: %s", status, ok and res or status) + log_err("[Influx][delete_bucket] failed! status: {}, err: {}", status, ok and res or status) return false, ok and res or status end return true @@ -186,7 +186,7 @@ function Influx:write(measurement, tags, fields) local querys = { org = self.org, bucket = self.bucket } local ok, status, res = http_client:call_post(self.write_addr, line_protocol, headers, querys) if not ok or status >= 300 then - log_err("[Influx][write] failed! status: %s, err: %s", status, ok and res or status) + log_err("[Influx][write] failed! status: {}, err: {}", status, ok and res or status) return false, ok and res or status end return true @@ -211,7 +211,7 @@ function Influx:batch(batch_datas) local querys = { org = self.org, bucket = self.bucket } local ok, status, res = http_client:call_post(self.write_addr, line_protocol, headers, querys) if not ok or status >= 300 then - log_err("[Influx][batch] failed! status: %s, err: %s", status, ok and res or status) + log_err("[Influx][batch] failed! status: {}, err: {}", status, ok and res or status) return false, ok and res or status end return true @@ -227,7 +227,7 @@ function Influx:query(script) local querys = { org = self.org } local ok, status, res = http_client:call_post(self.query_addr, script, headers, querys) if not ok or status >= 300 then - log_err("[Influx][query] failed! status: %s, err: %s", status, ok and res or status) + log_err("[Influx][query] failed! status: {}, err: {}", status, ok and res or status) return false, ok and res or status end return true, self:parse_csv(res) diff --git a/script/driver/mongo.lua b/script/driver/mongo.lua index d6e6cbc4..f7f897ed 100644 --- a/script/driver/mongo.lua +++ b/script/driver/mongo.lua @@ -156,14 +156,14 @@ function MongoDB:login(socket) local id, ip, port = socket.id, socket.ip, socket.port local ok, err = socket:connect(ip, port) if not ok then - log_err("[MongoDB][login] connect db(%s:%s:%s:%s) failed: %s!", ip, port, self.name, id, err) + log_err("[MongoDB][login] connect db({}:{}:{}:{}) failed: {}!", ip, port, self.name, id, err) return false end socket:set_codec(self.codec) if self.user and self.passwd then local aok, aerr = self:auth(socket, self.user, self.passwd) if not aok then - log_err("[MongoDB][login] auth db(%s:%s:%s:%s) failed! because: %s", ip, port, self.name, id, aerr) + log_err("[MongoDB][login] auth db({}:{}:{}:{}) failed! because: {}", ip, port, self.name, id, aerr) self:delive(socket) socket:close() return false @@ -171,7 +171,7 @@ function MongoDB:login(socket) end self.connections[id] = nil tinsert(self.alives, socket) - log_info("[MongoDB][login] connect db(%s:%s:%s:%s) success!", ip, port,self.name, id) + log_info("[MongoDB][login] connect db({}:{}:{}:{}) success!", ip, port,self.name, id) return true, SUCCESS end @@ -263,7 +263,7 @@ function MongoDB:on_socket_error(sock, token, err) self:check_alive() end) for session_id, cmd in pairs(sock.sessions) do - log_warn("[MongoDB][on_socket_error] drop cmd %s-%s)!", cmd, session_id) + log_warn("[MongoDB][on_socket_error] drop cmd {}-{})!", cmd, session_id) thread_mgr:response(session_id, false, err) end sock.sessions = {} @@ -304,10 +304,10 @@ function MongoDB:op_msg(sock, session_id, cmd, ...) sock.sessions[session_id] = nil local utime = lclock_ms() - tick if utime > FAST_MS then - log_warn("[MongoDB][op_msg] cmd (%s:%s) execute so big %s!", cmd, session_id, utime) + log_warn("[MongoDB][op_msg] cmd ({}:{}) execute so big {}!", cmd, session_id, utime) end end) - return thread_mgr:yield(session_id, sformat("mongo_op:%s", cmd), DB_TIMEOUT) + return thread_mgr:yield(session_id, cmd, DB_TIMEOUT) end function MongoDB:adminCommand(sock, cmd, cmd_v, ...) diff --git a/script/driver/mysql.lua b/script/driver/mysql.lua index fdd9fa67..069189ed 100644 --- a/script/driver/mysql.lua +++ b/script/driver/mysql.lua @@ -131,19 +131,19 @@ end function MysqlDB:login(socket) local id, ip, port = socket.id, socket.ip, socket.port if not socket:connect(ip, port) then - log_err("[MysqlDB][login] connect db(%s:%s:%s) failed!", ip, port, id) + log_err("[MysqlDB][login] connect db({}:{}:{}) failed!", ip, port, id) return false end local ok, res = self:auth(socket) if not ok then socket:close() self:delive(socket) - log_err("[MysqlDB][login] auth db(%s:%s:%s) auth failed! because: %s", ip, port, id, res) + log_err("[MysqlDB][login] auth db({}:{}:{}) auth failed! because: {}", ip, port, id, res) return false end self.connections[id] = nil tinsert(self.alives, socket) - log_info("[MysqlDB][login] login db(%s:%s:%s) success!", ip, port, id) + log_info("[MysqlDB][login] login db({}:{}:{}) success!", ip, port, id) return true, SUCCESS end diff --git a/script/driver/nacos.lua b/script/driver/nacos.lua index c7e9599b..3397f931 100644 --- a/script/driver/nacos.lua +++ b/script/driver/nacos.lua @@ -60,7 +60,7 @@ function Nacos:setup(nacos_ns) self.instances_url = sformat("http://%s:%s/nacos/v1/ns/instance/list", ip, port) self.inst_beat_url = sformat("http://%s:%s/nacos/v1/ns/instance/beat", ip, port) self.namespace_url = sformat("http://%s:%s/nacos/v1/console/namespaces", ip, port) - log_info("[Nacos][setup] setup (%s:%s) success!", ip, port) + log_info("[Nacos][setup] setup ({}:{}) success!", ip, port) end --定时获取token thread_mgr:entry(self:address(), function() @@ -82,12 +82,12 @@ function Nacos:auth() if user and pass then local ok, status, res = http_client:call_post(self.login_url, nil, nil, { username = user, password = pass } ) if not ok or status ~= 200 then - log_err("[Nacos][auth] failed! code: %s, err: %s", status, res) + log_err("[Nacos][auth] failed! code: {}, err: {}", status, res) return false, res end local resdata = json_decode(res) self.access_token = resdata.accessToken - log_info("[Nacos][auth] auth success : %s", res) + log_info("[Nacos][auth] auth success : {}", res) else self.access_token = "" end @@ -106,7 +106,7 @@ function Nacos:get_config(data_id, group) } local ok, status, res = http_client:call_get(self.config_url, query) if not ok or status ~= 200 then - log_err("[Nacos][get_config] failed! data_id: %s, code: %s, err: %s", data_id, status, res) + log_err("[Nacos][get_config] failed! data_id: {}, code: {}, err: {}", data_id, status, res) return nil, res end return res @@ -123,7 +123,7 @@ function Nacos:modify_config(data_id, content, group) } local ok, status, res = http_client:call_post(self.config_url, nil, nil, query) if not ok or status ~= 200 then - log_err("[Nacos][modify_config] failed! data_id: %s, code: %s, err: %s", data_id, status, res) + log_err("[Nacos][modify_config] failed! data_id: {}, code: {}, err: {}", data_id, status, res) return false, res end return true @@ -143,7 +143,7 @@ function Nacos:listen_config(data_id, group, md5, on_changed) local lisfmt = sformat("Listening-Configs=%s%s", tconcat(datas, WORD_SEPARATOR), LINE_SEPARATOR) local ok, status, res = http_client:call_post(self.listen_url, lisfmt, headers, query, SECOND_30_MS + 1000) if not ok or status ~= 200 then - log_err("[Nacos][listen_config] failed! data_id: %s, code: %s, err: %s", data_id, status, res) + log_err("[Nacos][listen_config] failed! data_id: {}, code: {}, err: {}", data_id, status, res) thread_mgr:sleep(SECOND_MS) goto contione end @@ -169,7 +169,7 @@ function Nacos:del_config(data_id, group) } local ok, status, res = http_client:call_del(self.config_url, query) if not ok or status ~= 200 then - log_err("[Nacos][del_config] failed! data_id: %s, code: %s, err: %s", data_id, status, res) + log_err("[Nacos][del_config] failed! data_id: {}, code: {}, err: {}", data_id, status, res) return false, res end return true @@ -182,7 +182,7 @@ function Nacos:query_namespaces() local query = { accessToken = self.access_token } local ok, status, res = http_client:call_get(self.namespace_url, query) if not ok or status ~= 200 then - log_err("[Nacos][query_namespaces] failed! code: %s, err: %s", status, res) + log_err("[Nacos][query_namespaces] failed! code: {}, err: {}", status, res) return nil, res end local resdata = json_decode(res) @@ -202,7 +202,7 @@ function Nacos:create_namespace(ns_id, ns_name, ns_desc) } local ok, status, res = http_client:call_post(self.namespace_url, nil, nil, query) if not ok or status ~= 200 then - log_err("[Nacos][create_namespace] failed! ns_name: %s, code: %s, err: %s", ns_name, status, res) + log_err("[Nacos][create_namespace] failed! ns_name: {}, code: {}, err: {}", ns_name, status, res) return false, res end return true @@ -221,7 +221,7 @@ function Nacos:modify_namespace(ns_id, ns_name, ns_desc) } local ok, status, res = http_client:call_put(self.namespace_url, nil, nil, query) if not ok or status ~= 200 then - log_err("[Nacos][modify_namespace] failed! ns_name: %s, code: %s, err: %s", ns_name, status, res) + log_err("[Nacos][modify_namespace] failed! ns_name: {}, code: {}, err: {}", ns_name, status, res) return false, res end return true @@ -235,7 +235,7 @@ function Nacos:del_namespace(ns_id) } local ok, status, res = http_client:call_del(self.namespace_url, query) if not ok or status ~= 200 then - log_err("[Nacos][del_namespace] failed! ns_id: %s, code: %s, err: %s", ns_id, status, res) + log_err("[Nacos][del_namespace] failed! ns_id: {}, code: {}, err: {}", ns_id, status, res) return false, res end return true @@ -259,7 +259,7 @@ function Nacos:query_instances(service_name, group_name) } local ok, status, res = http_client:call_get(self.instances_url, query) if not ok or status ~= 200 then - log_err("[Nacos][query_instances] failed! service_name:%s, code: %s, err: %s", service_name, status, res) + log_err("[Nacos][query_instances] failed! service_name:{}, code: {}, err: {}", service_name, status, res) return nil, res end local insts = {} @@ -294,7 +294,7 @@ function Nacos:query_instance(service_name, host, port, group_name) } local ok, status, res = http_client:call_get(self.instance_url, query) if not ok or status ~= 200 then - log_err("[Nacos][query_instance] failed! service_name:%s, code: %s, err: %s", service_name, status, res) + log_err("[Nacos][query_instance] failed! service_name:{}, code: {}, err: {}", service_name, status, res) return nil, res end return json_decode(res) @@ -329,7 +329,7 @@ function Nacos:regi_instance(service_name, host, port, group_name, metadata) end local ok, status, res = http_client:call_post(self.instance_url, nil, nil, query) if not ok or status ~= 200 then - log_err("[Nacos][regi_instance] failed! service_name:%s, code: %s, err: %s", service_name, status, res) + log_err("[Nacos][regi_instance] failed! service_name:{}, code: {}, err: {}", service_name, status, res) return false, res end return true @@ -357,7 +357,7 @@ function Nacos:sent_beat(service_name, host, port, group_name) } local ok, status, res = http_client:call_put(self.inst_beat_url, nil, nil, query) if not ok or status ~= 200 then - log_err("[Nacos][sent_beat] failed! service_name: %s, code: %s, err: %s", service_name, status, res) + log_err("[Nacos][sent_beat] failed! service_name: {}, code: {}, err: {}", service_name, status, res) return false, res end return res @@ -387,7 +387,7 @@ function Nacos:modify_instance(service_name, host, port, group_name) } local ok, status, res = http_client:call_put(self.instance_url, nil, nil, query) if not ok or status ~= 200 then - log_err("[Nacos][modify_instance] failed! service_name:%s, code: %s, err: %s", service_name, status, res) + log_err("[Nacos][modify_instance] failed! service_name:{}, code: {}, err: {}", service_name, status, res) return false, res end return res @@ -405,7 +405,7 @@ function Nacos:del_instance(service_name, host, port, group_name) } local ok, status, res = http_client:call_del(self.instance_url, query) if not ok or status ~= 200 then - log_err("[Nacos][del_instance] failed! service_name:%s, code: %s, err: %s", service_name, status, res) + log_err("[Nacos][del_instance] failed! service_name:{}, code: {}, err: {}", service_name, status, res) return false, res end return res @@ -430,7 +430,7 @@ function Nacos:create_service(service_name, group_name) } local ok, status, res = http_client:call_post(self.service_url, nil, nil, query) if not ok or status ~= 200 then - log_err("[Nacos][create_service] failed! service_name: %s, code: %s, err: %s", service_name, status, res) + log_err("[Nacos][create_service] failed! service_name: {}, code: {}, err: {}", service_name, status, res) return false, res end return true @@ -453,7 +453,7 @@ function Nacos:modify_service(service_name, group_name) } local ok, status, res = http_client:call_put(self.service_url, nil, nil, query) if not ok or status ~= 200 then - log_err("[Nacos][modify_service] failed! service_name: %s, code: %s, err: %s", service_name, status, res) + log_err("[Nacos][modify_service] failed! service_name: {}, code: {}, err: {}", service_name, status, res) return false, res end return true @@ -469,7 +469,7 @@ function Nacos:del_service(service_name, group_name) } local ok, status, res = http_client:call_del(self.service_url, query) if not ok or status ~= 200 then - log_err("[Nacos][del_service] failed! service_name: %s, code: %s, err: %s", service_name, status, res) + log_err("[Nacos][del_service] failed! service_name: {}, code: {}, err: {}", service_name, status, res) return false, res end return true @@ -485,7 +485,7 @@ function Nacos:query_service(service_name, group_name) } local ok, status, res = http_client:call_get(self.service_url, query) if not ok or status ~= 200 then - log_err("[Nacos][query_service] failed! service_name: %s, code: %s, err: %s", service_name, status, res) + log_err("[Nacos][query_service] failed! service_name: {}, code: {}, err: {}", service_name, status, res) return nil, res end return json_decode(res) @@ -506,7 +506,7 @@ function Nacos:query_services(page, size, group_name) } local ok, status, res = http_client:call_get(self.services_url, query) if not ok or status ~= 200 then - log_err("[Nacos][query_services] failed! group_name: %s, code: %s, err: %s", group_name, status, res) + log_err("[Nacos][query_services] failed! group_name: {}, code: {}, err: {}", group_name, status, res) return nil, res end local jdata = json_decode(res) @@ -517,7 +517,7 @@ end function Nacos:query_switchs() local ok, status, res = http_client:call_get(self.switches_url, {}) if not ok or status ~= 200 then - log_err("[Nacos][query_switchs] failed! code: %s, err: %s", status, res) + log_err("[Nacos][query_switchs] failed! code: {}, err: {}", status, res) return nil, res end return json_decode(res) @@ -531,7 +531,7 @@ function Nacos:modify_switchs(entry, value) } local ok, status, res = http_client:call_put(self.switches_url, nil, nil, query) if not ok or status ~= 200 then - log_err("[Nacos][modify_switchs] failed! entry: %s, code: %s, err: %s", entry, status, res) + log_err("[Nacos][modify_switchs] failed! entry: {}, code: {}, err: {}", entry, status, res) return false, res end return true diff --git a/script/driver/redis.lua b/script/driver/redis.lua index 3f8360a7..62451172 100644 --- a/script/driver/redis.lua +++ b/script/driver/redis.lua @@ -238,14 +238,14 @@ end function RedisDB:login(socket) local id, ip, port = socket.id, socket.ip, socket.port if not socket:connect(ip, port) then - log_err("[RedisDB][login] connect db(%s:%s:%s) failed!", ip, port, id) + log_err("[RedisDB][login] connect db({}:{}:{}) failed!", ip, port, id) return false end socket:set_codec(rediscodec(self.jcodec)) if self.passwd and #self.passwd > 0 then local ok, res = self:auth(socket) if not ok or res ~= "OK" then - log_err("[RedisDB][login] auth db(%s:%s:%s) auth failed! because: %s", ip, port, id, res) + log_err("[RedisDB][login] auth db({}:{}:{}) auth failed! because: {}", ip, port, id, res) self:delive(socket) socket:close() return false @@ -253,7 +253,7 @@ function RedisDB:login(socket) end self.connections[id] = nil tinsert(self.alives, socket) - log_info("[RedisDB][login] login db(%s:%s:%s) success!", ip, port, id) + log_info("[RedisDB][login] login db({}:{}:{}) success!", ip, port, id) event_mgr:fire_frame(function() self:on_socket_alive() end) @@ -304,9 +304,9 @@ function RedisDB:commit(socket, cmd, ...) return false, "send request failed" end self.req_counter:count_increase() - local ok, res = thread_mgr:yield(session_id, sformat("redis_comit:%s", cmd), DB_TIMEOUT) + local ok, res = thread_mgr:yield(session_id, cmd, DB_TIMEOUT) if not ok then - log_err("[RedisDB][commit] exec cmd %s failed: %s", cmd, res) + log_err("[RedisDB][commit] exec cmd {} failed: {}", cmd, res) return ok, res end local convertor = rconvertors[slower(cmd)] diff --git a/script/driver/socket.lua b/script/driver/socket.lua index 21519d4c..48a68f1b 100644 --- a/script/driver/socket.lua +++ b/script/driver/socket.lua @@ -50,13 +50,13 @@ function Socket:listen(ip, port) end self.listener = socket_mgr.listen(ip, port, proto_text) if not self.listener then - log_err("[Socket][listen] failed to listen: %s:%d", ip, port) + log_err("[Socket][listen] failed to listen: {}:{}", ip, port) return false end self.ip, self.port = ip, port - log_info("[Socket][listen] start listen at: %s:%d", ip, port) + log_info("[Socket][listen] start listen at: {}:{}", ip, port) self.listener.on_accept = function(session) - qxpcall(self.on_socket_accept, "on_socket_accept: %s", self, session, ip, port) + qxpcall(self.on_socket_accept, "on_socket_accept: {}", self, session, ip, port) end return true end @@ -81,7 +81,7 @@ function Socket:connect(ip, port, ptype) end local session, cerr = socket_mgr.connect(ip, port, CONNECT_TIMEOUT, proto_text) if not session then - log_err("[Socket][connect] failed to connect: %s:%s err=%s", ip, port, cerr) + log_err("[Socket][connect] failed to connect: {}:{} err={}", ip, port, cerr) return false, cerr end --设置阻塞id @@ -126,7 +126,7 @@ function Socket:on_socket_error(token, err) self.token = nil self.session = nil self.alive = false - log_err("[Socket][on_socket_error] err: %s - %s!", err, token) + log_err("[Socket][on_socket_error] err: {} - {}!", err, token) self.host:on_socket_error(self, token, err) end end) diff --git a/script/driver/webhook.lua b/script/driver/webhook.lua index 400300fb..27005d05 100644 --- a/script/driver/webhook.lua +++ b/script/driver/webhook.lua @@ -1,51 +1,81 @@ --webhook.lua import("network/http_client.lua") +local jencode = json.encode local sformat = string.format -local LIMIT_COUNT = 3 -- 周期内最大次数 +local WEBPATH = environ.get("QUANTA_WEBHOOK_PATH", "./webhooks/") +local log_dump = logfeature.dump("webhooks", WEBPATH, true) +local thread_mgr = quanta.get("thread_mgr") local http_client = quanta.get("http_client") + +local HOST_IP = environ.get("QUANTA_HOST_IP") local HOUR_S = quanta.enum("PeriodTime", "HOUR_S") +local LIMIT_COUNT = 3 -- 周期内最大次数 + local Webhook = singleton() local prop = property(Webhook) +prop:reader("mode", nil) --mode +prop:reader("title", "") --title prop:reader("hooks", {}) --webhook通知接口 prop:reader("notify_limit", {}) --控制同样消息的发送频率 function Webhook:__init() - self.hooks.lark_log = environ.get("QUANTA_LARK_URL") - self.hooks.ding_log = environ.get("QUANTA_DING_URL") - self.hooks.wechat_log = environ.get("QUANTA_WECHAT_URL") + local mode = environ.get("QUANTA_WEBHOOK_MODE") + if mode then + --添加webhook功能 + self.mode = mode + logger.add_monitor(self) + self.title = sformat("%s | %s", HOST_IP, quanta.service_name) + --初始化hooks + self.hooks.lark_log = environ.get("QUANTA_LARK_URL") + self.hooks.ding_log = environ.get("QUANTA_DING_URL") + self.hooks.wechat_log = environ.get("QUANTA_WECHAT_URL") + end +end + +--hook_log +function Webhook:hook_log(url, body) + if self.mode == "log" then + log_dump(jencode(body)) + return + end + --http输出 + thread_mgr:entry(url, function() + http_client:call_post(url, body) + end) end --飞书 -function Webhook:lark_log(url, title, context) - local text = sformat("%s\n %s", title, context) +function Webhook:lark_log(url, context) + local text = sformat("%s\n %s", self.title, context) local body = { msg_type = "text", content = { text = text } } - http_client:call_post(url, body) + self:hook_log(url, body) end --企业微信 --at_members: 成员列表,数组,如 at_members = {"wangqing", "@all"} --at_mobiles: 手机号列表,数组, 如 at_mobiles = {"156xxxx8827", "@all"} -function Webhook:wechat_log(url, title, context, at_mobiles, at_members) - local text = sformat("%s\n %s", title, context) +function Webhook:wechat_log(url, context, at_mobiles, at_members) + local text = sformat("%s\n %s", self.title, context) local body = { msgtype = "text", text = { content = text, mentioned_list = at_members, mentioned_mobile_list = at_mobiles } } - http_client:call_post(url, body) + self:hook_log(url, body) end --钉钉 --at_all: 是否群at,如 at_all = false/false --at_mobiles: 手机号列表,数组, 如 at_mobiles = {"189xxxx8325", "156xxxx8827"} -function Webhook:ding_log(url, title, context, at_mobiles, at_all) - local text = sformat("%s\n %s", title, context) +function Webhook:ding_log(url, context, at_mobiles, at_all) + local text = sformat("%s\n %s", self.title, context) local body = { msgtype = "text", text = { content = text }, at = { atMobiles = at_mobiles, isAtAll = at_all } } - http_client:call_post(url, body) + self:hook_log(url, body) end -function Webhook:notify(title, content, ...) - if next(self.hooks) then +--dispatch_log +function Webhook:dispatch_log(content) + if self.mode then local now = quanta.now local notify = self.notify_limit[content] if not notify then @@ -60,7 +90,7 @@ function Webhook:notify(title, content, ...) end notify.count = notify.count + 1 for hook_api, url in pairs(self.hooks) do - self[hook_api](self, url, title, content, ...) + self[hook_api](self, url, content) end end end diff --git a/script/driver/websocket.lua b/script/driver/websocket.lua index f0fca908..3ff76917 100644 --- a/script/driver/websocket.lua +++ b/script/driver/websocket.lua @@ -55,13 +55,13 @@ function WebSocket:listen(ip, port, ptype) end local listener = socket_mgr.listen(ip, port, proto_text) if not listener then - log_err("[WebSocket][listen] failed to listen: %s:%d", ip, port) + log_err("[WebSocket][listen] failed to listen: {}:{}", ip, port) return false end listener.set_codec(self.hcodec) - log_info("[WebSocket][listen] start listen at: %s:%d", ip, port) + log_info("[WebSocket][listen] start listen at: {}:{}", ip, port) listener.on_accept = function(session) - qxpcall(self.on_socket_accept, "on_socket_accept: %s", self, session, ip, port) + qxpcall(self.on_socket_accept, "on_socket_accept: {}", self, session, ip, port) end self.ip, self.port = ip, port self.listener = listener @@ -79,7 +79,7 @@ function WebSocket:on_socket_error(token, err) self.token = nil self.session = nil self.alive = false - log_err("[WebSocket][on_socket_error] err: %s - %s!", err, token) + log_err("[WebSocket][on_socket_error] err: {} - {}!", err, token) self.host:on_socket_error(self, token, err) end end) @@ -104,7 +104,6 @@ end --accept function WebSocket:accept(session, ip, port) - log_debug("[WebSocket][accept] ip, port: %s, %s", ip, port) local token = session.token session.set_timeout(NETWORK_TIMEOUT) session.on_call_data = function(recv_len, method, ...) @@ -122,7 +121,7 @@ end --握手协议 function WebSocket:on_handshake(session, token, url, params, headers, body) - log_debug("[WebSocket][on_handshake] recv: %s, %s, %s, %s!", url, params, headers, body) + log_debug("[WebSocket][on_handshake] recv: {}, {}, {}, {}!", url, params, headers, body) local upgrade = headers["Upgrade"] if not upgrade or upgrade ~= "websocket" then return self:send_data(400, nil, "can upgrade only to websocket!") diff --git a/script/driver/zipkin.lua b/script/driver/zipkin.lua index c2f6362b..9305ec58 100644 --- a/script/driver/zipkin.lua +++ b/script/driver/zipkin.lua @@ -22,7 +22,7 @@ function Zipkin:__init() if ip and port then self.enable = true self.addr = sformat("http://%s:%s/api/v2/spans", ip, port) - log_info("[Zipkin][setup] setup (%s) success!", self.addr) + log_info("[Zipkin][setup] setup ({}) success!", self.addr) end end @@ -49,7 +49,7 @@ function Zipkin:general(name, trace_id, parent_id) self.spans[trace_id] = { } end trace_span[#trace_span + 1] = span - log_info("[Zipkin][general] new span name:%s, id:%s, trace_id:%s, parent_id:%s!", name, span_id, trace_id, parent_id) + log_info("[Zipkin][general] new span name:{}, id:{}, trace_id:{}, parent_id:{}!", name, span_id, trace_id, parent_id) return span end @@ -115,7 +115,7 @@ function Zipkin:finish_span(span) end local ok, status, res = http_client:call_post(self.addr, span_list) if not ok or status >= 300 then - log_err("[Zipkin][finish_span] post failed! code: %s, err: %s", status, res) + log_err("[Zipkin][finish_span] post failed! code: {}, err: {}", status, res) end self.spans[span.traceId] = nil end) diff --git a/script/feature/config.lua b/script/feature/config.lua index 4c527028..9ec5d551 100644 --- a/script/feature/config.lua +++ b/script/feature/config.lua @@ -37,7 +37,7 @@ function ConfigTable:setup(name, ...) self.indexs = {...} import(sformat("config/%s_cfg.lua", name)) else - log_err("[ConfigTable][setup] keys len illegal. name=%s, size=%s", name, size) + log_err("[ConfigTable][setup] keys len illegal. name={}, size={}", name, size) end end @@ -51,7 +51,7 @@ function ConfigTable:upsert(row) tinsert(row_indexs, row[index]) end if #row_indexs ~= #self.indexs then - log_err("[ConfigTable][upsert] table %s row index lost. row=%s, indexs=%s", self.name, row, self.indexs) + log_err("[ConfigTable][upsert] table {} row index lost. row={}, indexs={}", self.name, row, self.indexs) return end local row_index = self:build_index(tunpack(row_indexs)) @@ -83,12 +83,12 @@ end function ConfigTable:find_one(...) local row_index = self:build_index(...) if not row_index then - log_warn("[ConfigTable][find_one] table %s row index is nil.", self.name) + log_warn("[ConfigTable][find_one] table {} row index is nil.", self.name) return end local row = self.rows[row_index] if not row then - log_warn("[ConfigTable][find_one] table %s row data not found. index=%s", self.name, row_index) + log_warn("[ConfigTable][find_one] table {} row data not found. index={}", self.name, row_index) end return row end @@ -148,7 +148,7 @@ function ConfigTable:find_group(key, gkey) local group_key = gkey or self.group_key local dgroup = self.groups[group_key] if not dgroup then - log_warn("[ConfigTable][find_group] table %s group %s data empty.", self.name, group_key) + log_warn("[ConfigTable][find_group] table {} group {} data empty.", self.name, group_key) end return dgroup[key] end diff --git a/script/feature/counter.lua b/script/feature/counter.lua index 4c800c2c..8caf3231 100644 --- a/script/feature/counter.lua +++ b/script/feature/counter.lua @@ -53,12 +53,12 @@ end function Counter:on_minute() if self.time > 0 then local avg = self.total / self.time - log_info("[Counter][on_minute] last minute %s count => total:%s, avg:%s range:%s-%s!", self.title, self.total, avg, self.min, self.max) + log_info("[Counter][on_minute] last minute {} count => total:{}, avg:{} range:{}-{}!", self.title, self.total, avg, self.min, self.max) self.total = 0 self.max = 0 self.min = 0 else - log_info("[Counter][on_minute] last minute %s count => cur:%s range:%s-%s!", self.title, self.count, self.min, self.max) + log_info("[Counter][on_minute] last minute {} count => cur:{} range:{}-{}!", self.title, self.count, self.min, self.max) self.max = self.count self.min = self.count end diff --git a/script/feature/scheduler.lua b/script/feature/scheduler.lua index 2229059e..14d98d4a 100644 --- a/script/feature/scheduler.lua +++ b/script/feature/scheduler.lua @@ -52,7 +52,7 @@ end function Scheduler:startup(name, entry) local ok, err = pcall(worker.startup, name, entry) if not ok then - log_err("[Scheduler][startup] startup failed: %s", err) + log_err("[Scheduler][startup] startup failed: {}", err) end return ok end diff --git a/script/feature/timer.lua b/script/feature/timer.lua index c37f951e..bd791455 100644 --- a/script/feature/timer.lua +++ b/script/feature/timer.lua @@ -10,7 +10,6 @@ function Timer:__init() end function Timer:__release() - logger.debug("==============================") self:unregister() end diff --git a/script/feature/worker.lua b/script/feature/worker.lua index 7edcdb76..bdb5a30d 100644 --- a/script/feature/worker.lua +++ b/script/feature/worker.lua @@ -30,6 +30,7 @@ local function init_core() import("kernel/thread_mgr.lua") import("kernel/event_mgr.lua") import("kernel/config_mgr.lua") + import("kernel/perfeval_mgr.lua") end --初始化网络 @@ -39,12 +40,6 @@ local function init_network() quanta.socket_mgr = socket_mgr end ---初始化统计 -local function init_statis() - import("agent/proxy_agent.lua") - import("kernel/perfeval_mgr.lua") -end - --协程改造 local function init_coroutine() coroutine.yield = function(...) @@ -75,6 +70,7 @@ end local function init_mainloop() import("kernel/timer_mgr.lua") import("kernel/update_mgr.lua") + import("driver/webhook.lua") event_mgr = quanta.get("event_mgr") thread_mgr = quanta.get("thread_mgr") update_mgr = quanta.get("update_mgr") @@ -88,7 +84,6 @@ function quanta.init() --主循环 init_coroutine() init_mainloop() - init_statis() --网络 init_network() --加载协议 @@ -126,15 +121,15 @@ quanta.run = function() local io_ms = clock_ms - sclock_ms local work_ms = lclock_ms() - sclock_ms if work_ms > HALF_MS or io_ms > FAST_MS then - log_warn("[worker][run] last frame too long => all:%d, net:%d)!", work_ms, io_ms) + log_warn("[worker][run] last frame too long => all:{}, net:{})!", work_ms, io_ms) end - end, "worker run err: %s") + end, "worker run err: {}") end --事件分发 local function notify_rpc(session_id, title, rpc, ...) if rpc == "on_reload" then - log_info("[Worker][on_reload]worker:%s reload for signal !", TITLE) + log_info("[Worker][on_reload]worker:{} reload for signal !", TITLE) --重新加载脚本 quanta.reload() --事件通知 diff --git a/script/kernel.lua b/script/kernel.lua index a317335d..54c358bc 100644 --- a/script/kernel.lua +++ b/script/kernel.lua @@ -24,6 +24,7 @@ local function init_core() import("kernel/thread_mgr.lua") import("kernel/event_mgr.lua") import("kernel/config_mgr.lua") + import("kernel/perfeval_mgr.lua") end --初始化网络 @@ -64,16 +65,11 @@ local function init_mainloop() import("kernel/timer_mgr.lua") import("kernel/update_mgr.lua") import("feature/scheduler.lua") + import("driver/webhook.lua") update_mgr = quanta.get("update_mgr") scheduler = quanta.get("scheduler") end ---初始化统计 -local function init_statis() - import("agent/proxy_agent.lua") - import("kernel/perfeval_mgr.lua") -end - function quanta.init() --核心加载 init_core() @@ -86,7 +82,6 @@ function quanta.init() init_coroutine() init_mainloop() init_network() - init_statis() --其他模式 if quanta.mode <= QuantaMode.ROUTER then --加载monitor @@ -134,6 +129,6 @@ quanta.run = function() local io_ms = clock_ms - sclock_ms local work_ms = lclock_ms() - sclock_ms if work_ms > HALF_MS or io_ms > FAST_MS then - log_warn("[quanta][run] last frame too long => all:%d, net:%d)!", work_ms, io_ms) + log_warn("[quanta][run] last frame too long => all:{}, net:{})!", work_ms, io_ms) end end diff --git a/script/kernel/config_mgr.lua b/script/kernel/config_mgr.lua index 20f9e35c..3ecebf16 100644 --- a/script/kernel/config_mgr.lua +++ b/script/kernel/config_mgr.lua @@ -60,7 +60,7 @@ end function ConfigMgr:get_table(name) local conf_tab = self.table_list[name] if not conf_tab then - log_warn("[ConfigMgr][get_table] table %s not init.", name) + log_warn("[ConfigMgr][get_table] table {} not init.", name) end return conf_tab end diff --git a/script/kernel/event_mgr.lua b/script/kernel/event_mgr.lua index b2c2bfb2..b7ac9c14 100644 --- a/script/kernel/event_mgr.lua +++ b/script/kernel/event_mgr.lua @@ -59,7 +59,7 @@ end --invalidate function EventMgr:invalidate(obj, func) if not obj[func] then - log_warn("[EventMgr][invalidate] obj(%s) isn't %s method!", obj:source(), func) + log_warn("[EventMgr][invalidate] obj({}) isn't {} method!", obj:source(), func) return end self.invalidates[obj] = func diff --git a/script/kernel/perfeval_mgr.lua b/script/kernel/perfeval_mgr.lua index 475648de..81ccf98d 100644 --- a/script/kernel/perfeval_mgr.lua +++ b/script/kernel/perfeval_mgr.lua @@ -6,8 +6,6 @@ local env_status = environ.status local tclock_ms = timer.clock_ms local qdefer = quanta.defer -local proxy_agent = quanta.get("proxy_agent") - local PerfevalMgr = singleton() local prop = property(PerfevalMgr) prop:reader("eval_id", 0) @@ -75,8 +73,8 @@ function PerfevalMgr:start(eval_name) end function PerfevalMgr:stop(eval_data) - local clock_ms = tclock_ms() - proxy_agent:statistics("on_perfeval", eval_data, clock_ms) + --local clock_ms = tclock_ms() + --proxy_agent:statistics("on_perfeval", eval_data, clock_ms) self.eval_list[eval_data.co][eval_data.eval_id] = nil end diff --git a/script/kernel/protobuf_mgr.lua b/script/kernel/protobuf_mgr.lua index 2aaceb27..a7b3e03d 100644 --- a/script/kernel/protobuf_mgr.lua +++ b/script/kernel/protobuf_mgr.lua @@ -40,7 +40,7 @@ end function ProtobufMgr:callback_id(cmd_id) local pb_cbid = self.pb_callbacks[cmd_id] if not pb_cbid then - log_warn("[ProtobufMgr][callback_id] cmdid %s find callback_id is nil", cmd_id) + log_warn("[ProtobufMgr][callback_id] cmdid {} find callback_id is nil", cmd_id) end return pb_cbid end @@ -62,13 +62,13 @@ function ProtobufMgr:enum(ename, ekey) local emun = ncmd_cs[ename] if not emun then local info = dgetinfo(2, "S") - log_warn("[ProtobufMgr][enum] %s not initial! source(%s:%s)", ename, info.short_src, info.linedefined) + log_warn("[ProtobufMgr][enum] {} not initial! source({}:{})", ename, info.short_src, info.linedefined) return end local value = emun[ekey] if not value then local info = dgetinfo(2, "S") - log_warn("[ProtobufMgr][enum] %s.%s not defined! source(%s:%s)", ename, ekey, info.short_src, info.linedefined) + log_warn("[ProtobufMgr][enum] %s.%s not defined! source({}:{})", ename, ekey, info.short_src, info.linedefined) return end return value @@ -121,7 +121,7 @@ end function ProtobufMgr:encode(pb_cmd, data) local proto = self.pb_indexs[pb_cmd] if not proto then - log_err("[ProtobufMgr][encode] find proto failed! cmd:%s", pb_cmd) + log_err("[ProtobufMgr][encode] find proto failed! cmd:{}", pb_cmd) return end local ok, pb_str = pcall(pb_encode, proto.name, data or {}) @@ -140,7 +140,7 @@ end function ProtobufMgr:decode(pb_cmd, pb_str) local proto = self.pb_indexs[pb_cmd] if not proto then - log_err("[ProtobufMgr][decode] find proto failed! cmd:%s", pb_cmd) + log_err("[ProtobufMgr][decode] find proto failed! cmd:{}", pb_cmd) return end local ok, pb_data = pcall(pb_decode, proto.name, pb_str) @@ -153,7 +153,7 @@ local function pbenum(full_name) return function(_, enum_name) local enum_val = pb_enum_id(full_name, enum_name) if not enum_val then - log_warn("[pbenum] no enum %s.%s", full_name, enum_name) + log_warn("[pbenum] no enum {}.{}", full_name, enum_name) end return enum_val end @@ -191,14 +191,14 @@ function ProtobufMgr:define_command(full_name, proto_name) end return end - --log_warn("[ProtobufMgr][define_command] proto_name: [%s] can't find msg enum:[%s] !", proto_name, msg_name) + --log_warn("[ProtobufMgr][define_command] proto_name: [{}] can't find msg enum:[{}] !", proto_name, msg_name) end end function ProtobufMgr:register(doer, pb_name, callback) local proto = self.pb_indexs[pb_name] if not proto then - log_warn("[ProtobufMgr][register] proto_name: [%s] can't find!", pb_name) + log_warn("[ProtobufMgr][register] proto_name: [{}] can't find!", pb_name) return end event_mgr:add_cmd_listener(doer, proto.id, callback) diff --git a/script/kernel/router_mgr.lua b/script/kernel/router_mgr.lua index f3490f60..29bde601 100644 --- a/script/kernel/router_mgr.lua +++ b/script/kernel/router_mgr.lua @@ -34,7 +34,7 @@ end --服务关闭 function RouterMgr:on_service_close(id, name) - log_debug("[RouterMgr][on_service_close] node: %s-%s", name, id) + log_debug("[RouterMgr][on_service_close] node: {}-{}", name, id) local router = self.routers[id] if router then router:set_holder(nil) @@ -43,13 +43,13 @@ end --服务上线 function RouterMgr:on_service_ready(id, name, info) - log_debug("[RouterMgr][on_service_ready] node: %s-%s, info: %s", name, id, info) + log_debug("[RouterMgr][on_service_ready] node: {}-{}, info: {}", name, id, info) self:add_router(info.id, info.ip, info.port) end --服务被踢下线 function RouterMgr:rpc_service_kickout(router_id, reason) - log_err("[RouterMgr][rpc_service_kickout] reason:%s router_id:%s", reason, router_id) + log_err("[RouterMgr][rpc_service_kickout] reason:{} router_id:{}", reason, router_id) signal_quit() end @@ -66,13 +66,13 @@ end --错误处理 function RouterMgr:on_socket_error(client, token, err) - log_err("[RouterMgr][on_socket_error] router lost %s:%s, err=%s", client.ip, client.port, err) + log_err("[RouterMgr][on_socket_error] router lost {}:{}, err={}", client.ip, client.port, err) self:check_router() end --连接成功 function RouterMgr:on_socket_connect(client, res) - log_info("[RouterMgr][on_socket_connect] router %s:%s success!", client.ip, client.port) + log_info("[RouterMgr][on_socket_connect] router {}:{} success!", client.ip, client.port) client:register() self:check_router() end diff --git a/script/kernel/thread_mgr.lua b/script/kernel/thread_mgr.lua index dbb61041..27a913a4 100644 --- a/script/kernel/thread_mgr.lua +++ b/script/kernel/thread_mgr.lua @@ -114,13 +114,13 @@ function ThreadMgr:create_co(f) local co = pool:pop() if co == nil then co = co_create(function(...) - qxpcall(f, "[ThreadMgr][co_create] fork error: %s", ...) + qxpcall(f, "[ThreadMgr][co_create] fork error: {}", ...) while true do f = nil pool:push(co) f = co_yield() if type(f) == "function" then - qxpcall(f, "[ThreadMgr][co_create] fork error: %s", co_yield()) + qxpcall(f, "[ThreadMgr][co_create] fork error: {}", co_yield()) end end end) @@ -143,7 +143,7 @@ end function ThreadMgr:response(session_id, ...) local context = self.coroutine_yields[session_id] if not context then - log_warn("[ThreadMgr][response] unknown session_id(%s) response!", session_id) + log_warn("[ThreadMgr][response] unknown session_id({}) response!", session_id) return end self.coroutine_yields[session_id] = nil @@ -213,7 +213,7 @@ function ThreadMgr:on_second(clock_ms) local session_id = context.session_id self.coroutine_yields[session_id] = nil if context.title then - log_err("[ThreadMgr][on_second] session_id(%s:%s) timeout!", session_id, context.title) + log_err("[ThreadMgr][on_second] session_id({}:{}) timeout!", session_id, context.title) end self:resume(context.co, false, sformat("%s timeout", context.title), session_id) end diff --git a/script/kernel/update_mgr.lua b/script/kernel/update_mgr.lua index 1f9b778c..ef49eaea 100644 --- a/script/kernel/update_mgr.lua +++ b/script/kernel/update_mgr.lua @@ -146,7 +146,7 @@ function UpdateMgr:update_by_time(now, clock_ms) if cur_hour == 4 then collectgarbage("collect") end - log_info("[UpdateMgr][update]now lua mem: %s!", collectgarbage("count")) + log_info("[UpdateMgr][update]now lua mem: {}!", collectgarbage("count")) end function UpdateMgr:check_signal(scheduler) @@ -179,7 +179,7 @@ end --添加对象到小时更新循环 function UpdateMgr:attach_hour(obj) if not obj.on_hour then - log_warn("[UpdateMgr][attach_hour] obj(%s) isn't on_hour method!", obj:source()) + log_warn("[UpdateMgr][attach_hour] obj({}) isn't on_hour method!", obj:source()) return end self.hour_objs[obj] = true @@ -192,7 +192,7 @@ end --添加对象到分更新循环 function UpdateMgr:attach_minute(obj) if not obj.on_minute then - log_warn("[UpdateMgr][attach_minute] obj(%s) isn't on_minute method!", obj:source()) + log_warn("[UpdateMgr][attach_minute] obj({}) isn't on_minute method!", obj:source()) return end self.minute_objs[obj] = true @@ -205,7 +205,7 @@ end --添加对象到秒更新循环 function UpdateMgr:attach_second(obj) if not obj.on_second then - log_warn("[UpdateMgr][attach_second] obj(%s) isn't on_second method!", obj:source()) + log_warn("[UpdateMgr][attach_second] obj({}) isn't on_second method!", obj:source()) return end self.second_objs[obj] = obj:address() @@ -218,7 +218,7 @@ end --添加对象到5秒更新循环 function UpdateMgr:attach_second5(obj) if not obj.on_second5 then - log_warn("[UpdateMgr][attach_second5] obj(%s) isn't on_second5 method!", obj:source()) + log_warn("[UpdateMgr][attach_second5] obj({}) isn't on_second5 method!", obj:source()) return end self.second5_objs[obj] = true @@ -231,7 +231,7 @@ end --添加对象到30秒更新循环 function UpdateMgr:attach_second30(obj) if not obj.on_second30 then - log_warn("[UpdateMgr][attach_second30] obj(%s) isn't on_second30 method!", obj:source()) + log_warn("[UpdateMgr][attach_second30] obj({}) isn't on_second30 method!", obj:source()) return end self.second30_objs[obj] = true @@ -244,7 +244,7 @@ end --添加对象到帧更新循环 function UpdateMgr:attach_frame(obj) if not obj.on_frame then - log_warn("[UpdateMgr][attach_frame] obj(%s) isn't on_frame method!", obj:source()) + log_warn("[UpdateMgr][attach_frame] obj({}) isn't on_frame method!", obj:source()) return end self.frame_objs[obj] = obj:address() @@ -257,7 +257,7 @@ end --添加对象到快帧更新循环 function UpdateMgr:attach_fast(obj) if not obj.on_fast then - log_warn("[UpdateMgr][attach_fast] obj(%s) isn't on_fast method!", obj:source()) + log_warn("[UpdateMgr][attach_fast] obj({}) isn't on_fast method!", obj:source()) return end self.fast_objs[obj] = obj:address() @@ -270,7 +270,7 @@ end --添加对象到程序退出通知列表 function UpdateMgr:attach_quit(obj) if not obj.on_quit then - log_warn("[UpdateMgr][attach_quit] obj(%s) isn't on_quit method!", obj) + log_warn("[UpdateMgr][attach_quit] obj({}) isn't on_quit method!", obj) return end self.quit_objs[obj] = true diff --git a/script/network/http_client.lua b/script/network/http_client.lua index 5d65fea9..40c1a42c 100644 --- a/script/network/http_client.lua +++ b/script/network/http_client.lua @@ -97,7 +97,7 @@ function HttpClient:send_request(url, timeout, querys, headers, method, datas) local fmt_url = self:format_url(url, querys) local request, curl_handle = curlm_mgr.create_request(fmt_url, to) if not request then - log_err("[HttpClient][send_request] failed : %s", curl_handle) + log_err("[HttpClient][send_request] failed : {}", curl_handle) return false end if not headers then @@ -112,7 +112,7 @@ function HttpClient:send_request(url, timeout, querys, headers, method, datas) end local ok, err = request[method](datas or "") if not ok then - log_err("[HttpClient][send_request] curl %s failed: %s!", method, err) + log_err("[HttpClient][send_request] curl {} failed: {}!", method, err) return false end local session_id = thread_mgr:build_session_id() diff --git a/script/network/http_server.lua b/script/network/http_server.lua index 598a0467..916812c8 100644 --- a/script/network/http_server.lua +++ b/script/network/http_server.lua @@ -36,12 +36,12 @@ function HttpServer:setup(http_addr) self.ip, self.port = saddr(http_addr) local socket = Socket(self) if not socket:listen(self.ip, self.port) then - log_err("[HttpServer][setup] now listen %s failed", http_addr) + log_err("[HttpServer][setup] now listen {} failed", http_addr) signalquit(1) return end socket:set_codec(self.hcodec) - log_info("[HttpServer][setup] listen(%s:%s) success!", self.ip, self.port) + log_info("[HttpServer][setup] listen({}:{}) success!", self.ip, self.port) self.listener = socket end @@ -52,21 +52,21 @@ end function HttpServer:on_socket_error(socket, token, err) if socket == self.listener then - log_info("[HttpServer][on_socket_error] listener(%s:%s) close!", self.ip, self.port) + log_info("[HttpServer][on_socket_error] listener({}:{}) close!", self.ip, self.port) self.listener = nil return end - log_debug("[HttpServer][on_socket_error] client(token:%s) close(%s)!", token, err) + log_debug("[HttpServer][on_socket_error] client(token:{}) close({})!", token, err) self.clients[token] = nil end function HttpServer:on_socket_accept(socket, token) - --log_debug("[HttpServer][on_socket_accept] client(token:%s) connected!", token) + --log_debug("[HttpServer][on_socket_accept] client(token:{}) connected!", token) self.clients[token] = socket end function HttpServer:on_socket_recv(socket, method, url, params, headers, body) - -- log_debug("[HttpServer][on_socket_recv] recv: %s, %s, %s, %s, %s!", method, url, params, headers, body) + log_debug("[HttpServer][on_socket_recv] recv: {}, {}, {}, {}, {}!", method, url, params, headers, body) if method == "GET" then return self:on_http_request(self.get_handlers, socket, url, params, headers) end @@ -83,25 +83,25 @@ end --注册get回调 function HttpServer:register_get(url, handler, target) - log_debug("[HttpServer][register_get] url: %s", url) + log_debug("[HttpServer][register_get] url: {}", url) self.get_handlers[url] = { handler, target } end --注册post回调 function HttpServer:register_post(url, handler, target) - log_debug("[HttpServer][register_post] url: %s", url) + log_debug("[HttpServer][register_post] url: {}", url) self.post_handlers[url] = { handler, target } end --注册put回调 function HttpServer:register_put(url, handler, target) - log_debug("[HttpServer][register_put] url: %s", url) + log_debug("[HttpServer][register_put] url: {}", url) self.put_handlers[url] = { handler, target } end --注册del回调 function HttpServer:register_del(url, handler, target) - log_debug("[HttpServer][register_del] url: %s", url) + log_debug("[HttpServer][register_del] url: {}", url) self.del_handlers[url] = { handler, target } end @@ -126,7 +126,7 @@ function HttpServer:on_http_request(handlers, socket, url, ...) if type(handler) == "function" then local ok, response, headers = pcall(handler, target, url, ...) if not ok then - log_err("[HttpServer][on_http_request] ok:%s, response:%s", ok, response) + log_err("[HttpServer][on_http_request] ok:{}, response:{}", ok, response) response = { code = 1, msg = response } end self:response(socket, 200, response, headers) @@ -134,7 +134,7 @@ function HttpServer:on_http_request(handlers, socket, url, ...) end end end - log_warn("[HttpServer][on_http_request] request %s hasn't process!", url) + log_warn("[HttpServer][on_http_request] request {} hasn't process!", url) self:response(socket, 404, "this http request hasn't process!") end diff --git a/script/network/net_client.lua b/script/network/net_client.lua index fa83b310..70b8ebb3 100644 --- a/script/network/net_client.lua +++ b/script/network/net_client.lua @@ -1,14 +1,12 @@ --net_client.lua local log_err = logger.err -local log_fatal = logger.fatal local qeval = quanta.eval local qxpcall = quanta.xpcall local event_mgr = quanta.get("event_mgr") local socket_mgr = quanta.get("socket_mgr") local thread_mgr = quanta.get("thread_mgr") -local proxy_agent = quanta.get("proxy_agent") local proto_pb = luabus.eproto_type.pb @@ -40,7 +38,7 @@ function NetClient:connect(block) end local socket, cerr = socket_mgr.connect(self.ip, self.port, CONNECT_TIMEOUT, proto_pb) if not socket then - log_err("[NetClient][connect] failed to connect: %s:%s err=%s", self.ip, self.port, cerr) + log_err("[NetClient][connect] failed to connect: {}:{} err={}", self.ip, self.port, cerr) return false, cerr end --设置阻塞id @@ -62,8 +60,8 @@ function NetClient:connect(block) end end socket.on_call_pb = function(recv_len, session_id, cmd_id, flag, type, crc8, body) - proxy_agent:statistics("on_proto_recv", cmd_id, recv_len) - qxpcall(self.on_socket_rpc, "on_socket_rpc: %s", self, socket, cmd_id, flag, type, session_id, body) + --:statistics("on_proto_recv", cmd_id, recv_len) + qxpcall(self.on_socket_rpc, "on_socket_rpc: {}", self, socket, cmd_id, flag, type, session_id, body) end socket.on_error = function(token, err) thread_mgr:fork(function() @@ -112,22 +110,17 @@ function NetClient:close() end end -function NetClient:write(cmd, data, type, session_id, flag) +function NetClient:write(cmd_id, data, type, session_id, flag) if not self.alive then return false end - local body, cmd_id, pflag = self:encode(cmd, data, flag) - if not body then - log_fatal("[NetClient][write] encode failed! data (%s-%s)", cmd_id, body) - return false - end -- call lbus - local send_len = self.socket.call_pb(cmd_id, pflag, type, session_id, data) + local send_len = self.socket.call_pb(session_id, cmd_id, flag, type, 0, data) if send_len < 0 then log_err("[NetClient][write] call_pb failed! code:%s", send_len) return false end - proxy_agent:statistics("on_proto_send", cmd_id, send_len) + --proxy_agent:statistics("on_proto_send", cmd_id, send_len) return true end diff --git a/script/network/net_server.lua b/script/network/net_server.lua index bf252eeb..3f9c50bc 100644 --- a/script/network/net_server.lua +++ b/script/network/net_server.lua @@ -14,7 +14,6 @@ local event_mgr = quanta.get("event_mgr") local thread_mgr = quanta.get("thread_mgr") local socket_mgr = quanta.get("socket_mgr") local protobuf_mgr = quanta.get("protobuf_mgr") -local proxy_agent = quanta.get("proxy_agent") local FLAG_REQ = quanta.enum("FlagMask", "REQ") local FLAG_RES = quanta.enum("FlagMask", "RES") @@ -48,22 +47,22 @@ end function NetServer:setup(ip, port, induce) -- 开启监听 if not ip or not port then - log_err("[NetServer][setup] ip:%s or port:%s is nil", ip, port) + log_err("[NetServer][setup] ip:{} or port:{} is nil", ip, port) signalquit() return end local real_port = induce and (port + quanta.order - 1) or port local listener = socket_mgr.listen(ip, real_port, proto_pb) if not listener then - log_err("[NetServer][setup] failed to listen: %s:%d", ip, real_port) + log_err("[NetServer][setup] failed to listen: {}:{}", ip, real_port) signalquit() return end - log_info("[NetServer][setup] start listen at: %s:%d", ip, real_port) + log_info("[NetServer][setup] start listen at: {}:{}", ip, real_port) -- 安装回调 listener.set_codec(self.codec) listener.on_accept = function(session) - qxpcall(self.on_socket_accept, "on_socket_accept: %s", self, session) + qxpcall(self.on_socket_accept, "on_socket_accept: {}", self, session) end self.listener = listener self.ip, self.port = ip, real_port @@ -86,14 +85,14 @@ function NetServer:on_socket_accept(session) session.call_client = function(cmd_id, flag, session_id, body) local send_len = session.call_pb(session_id, cmd_id, flag, 0, 0, body) if send_len <= 0 then - log_err("[NetServer][call_client] call_pb failed! code:%s", send_len) + log_err("[NetServer][call_client] call_pb failed! code:{}", send_len) return false end return true end session.on_call_pb = function(recv_len, session_id, cmd_id, flag, type, crc8, body) local now_ms = quanta.now_ms - if session.lc_crc == crc8 and now_ms - session.lc_time < FAST_MS then + if crc8 > 0 and session.lc_crc == crc8 and now_ms - session.lc_time < FAST_MS then self:callback_errcode(session, cmd_id, TOO_FAST, session_id) return end @@ -103,8 +102,8 @@ function NetServer:on_socket_accept(session) session.fc_packet = session.fc_packet + 1 session.fc_bytes = session.fc_bytes + recv_len end - proxy_agent:statistics("on_proto_recv", cmd_id, recv_len) - qxpcall(self.on_socket_recv, "on_socket_recv: %s", self, session, cmd_id, flag, type, session_id, body) + --proxy_agent:statistics("on_proto_recv", cmd_id, recv_len) + qxpcall(self.on_socket_recv, "on_socket_recv: {}", self, session, cmd_id, flag, type, session_id, body) end -- 绑定网络错误回调(断开) session.on_error = function(stoken, err) @@ -116,7 +115,7 @@ end function NetServer:write(session, cmd, data, session_id, flag) if session.token == 0 then - log_fatal("[NetServer][write] session lost! cmd_id:%s-(%s)", cmd, data) + log_fatal("[NetServer][write] session lost! cmd_id:{}-({})", cmd, data) return false end return session.call_client(cmd, flag, session_id, data) @@ -162,7 +161,7 @@ function NetServer:on_socket_recv(session, cmd_id, flag, type, session_id, body) local _ = qeval(cmd_id) local result = event_mgr:notify_listener("on_socket_cmd", _session, typ, cmd, cbody, session_id) if not result[1] then - log_err("[NetServer][on_socket_recv] on_socket_cmd failed! cmd_id:%s", cmd_id) + log_err("[NetServer][on_socket_recv] on_socket_cmd failed! cmd_id:{}", cmd_id) end end thread_mgr:fork(dispatch_rpc_message, session, type, cmd_id, body) @@ -221,7 +220,7 @@ function NetServer:add_session(session) if not self.sessions[token] then self.sessions[token] = session self.session_count = self.session_count + 1 - proxy_agent:statistics("on_conn_update", self.session_type, self.session_count) + --proxy_agent:statistics("on_conn_update", self.session_type, self.session_count) end return token end @@ -232,7 +231,7 @@ function NetServer:remove_session(token) if session then self.sessions[token] = nil self.session_count = self.session_count - 1 - proxy_agent:statistics("on_conn_update", self.session_type, self.session_count) + --proxy_agent:statistics("on_conn_update", self.session_type, self.session_count) return session end end diff --git a/script/network/rpc_client.lua b/script/network/rpc_client.lua index 1f8c284a..a82d4ac8 100644 --- a/script/network/rpc_client.lua +++ b/script/network/rpc_client.lua @@ -10,7 +10,6 @@ local event_mgr = quanta.get("event_mgr") local timer_mgr = quanta.get("timer_mgr") local socket_mgr = quanta.get("socket_mgr") local thread_mgr = quanta.get("thread_mgr") -local proxy_agent = quanta.get("proxy_agent") local FLAG_REQ = quanta.enum("FlagMask", "REQ") local FLAG_RES = quanta.enum("FlagMask", "RES") @@ -59,10 +58,10 @@ end --调用rpc后续处理 function RpcClient:on_call_router(rpc, token, send_len) if send_len > 0 then - proxy_agent:statistics("on_rpc_send", rpc, send_len) + --proxy_agent:statistics("on_rpc_send", rpc, send_len) return true, send_len end - log_err("[RpcClient][on_call_router] rpc %s call failed! code:%s", rpc, send_len) + log_err("[RpcClient][on_call_router] rpc {} call failed! code:{}", rpc, send_len) return false end @@ -75,12 +74,12 @@ function RpcClient:connect() --开始连接 local socket, cerr = socket_mgr.connect(self.ip, self.port, CONNECT_TIMEOUT) if not socket then - log_err("[RpcClient][connect] failed to connect: %s:%s err=%s", self.ip, self.port, cerr) + log_err("[RpcClient][connect] failed to connect: {}:{} err={}", self.ip, self.port, cerr) return false, cerr end local token = socket.token socket.on_call = function(recv_len, session_id, rpc_flag, ...) - qxpcall(self.on_socket_rpc, "on_socket_rpc: %s", self, socket, session_id, rpc_flag, recv_len, ...) + qxpcall(self.on_socket_rpc, "on_socket_rpc: {}", self, socket, session_id, rpc_flag, recv_len, ...) end socket.call_rpc = function(rpc, session_id, rpc_flag, ...) local send_len = socket.call(session_id, rpc_flag, quanta.id, rpc, ...) @@ -121,7 +120,7 @@ function RpcClient:connect() end socket.on_connect = function(res) if res == "ok" then - qxpcall(self.on_socket_connect, "on_socket_connect: %s", self, socket, res) + qxpcall(self.on_socket_connect, "on_socket_connect: {}", self, socket, res) else self:on_socket_error(token, res) end @@ -131,7 +130,7 @@ end -- 主动关闭连接 function RpcClient:close() - log_err("[RpcClient][close] socket %s:%s!", self.ip, self.port) + log_err("[RpcClient][close] socket {}:{}!", self.ip, self.port) if self.socket then self.socket.close() self.alive = false @@ -144,7 +143,7 @@ function RpcClient:on_socket_rpc(socket, session_id, rpc_flag, recv_len, source, if rpc == "on_heartbeat" then return end - proxy_agent:statistics("on_rpc_recv", rpc, recv_len) + --proxy_agent:statistics("on_rpc_recv", rpc, recv_len) if session_id == 0 or rpc_flag == FLAG_REQ then local function dispatch_rpc_message(...) local _ = qeval(rpc) @@ -162,7 +161,7 @@ end --错误处理 function RpcClient:on_socket_error(token, err) thread_mgr:fork(function() - log_err("[RpcClient][on_socket_error] socket %s:%s %s!", self.ip, self.port, err) + log_err("[RpcClient][on_socket_error] socket {}:{} {}!", self.ip, self.port, err) self.socket = nil self.alive = false if self.holder then @@ -176,7 +175,7 @@ end --连接成功 function RpcClient:on_socket_connect(socket) - --log_info("[RpcClient][on_socket_connect] connect to %s:%s success!", self.ip, self.port) + --log_info("[RpcClient][on_socket_connect] connect to {}:{} success!", self.ip, self.port) thread_mgr:fork(function() self.alive = true self.holder:on_socket_connect(self) diff --git a/script/network/rpc_server.lua b/script/network/rpc_server.lua index 0f30d748..8132ebc8 100644 --- a/script/network/rpc_server.lua +++ b/script/network/rpc_server.lua @@ -13,7 +13,6 @@ local hash_code = codec.hash_code local event_mgr = quanta.get("event_mgr") local thread_mgr = quanta.get("thread_mgr") local socket_mgr = quanta.get("socket_mgr") -local proxy_agent = quanta.get("proxy_agent") local FLAG_REQ = quanta.enum("FlagMask", "REQ") local FLAG_RES = quanta.enum("FlagMask", "RES") @@ -35,31 +34,31 @@ prop:reader("holder", nil) --持有者 --induce:根据 order 推导port function RpcServer:__init(holder, ip, port, induce) if not ip or not port then - log_err("[RpcServer][setup] ip:%s or port:%s is nil", ip, port) + log_err("[RpcServer][setup] ip:{} or port:{} is nil", ip, port) signalquit() return end local real_port = induce and (port + quanta.order - 1) or port local listener = socket_mgr.listen(ip, real_port) if not listener then - log_err("[RpcServer][setup] now listen %s:%s failed", ip, real_port) + log_err("[RpcServer][setup] now listen {}:{} failed", ip, real_port) signalquit() return end listener.on_accept = function(client) - qxpcall(self.on_socket_accept, "on_socket_accept: %s", self, client) + qxpcall(self.on_socket_accept, "on_socket_accept: {}", self, client) end self.holder = holder self.listener = listener self.ip, self.port = ip, real_port - log_info("[RpcServer][setup] now listen %s:%s success!", ip, real_port) + log_info("[RpcServer][setup] now listen {}:{} success!", ip, real_port) event_mgr:add_listener(self, "rpc_heartbeat") event_mgr:add_listener(self, "rpc_register") end --rpc事件 function RpcServer:on_socket_rpc(client, session_id, rpc_flag, recv_len, source, rpc, ...) - proxy_agent:statistics("on_rpc_recv", rpc, recv_len) + --proxy_agent:statistics("on_rpc_recv", rpc, recv_len) if session_id == 0 or rpc_flag == FLAG_REQ then local function dispatch_rpc_message(...) local _ = qeval(rpc) @@ -96,14 +95,14 @@ function RpcServer:on_socket_accept(client) client.call_rpc = function(rpc, session_id, rpc_flag, ...) local send_len = client.call(session_id, rpc_flag, 0, rpc, ...) if send_len < 0 then - log_err("[RpcServer][call_rpc] call failed! code:%s", send_len) + log_err("[RpcServer][call_rpc] call failed! code:{}", send_len) return false end - proxy_agent:statistics("on_rpc_send", rpc, send_len) + --proxy_agent:statistics("on_rpc_send", rpc, send_len) return true, SUCCESS end client.on_call = function(recv_len, session_id, rpc_flag, ...) - qxpcall(self.on_socket_rpc, "on_socket_rpc: %s", self, client, session_id, rpc_flag, recv_len, ...) + qxpcall(self.on_socket_rpc, "on_socket_rpc: {}", self, client, session_id, rpc_flag, recv_len, ...) end client.on_transfer = function(recv_len, session_id, service_id, target_id, slice) local function dispatch_rpc_message() @@ -220,7 +219,7 @@ function RpcServer:rpc_register(client, node) if eclient then eclient.id = nil self:send(eclient, "rpc_service_kickout", quanta.id, "service replace") - log_warn("[RpcServer][rpc_heartbeat] client(%s) be kickout, service replace!", eclient.name) + log_warn("[RpcServer][rpc_heartbeat] client({}) be kickout, service replace!", eclient.name) end -- 通知注册 client.id = client_id diff --git a/script/network/ws_server.lua b/script/network/ws_server.lua index 758ecb71..6cd0b4ba 100644 --- a/script/network/ws_server.lua +++ b/script/network/ws_server.lua @@ -21,32 +21,32 @@ function WSServer:setup(ws_addr) self.ip, self.port = saddr(ws_addr) local socket = WebSocket(self) if not socket:listen(self.ip, self.port) then - log_info("[WSServer][setup] now listen %s failed", ws_addr) + log_info("[WSServer][setup] now listen {} failed", ws_addr) signalquit(1) return end - log_info("[WSServer][setup] listen(%s:%s) success!", self.ip, self.port) + log_info("[WSServer][setup] listen({}:{}) success!", self.ip, self.port) self.listener = socket end function WSServer:on_socket_error(socket, token, err) if socket == self.listener then - log_info("[WSServer][on_socket_error] listener(%s:%s) close!", self.ip, self.port) + log_info("[WSServer][on_socket_error] listener({}:{}) close!", self.ip, self.port) self.listener = nil return end - log_debug("[WSServer][on_socket_error] client(token:%s) close!", token) + log_debug("[WSServer][on_socket_error] client(token:{}) close!", token) self.clients[token] = nil end function WSServer:on_socket_accept(socket, token) - log_debug("[WSServer][on_socket_accept] client(token:%s) connected!", token) + log_debug("[WSServer][on_socket_accept] client(token:{}) connected!", token) self.clients[token] = socket end --回调 function WSServer:on_socket_recv(socket, token, message) - log_debug("[WSServer][on_socket_recv] client(token:%s) msg:%s!", token, message) + log_debug("[WSServer][on_socket_recv] client(token:{}) msg:{}!", token, message) socket:send_frame(message) end diff --git a/script/quanta.lua b/script/quanta.lua index 6e8e37ce..736bda87 100644 --- a/script/quanta.lua +++ b/script/quanta.lua @@ -35,7 +35,7 @@ function quanta.check_endless_loop() local debug_hook = function() local now = otime() if now - quanta.now >= 10 then - log_err("check_endless_loop:%s", dtraceback()) + log_err("check_endless_loop:{}", dtraceback()) end end dsethook(debug_hook, "l") @@ -49,7 +49,7 @@ function quanta.get(name) local global_obj = quanta[name] if not global_obj then local info = dgetinfo(2, "S") - log_err("[quanta][get] %s not initial! source(%s:%s)", name, info.short_src, info.linedefined) + log_err("[quanta][get] {} not initial! source({}:{})", name, info.short_src, info.linedefined) return end return global_obj @@ -60,13 +60,13 @@ function quanta.enum(ename, ekey) local eobj = enum(ename) if not eobj then local info = dgetinfo(2, "S") - log_err("[quanta][enum] %s not initial! source(%s:%s)", ename, info.short_src, info.linedefined) + log_err("[quanta][enum] {} not initial! source({}:{})", ename, info.short_src, info.linedefined) return end local eval = eobj[ekey] if not eval then local info = dgetinfo(2, "S") - log_err("[quanta][enum] %s.%s not defined! source(%s:%s)", ename, ekey, info.short_src, info.linedefined) + log_err("[quanta][enum] {}.{} not defined! source({}:{})", ename, ekey, info.short_src, info.linedefined) return end return eval diff --git a/script/queue/mongo_mq.lua b/script/queue/mongo_mq.lua index c168acb3..771cbce4 100644 --- a/script/queue/mongo_mq.lua +++ b/script/queue/mongo_mq.lua @@ -21,9 +21,9 @@ function MongoMQ:setup(coll_name) local query = { coll_name, { { key = { ttl = 1 }, expireAfterSeconds = 0, name = "ttl", unique = false } } } local ok, code = mongo_agent:create_indexes(query) if qsuccess(code, ok) then - log_info("[MongoMQ][setup] rmsg table %s build due index success") + log_info("[MongoMQ][setup] rmsg table {} build due index success") end - log_info("[MongoMQ][setup] init rmsg coll: %s", coll_name) + log_info("[MongoMQ][setup] init rmsg coll: {}", coll_name) end -- 获取消息长度 @@ -49,7 +49,7 @@ end -- 删除消息 function MongoMQ:delete_message(target_id, timestamp) - log_info("[MongoMQ][delete_message] delete message: %s", target_id) + log_info("[MongoMQ][delete_message] delete message: {}", target_id) local selecter = { ["$and"] = { { target_id = target_id }, { time = {["$lte"] = timestamp } }}} return mongo_agent:delete({ self.coll_name, selecter }, target_id) end @@ -63,10 +63,10 @@ function MongoMQ:send_message(target_id, event, args, ttl) end local ok = mongo_agent:insert({ self.coll_name, doc }, target_id) if not ok then - log_err("[MongoMQ][send_message] send message failed: %s, %s", target_id, args) + log_err("[MongoMQ][send_message] send message failed: {}, {}", target_id, args) return ok end - log_debug("[MongoMQ][send_message] send message succeed: %s, %s", target_id, args) + log_debug("[MongoMQ][send_message] send message succeed: {}, {}", target_id, args) return ok end diff --git a/script/queue/redis_mq.lua b/script/queue/redis_mq.lua index 732759c7..62341d42 100644 --- a/script/queue/redis_mq.lua +++ b/script/queue/redis_mq.lua @@ -22,7 +22,7 @@ end function RedisMQ:setup(coll_name) self.coll_name = coll_name self.prefix = sformat("RELIABLE:%s:%s", NAMESPACE, coll_name) - log_info("[RedisMQ][setup] init rmsg coll: %s", coll_name) + log_info("[RedisMQ][setup] init rmsg coll: {}", coll_name) end -- 获取消息长度 @@ -47,7 +47,7 @@ end -- 删除消息 function RedisMQ:delete_message(target_id, timestamp) - log_info("[RedisMQ][delete_message] delete message: %s-%s", target_id, timestamp) + log_info("[RedisMQ][delete_message] delete message: {}-{}", target_id, timestamp) local zset_name = sformat("%s:%s", self.prefix, target_id) return redis_agent:execute({ "ZREMRANGEBYSCORE", zset_name, 0, timestamp }, target_id) end @@ -62,10 +62,10 @@ function RedisMQ:send_message(target_id, event, args, ttl) if ttl then redis_agent:execute( { "EXPIRE", zset_name, ttl }, target_id) end - log_debug("[RedisMQ][send_message] send message succeed: %s, %s", target_id, doc) + log_debug("[RedisMQ][send_message] send message succeed: {}, {}", target_id, doc) return true end - log_err("[RedisMQ][send_message] send message failed: %s, %s", target_id, doc) + log_err("[RedisMQ][send_message] send message failed: {}, {}", target_id, doc) return false end diff --git a/script/sandbox.lua b/script/sandbox.lua index c7d29975..89faa1d2 100644 --- a/script/sandbox.lua +++ b/script/sandbox.lua @@ -6,23 +6,24 @@ local loadfile = loadfile local iopen = io.open local mabs = math.abs local ogetenv = os.getenv -local log_info = log.info -local log_err = log.error +local lprint = log.print local sformat = string.format local traceback = debug.traceback local file_time = stdfs.last_write_time +local LOG_LEVEL = log.LOG_LEVEL + local FEATURE = "devops" local TITLE = quanta.title local load_status = "success" local log_error = function(content) load_status = "failed" - log_err(content, TITLE, FEATURE) + lprint(LOG_LEVEL.ERROR, 0, TITLE, FEATURE, content) end local log_output = function(content) - log_info(content, TITLE) + lprint(LOG_LEVEL.INFO, 0, TITLE, FEATURE, content) end local function ssplit(str, token) @@ -112,9 +113,9 @@ function quanta.report(type) local divider = "----------------------------------------------------------------------------------------" local fmt = '{"type":"%s","pid":"%s","state":"%s","time":%s,"service":"%s"}' local str = sformat(fmt, type, quanta.pid, load_status, os.time(), quanta.name) - log_info(divider, TITLE, FEATURE) - log_info(str, TITLE, FEATURE) - log_info(divider, TITLE, FEATURE) + log_output(divider) + log_output(str) + log_output(divider) end function quanta.reload() diff --git a/script/store/clickhouse_mgr.lua b/script/store/clickhouse_mgr.lua index b88284f2..01c3002e 100644 --- a/script/store/clickhouse_mgr.lua +++ b/script/store/clickhouse_mgr.lua @@ -16,8 +16,6 @@ function ClickHouseMgr:__init() self:setup() -- 注册事件 event_mgr:add_listener(self, "rpc_clickhouse_query", "query") - event_mgr:add_listener(self, "rpc_clickhouse_prepare", "prepare") - event_mgr:add_listener(self, "rpc_clickhouse_execute", "execute") end --初始化 @@ -40,31 +38,7 @@ function ClickHouseMgr:query(db_id, primary_id, sql) if clickhouse_db and clickhouse_db:set_executer(primary_id) then local ok, res_oe = clickhouse_db:query(sql) if not ok then - log_err("[ClickHouseMgr][query] query %s failed, because: %s", sql, res_oe) - end - return ok and SUCCESS or MYSQL_FAILED, res_oe - end - return MYSQL_FAILED, "clickhouse db not exist" -end - -function ClickHouseMgr:execute(db_id, primary_id, stmt, ...) - local clickhouse_db = self:get_db(db_id) - if clickhouse_db and clickhouse_db:set_executer(primary_id) then - local ok, res_oe = clickhouse_db:execute(stmt, ...) - if not ok then - log_err("[ClickHouseMgr][execute] execute %s failed, because: %s", stmt, res_oe) - end - return ok and SUCCESS or MYSQL_FAILED, res_oe - end - return MYSQL_FAILED, "clickhouse db not exist" -end - -function ClickHouseMgr:prepare(db_id, sql) - local clickhouse_db = self:get_db(db_id) - if clickhouse_db and clickhouse_db:set_executer() then - local ok, res_oe = clickhouse_db:prepare(sql) - if not ok then - log_err("[ClickHouseMgr][prepare] prepare %s failed, because: %s", sql, res_oe) + log_err("[ClickHouseMgr][query] query {} failed, because: {}", sql, res_oe) end return ok and SUCCESS or MYSQL_FAILED, res_oe end diff --git a/script/store/game_dao.lua b/script/store/game_dao.lua index d6b9ee77..4b239cb6 100644 --- a/script/store/game_dao.lua +++ b/script/store/game_dao.lua @@ -62,7 +62,7 @@ function GameDAO:load_impl(primary_id, sheet_name) if USE_CACHE then local code, adata = cache_agent:load(primary_id, sheet_name) if qfailed(code) then - log_err("[GameDAO][load_%s] primary_id: %s find failed! code: %s, res: %s", sheet_name, primary_id, code, adata) + log_err("[GameDAO][load_{}] primary_id: {} find failed! code: {}, res: {}", sheet_name, primary_id, code, adata) return false end return true, adata @@ -77,7 +77,7 @@ function GameDAO:load_mongo(sheet_name, primary_id) end local ok, code, adata = mongo_agent:find_one({ sheet_name, { [primary_key] = primary_id }, { _id = 0 } }) if qfailed(code, ok) then - log_err("[GameDAO][load_mongo_%s] primary_id: %s find failed! code: %s, res: %s", sheet_name, primary_id, code, adata) + log_err("[GameDAO][load_mongo_{}] primary_id: {} find failed! code: {}, res: {}", sheet_name, primary_id, code, adata) return false end return true, adata or {} @@ -118,7 +118,7 @@ function GameDAO:update_field(primary_id, sheet_name, field, field_data) if USE_CACHE then local code, adata = cache_agent:update_field(primary_id, sheet_name, field, field_data) if qfailed(code) then - log_err("[GameDAO][update_field_%s] primary_id: %s find failed! code: %s, res: %s", sheet_name, primary_id, code, adata) + log_err("[GameDAO][update_field_{}] primary_id: {} find failed! code: {}, res: {}", sheet_name, primary_id, code, adata) return false end return true, SUCCESS @@ -139,7 +139,7 @@ function GameDAO:update_mongo_field(sheet_name, primary_id, field, field_data) end local ok, code, res = mongo_agent:update({ sheet_name, udata, { [primary_key] = primary_id }, true }) if qfailed(code, ok) then - log_err("[GameDAO][update_mongo_field_%s] update (%s) failed! primary_id(%s), code(%s), res(%s)", sheet_name, field, primary_id, code, res) + log_err("[GameDAO][update_mongo_field_{}] update ({}) failed! primary_id({}), code({}), res({})", sheet_name, field, primary_id, code, res) return false end return true, SUCCESS @@ -149,7 +149,7 @@ function GameDAO:remove_field(primary_id, sheet_name, field) if USE_CACHE then local code, res = cache_agent:remove_field(primary_id, sheet_name, field) if qfailed(code) then - log_err("[GameDAO][remove_field_%s] remove (%s) failed primary_id(%s), code: %s, res: %s!", sheet_name, field, primary_id, code, res) + log_err("[GameDAO][remove_field_{}] remove ({}) failed primary_id({}), code: {}, res: {}!", sheet_name, field, primary_id, code, res) return false end return true, SUCCESS @@ -165,7 +165,7 @@ function GameDAO:remove_mongo_field(sheet_name, primary_id, field) local udata = { ["$unset"] = { [field] = 1 } } local ok, code, res = mongo_agent:update({ sheet_name, udata, { [primary_key] = primary_id }, true }) if qfailed(code, ok) then - log_err("[GameDAO][remove_field_%s] remove (%s) failed primary_id(%s), code: %s, res: %s!", sheet_name, field, primary_id, code, res) + log_err("[GameDAO][remove_field_{}] remove ({}) failed primary_id({}), code: {}, res: {}!", sheet_name, field, primary_id, code, res) return false end return true, SUCCESS @@ -176,7 +176,7 @@ function GameDAO:delete(primary_id, sheet_name) if USE_CACHE then local code, res = cache_agent:delete(primary_id, sheet_name) if qfailed(code) then - log_err("[GameDAO][delete] delete (%s) failed primary_id(%s), code: %s, res: %s!", sheet_name, primary_id, code, res) + log_err("[GameDAO][delete] delete ({}) failed primary_id({}), code: {}, res: {}!", sheet_name, primary_id, code, res) return false end return true, SUCCESS @@ -192,21 +192,21 @@ function GameDAO:delete_mongo(sheet_name, primary_id) end local ok, code, res = mongo_agent:delete({ sheet_name, { [primary_key] = primary_id }, true }) if qfailed(code, ok) then - log_err("[GameDAO][delete_mongo_%s] delete failed primary_id(%s), code: %s, res: %s!", sheet_name, primary_id, code, res) + log_err("[GameDAO][delete_mongo_{}] delete failed primary_id({}), code: {}, res: {}!", sheet_name, primary_id, code, res) return false end return true, SUCCESS end function GameDAO:on_db_prop_update(primary_id, sheet_name, db_key, value) - log_debug("[GameDAO][on_db_prop_update] %s db_key: %s.%s", primary_id, sheet_name, db_key) + log_debug("[GameDAO][on_db_prop_update] {} db_key: {}.{}", primary_id, sheet_name, db_key) self.recv_channel:push(function() return self:update_field(primary_id, sheet_name, db_key, value) end) end function GameDAO:on_db_prop_remove(primary_id, sheet_name, db_key) - log_debug("[GameDAO][on_db_prop_remove] %s db_key: %s.%s", primary_id, sheet_name, db_key) + log_debug("[GameDAO][on_db_prop_remove] {} db_key: {}.{}", primary_id, sheet_name, db_key) self.recv_channel:push(function() return self:remove_field(primary_id, sheet_name, db_key) end) @@ -228,7 +228,7 @@ end function GameDAO:execute(primary_id, cmd, ...) local ok, code, result = redis_agent:execute({ cmd, ... }, primary_id) if qfailed(code, ok) then - log_err("[GameDAO][execute] execute (%s) failed: code: %s, res: %s!", cmd, code, result) + log_err("[GameDAO][execute] execute ({}) failed: code: {}, res: {}!", cmd, code, result) return code end return code, result diff --git a/script/store/mongo_mgr.lua b/script/store/mongo_mgr.lua index bee0a542..11c1beb3 100644 --- a/script/store/mongo_mgr.lua +++ b/script/store/mongo_mgr.lua @@ -46,7 +46,7 @@ function MongoMgr:get_db(db_id) end function MongoMgr:find(db_id, primary_id, coll_name, selector, fields, sortor, limit) - log_debug("[MongoMgr][find]: %s, selector:%s", coll_name, selector) + log_debug("[MongoMgr][find]: {}, selector:{}", coll_name, selector) local mongodb = self:get_db(db_id) if mongodb and mongodb:set_executer(primary_id) then mongodb:set_executer(primary_id) @@ -57,7 +57,7 @@ function MongoMgr:find(db_id, primary_id, coll_name, selector, fields, sortor, l end function MongoMgr:find_one(db_id, primary_id, coll_name, selector, fields) - log_debug("[MongoMgr][find_one]: %s, selector:%s", coll_name, selector) + log_debug("[MongoMgr][find_one]: {}, selector:{}", coll_name, selector) local mongodb = self:get_db(db_id) if mongodb and mongodb:set_executer(primary_id) then local ok, res_oe = mongodb:find_one(coll_name, selector, fields or {_id = 0}) @@ -67,7 +67,7 @@ function MongoMgr:find_one(db_id, primary_id, coll_name, selector, fields) end function MongoMgr:insert(db_id, primary_id, coll_name, obj) - log_debug("[MongoMgr][insert]: %s, obj:%s", coll_name, obj) + log_debug("[MongoMgr][insert]: {}, obj:{}", coll_name, obj) local mongodb = self:get_db(db_id) if mongodb and mongodb:set_executer(primary_id) then local ok, res_oe = mongodb:insert(coll_name, obj) @@ -77,7 +77,7 @@ function MongoMgr:insert(db_id, primary_id, coll_name, obj) end function MongoMgr:update(db_id, primary_id, coll_name, obj, selector, upsert, multi) - log_debug("[MongoMgr][update]: %s, obj:%s, selector:%s", coll_name, obj, selector) + log_debug("[MongoMgr][update]: {}, obj:{}, selector:{}", coll_name, obj, selector) local mongodb = self:get_db(db_id) if mongodb and mongodb:set_executer(primary_id) then local ok, res_oe = mongodb:update(coll_name, obj, selector, upsert, multi) @@ -87,7 +87,7 @@ function MongoMgr:update(db_id, primary_id, coll_name, obj, selector, upsert, mu end function MongoMgr:delete(db_id, primary_id, coll_name, selector, onlyone) - log_debug("[MongoMgr][delete]: %s, selector:%s", coll_name, selector) + log_debug("[MongoMgr][delete]: {}, selector:{}", coll_name, selector) local mongodb = self:get_db(db_id) if mongodb and mongodb:set_executer(primary_id) then local ok, res_oe = mongodb:delete(coll_name, selector, onlyone) diff --git a/script/store/mysql_mgr.lua b/script/store/mysql_mgr.lua index c05100ad..31a8e472 100644 --- a/script/store/mysql_mgr.lua +++ b/script/store/mysql_mgr.lua @@ -40,7 +40,7 @@ function MysqlMgr:query(db_id, primary_id, sql) if mysqldb and mysqldb:set_executer(primary_id) then local ok, res_oe = mysqldb:query(sql) if not ok then - log_err("[MysqlMgr][query] query %s failed, because: %s", sql, res_oe) + log_err("[MysqlMgr][query] query {} failed, because: {}", sql, res_oe) end return ok and SUCCESS or MYSQL_FAILED, res_oe end @@ -52,7 +52,7 @@ function MysqlMgr:execute(db_id, primary_id, stmt, ...) if mysqldb and mysqldb:set_executer(primary_id) then local ok, res_oe = mysqldb:execute(stmt, ...) if not ok then - log_err("[MysqlMgr][execute] execute %s failed, because: %s", stmt, res_oe) + log_err("[MysqlMgr][execute] execute {} failed, because: {}", stmt, res_oe) end return ok and SUCCESS or MYSQL_FAILED, res_oe end @@ -64,7 +64,7 @@ function MysqlMgr:prepare(db_id, sql) if mysqldb and mysqldb:set_executer() then local ok, res_oe = mysqldb:prepare(sql) if not ok then - log_err("[MysqlMgr][prepare] prepare %s failed, because: %s", sql, res_oe) + log_err("[MysqlMgr][prepare] prepare {} failed, because: {}", sql, res_oe) end return ok and SUCCESS or MYSQL_FAILED, res_oe end diff --git a/script/store/redis_mgr.lua b/script/store/redis_mgr.lua index 381a4fbd..675e2d66 100644 --- a/script/store/redis_mgr.lua +++ b/script/store/redis_mgr.lua @@ -41,10 +41,10 @@ function RedisMgr:execute(db_id, cmd, ...) if redisdb then local res = tpack(redisdb:execute(cmd, ...)) if not res[1] then - log_err("[RedisMgr][execute] execute %s (%s) failed, because: %s", cmd, {...}, res[2]) + log_err("[RedisMgr][execute] execute {} ({}) failed, because: {}", cmd, {...}, res[2]) return res[1] and SUCCESS or REDIS_FAILED, res[2] end - log_debug("[RedisMgr][execute]: cmd %s, args: %s", cmd, {...}) + log_debug("[RedisMgr][execute]: cmd {}, args: {}", cmd, {...}) return SUCCESS, tunpack(res, 2) end return REDIS_FAILED, "redis db not exist" diff --git a/server/business/admin/shield.lua b/server/business/admin/shield.lua index be956568..11a85ae6 100644 --- a/server/business/admin/shield.lua +++ b/server/business/admin/shield.lua @@ -37,7 +37,7 @@ function Shield:rpc_add_proto_shield(start_cmd_id, count) for cmd_id = start_cmd_id, end_cmd_id do self.filters[cmd_id] = true end - log_info("[Shield][rpc_add_shield] start_cmd_id=%s count=%s", start_cmd_id, count) + log_info("[Shield][rpc_add_shield] start_cmd_id={} count={}", start_cmd_id, count) end -- 删除协议过滤 @@ -46,12 +46,12 @@ function Shield:rpc_del_proto_shield(start_cmd_id, count) for cmd_id = start_cmd_id, end_cmd_id do self.filters[cmd_id] = nil end - log_info("[Shield][rpc_del_shield] start_cmd_id=%s count=%s", start_cmd_id, count) + log_info("[Shield][rpc_del_shield] start_cmd_id={} count={}", start_cmd_id, count) end -- 清理过滤协议 function Shield:rpc_shield_service_proto(service_type, status) - log_info("[Shield][rpc_shield_service_proto] service_type=%s status=%s", service_type, status) + log_info("[Shield][rpc_shield_service_proto] service_type={} status={}", service_type, status) self.services[service_type] = status end diff --git a/server/business/attr/attribute_agent.lua b/server/business/attr/attribute_agent.lua index 3b4e0892..6e4e987c 100644 --- a/server/business/attr/attribute_agent.lua +++ b/server/business/attr/attribute_agent.lua @@ -33,7 +33,7 @@ function AttributeAgent:on_attr_writeback(player, player_id) local write_attrs = player:get_write_attrs() local ok, code = player:call_lobby("rpc_attr_writeback", write_attrs, quanta.service) if qfailed(code, ok) then - log_err("[AttributeAgent][on_attr_writeback] writeback failed attrs=%s, player=%s, code=%s", write_attrs, player_id, code) + log_err("[AttributeAgent][on_attr_writeback] writeback failed attrs={}, player={}, code={}", write_attrs, player_id, code) end player:set_write_attrs({}) end @@ -44,13 +44,13 @@ end function AttributeAgent:rpc_attr_relay(player_id, attrs, service_id) local player = player_mgr:get_entity(player_id) if not player then - log_err("[AttributeAgent][rpc_attr_relay] player not exist attrs=%s, player_id=%s", attrs, player_id) + log_err("[AttributeAgent][rpc_attr_relay] player not exist attrs={}, player_id={}", attrs, player_id) return ROLE_NOT_EXIST end for attr_id, value in pairs(attrs) do player:set_attr(attr_id, value, service_id) end - log_debug("[AttributeAgent][rpc_attr_relay] success player_id=%s, attrs=%s", player_id, attrs) + log_debug("[AttributeAgent][rpc_attr_relay] success player_id={}, attrs={}", player_id, attrs) return FRAME_SUCCESS end diff --git a/server/business/attr/attribute_relay.lua b/server/business/attr/attribute_relay.lua index 5c1c1b95..46e31d9c 100644 --- a/server/business/attr/attribute_relay.lua +++ b/server/business/attr/attribute_relay.lua @@ -69,13 +69,13 @@ end function AttributeRelay:rpc_attr_writeback(player_id, attrs, service_id) local player = player_mgr:get_entity(player_id) if not player then - log_err("[AttributeRelay][rpc_attr_writeback] player not exist attrs=%s, player_id=%s", attrs, player_id) + log_err("[AttributeRelay][rpc_attr_writeback] player not exist attrs={}, player_id={}", attrs, player_id) return ROLE_NOT_EXIST end for attr_id, value in pairs(attrs) do player:set_attr(attr_id, value, service_id) end - log_debug("[AttributeRelay][rpc_attr_writeback] success! attrs=%s, player_id=%s", attrs, player_id) + log_debug("[AttributeRelay][rpc_attr_writeback] success! attrs={}, player_id={}", attrs, player_id) return FRAME_SUCCESS end @@ -97,7 +97,7 @@ function AttributeRelay:on_attr_relay(player, player_id) if next(attrs) then local ok, code = player:call_service(service_name, "rpc_attr_relay", attrs, quanta.service) if qfailed(code, ok) then - log_err("[AttributeRelay][on_attr_relay] sync failed attrs=%s, player_id=%s, code=%s", attrs, player_id, code) + log_err("[AttributeRelay][on_attr_relay] sync failed attrs={}, player_id={}, code={}", attrs, player_id, code) end end end diff --git a/server/business/component/attr_component.lua b/server/business/component/attr_component.lua index 20b5d96d..9e3dfaa3 100644 --- a/server/business/component/attr_component.lua +++ b/server/business/component/attr_component.lua @@ -61,7 +61,7 @@ end --加载db数据 function AttrComponent:on_db_player_attr_load(data) - log_debug("[AttrComponent][on_db_player_attr_load] data(%s)", data) + log_debug("[AttrComponent][on_db_player_attr_load] data({})", data) if data.player_id then self:load_attrs(data.attrs or {}) return true @@ -75,11 +75,11 @@ end function AttrComponent:set_attr(attr_id, value, service_id) local attr = self.attr_set[attr_id] if not attr then - log_warn("[AttrComponent][set_attr] attr(%s) not define", attr_id) + log_warn("[AttrComponent][set_attr] attr({}) not define", attr_id) return false end if not value then - log_warn("[AttrComponent][set_attr] attr(%s) value is nil", attr_id) + log_warn("[AttrComponent][set_attr] attr({}) value is nil", attr_id) return false end local cur_val = self.attrs[attr_id] @@ -176,7 +176,7 @@ function AttrComponent:load_attrs(attrs) for attr_id, value in pairs(attrs) do local attr = self.attr_set[attr_id] if not attr then - log_warn("[AttrComponent][load_attrs] attr(%s) not define", attr_id) + log_warn("[AttrComponent][load_attrs] attr({}) not define", attr_id) end self:set_attrs_field(attr_id, value) end diff --git a/server/business/component/event_component.lua b/server/business/component/event_component.lua index 9d96930d..d74b2a7a 100644 --- a/server/business/component/event_component.lua +++ b/server/business/component/event_component.lua @@ -18,7 +18,7 @@ function EventComponent:watch_event(watcher, event, handler) local func_name = handler or event local callback_func = watcher[func_name] if not callback_func or type(callback_func) ~= "function" then - log_warn("[EventComponent][watch_event] event(%s) handler not define!", event) + log_warn("[EventComponent][watch_event] event({}) handler not define!", event) return end local watcher_map = self.events[event] @@ -44,7 +44,7 @@ function EventComponent:notify_event(event, ...) local callback_func = watcher[func_name] local ok, ret = xpcall(callback_func, dtraceback, watcher, ...) if not ok then - log_fatal("[EventComponent][notify_event] xpcall [%s:%s] failed: %s!", watcher:source(), func_name, ret) + log_fatal("[EventComponent][notify_event] xpcall [{}:{}] failed: {}!", watcher:source(), func_name, ret) end end end diff --git a/server/business/component/sub_component.lua b/server/business/component/sub_component.lua index 47c8219b..51cfbe30 100644 --- a/server/business/component/sub_component.lua +++ b/server/business/component/sub_component.lua @@ -21,7 +21,7 @@ function SubComponent:register_subhandler(trigger, event, handler) local func_name = handler or event local callback_func = trigger[func_name] if not callback_func or type(callback_func) ~= "function" then - log_warn("[SubComponent][register_subhandler] event(%s) handler is nil!", event) + log_warn("[SubComponent][register_subhandler] event({}) handler is nil!", event) return end self.subhandlers[event] = { trigger, func_name } @@ -67,7 +67,7 @@ function SubComponent:pub_event(serv_name, event, ...) end local hand_info = self.subhandlers[event] if not hand_info then - log_warn("[SubComponent][pub_event] event(%s) subhandlers is nil!", event) + log_warn("[SubComponent][pub_event] event({}) subhandlers is nil!", event) return end local taigger, func_name = tunpack(hand_info) diff --git a/server/business/entity/entity.lua b/server/business/entity/entity.lua index fc8163cd..f1f0204e 100644 --- a/server/business/entity/entity.lua +++ b/server/business/entity/entity.lua @@ -36,12 +36,12 @@ end -- 初始化 function Entity:setup(conf) if not self:load(conf) then - log_warn("[Entity][setup] entity %s load faild!", self.id) + log_warn("[Entity][setup] entity {} load faild!", self.id) return false end local setup_ok = self:collect("_setup") if not setup_ok then - log_warn("[Entity][setup] entity %s setup faild!", self.id) + log_warn("[Entity][setup] entity {} setup faild!", self.id) return setup_ok end return setup_ok diff --git a/server/business/entity/entity_mgr.lua b/server/business/entity/entity_mgr.lua index d6571f10..51312399 100644 --- a/server/business/entity/entity_mgr.lua +++ b/server/business/entity/entity_mgr.lua @@ -37,13 +37,13 @@ end -- 设置实体 function EntityMgr:add_entity(entity_id, entity) - log_info("[EntityMgr][add_entity] entity_id=%s", entity_id) + log_info("[EntityMgr][add_entity] entity_id={}", entity_id) self.entity_map:set(entity_id, entity) end -- 移除实体 function EntityMgr:remove_entity(entity, entity_id) - log_info("[EntityMgr][remove_entity] entity_id=%s", entity_id) + log_info("[EntityMgr][remove_entity] entity_id={}", entity_id) self:on_destory(entity_id, entity) self.entity_map:set(entity_id, nil) entity:destory() diff --git a/server/cache/cache_gm.lua b/server/cache/cache_gm.lua index cccf053a..a5f162be 100644 --- a/server/cache/cache_gm.lua +++ b/server/cache/cache_gm.lua @@ -119,13 +119,13 @@ end --复制缓存数据 function CacheGM:copy_cache(to_player_id, player_id, coll_name) - log_info("[CacheGM][copy_cache] to_player_id=%s, player_id=%s, coll_name=%s", to_player_id, player_id, coll_name) + log_info("[CacheGM][copy_cache] to_player_id={}, player_id={}, coll_name={}", to_player_id, player_id, coll_name) local coll_cfg = cache_db:find_one(coll_name) if not coll_cfg then - return sformat("%s not found cache", coll_name) + return sformat("{} not found cache", coll_name) end if not coll_cfg.copyable then - return sformat("%s cant copy", coll_name) + return sformat("{} cant copy", coll_name) end local ok = cache_mgr:rpc_cache_copy(to_player_id, player_id, coll_name) @@ -137,7 +137,7 @@ end --删除缓存 function CacheGM:del_cache(player_id, coll_name) - log_info("[CacheGM][del_cache] player_id=%s coll_name=%s", player_id, coll_name) + log_info("[CacheGM][del_cache] player_id={} coll_name={}", player_id, coll_name) -- 通知服务 local ok = cache_mgr:rpc_cache_delete(player_id, coll_name) if not ok then @@ -148,29 +148,29 @@ end --更新缓存 function CacheGM:update_cache(player_id, coll_name, field, field_data) - log_info("[CacheGM][update_cache] player_id:%s coll_name=%s field:%s, field_data:%s", player_id, coll_name, field, field_data) + log_info("[CacheGM][update_cache] player_id:{} coll_name={} field:{}, field_data:{}", player_id, coll_name, field, field_data) local pok, datas = pcall(unserialize, field_data) if not pok or not datas then - return sformat("parse failed. field_data:%s", field_data) + return sformat("parse failed. field_data:{}", field_data) end local ok = cache_mgr:rpc_cache_update_field(player_id, coll_name, field, datas) if not ok then - return sformat("failed code:%s", ok) + return sformat("failed code:{}", ok) end return "success" end --查询缓存 function CacheGM:query_cache(player_id, coll_name) - log_info("[CacheGM][query_cache] player_id=%s coll_name=%s", player_id, coll_name) + log_info("[CacheGM][query_cache] player_id={} coll_name={}", player_id, coll_name) -- 通知服务 local ok, doc = cache_mgr:load_document(coll_name, player_id) if not ok or not doc then return "cache not find" end - log_info("[CacheGM][query_cache] player_id=%s coll_name=%s datas:%s", player_id, coll_name, doc:get_datas()) + log_info("[CacheGM][query_cache] player_id={} coll_name={} datas:{}", player_id, coll_name, doc:get_datas()) return doc:get_datas() end diff --git a/server/cache/cache_mgr.lua b/server/cache/cache_mgr.lua index b19c4673..688b9897 100644 --- a/server/cache/cache_mgr.lua +++ b/server/cache/cache_mgr.lua @@ -76,7 +76,7 @@ end --清理缓存 function CacheMgr:on_cache_load(group_name, primary_id) - log_debug("[CacheMgr][on_cache_load] group_name=%s, primary=%s", group_name, primary_id) + log_debug("[CacheMgr][on_cache_load] group_name={}, primary={}", group_name, primary_id) local groups = self.caches[group_name] if groups then groups:del(primary_id) @@ -178,7 +178,7 @@ function CacheMgr:load_group(coll_name, primary_id) local Group = import("cache/group.lua") local group = Group(group_name) if not group:load(primary_id, gconfs) then - log_err("[CacheMgr][load_group] group load failed! coll_name=%s, primary=%s", group_name, primary_id) + log_err("[CacheMgr][load_group] group load failed! coll_name={}, primary={}", group_name, primary_id) return DB_LOAD_ERR end local groups = self.caches[group_name] @@ -204,10 +204,10 @@ end function CacheMgr:rpc_router_update(primary_id, router_id, serv_name, serv_id) local group_name = self.collections[ROUTER_COL] local _ = thread_mgr:lock(sformat("%s.%s", group_name, primary_id), true) - log_debug("[CacheMgr][rpc_router_update] router_id=%s, primary=%s, service: %s-%s", router_id, primary_id, serv_name, serv_id) + log_debug("[CacheMgr][rpc_router_update] router_id={}, primary={}, service: {}-{}", router_id, primary_id, serv_name, serv_id) local ccode, doc = self:load_document(ROUTER_COL, primary_id) if qfailed(ccode) then - log_err("[CacheMgr][rpc_router_update] load_document failed! primary=%s", primary_id) + log_err("[CacheMgr][rpc_router_update] load_document failed! primary={}", primary_id) return ccode end if serv_name and serv_id then @@ -240,10 +240,10 @@ function CacheMgr:rpc_cache_load(primary_id, coll_name) local _ = thread_mgr:lock(sformat("%s.%s", group_name, primary_id), true) local code, doc = self:load_document(coll_name, primary_id) if qfailed(code) then - log_err("[CacheMgr][rpc_cache_load] load_document failed! coll_name=%s, primary=%s", coll_name, primary_id) + log_err("[CacheMgr][rpc_cache_load] load_document failed! coll_name={}, primary={}", coll_name, primary_id) return code end - log_debug("[CacheMgr][rpc_cache_load] coll_name=%s, primary=%s", coll_name, primary_id) + log_debug("[CacheMgr][rpc_cache_load] coll_name={}, primary={}", coll_name, primary_id) return code, doc:get_datas() end @@ -252,10 +252,10 @@ function CacheMgr:rpc_cache_update_field(primary_id, coll_name, field, field_dat local _ = thread_mgr:lock(primary_id, true) local ccode, doc = self:load_document(coll_name, primary_id) if qfailed(ccode) then - log_err("[CacheMgr][rpc_cache_update_field] load_document failed! coll_name=%s, primary=%s, field=%s", coll_name, primary_id, field) + log_err("[CacheMgr][rpc_cache_update_field] load_document failed! coll_name={}, primary={}, field={}", coll_name, primary_id, field) return ccode end - log_debug("[CacheMgr][rpc_cache_update_field] coll_name=%s, primary=%s, field=%s, data:%s", coll_name, primary_id, field, field_data) + log_debug("[CacheMgr][rpc_cache_update_field] coll_name={}, primary={}, field={}, data:{}", coll_name, primary_id, field, field_data) doc:update_field(field, field_data) return SUCCESS end @@ -266,11 +266,11 @@ function CacheMgr:rpc_cache_remove_field(primary_id, coll_name, field) local _ = thread_mgr:lock(sformat("%s.%s", group_name, primary_id), true) local ccode, doc = self:load_document(coll_name, primary_id) if qfailed(ccode) then - log_err("[CacheMgr][rpc_cache_remove_field] load_document failed! coll_name=%s, primary=%s, field=%s", coll_name, primary_id, field) + log_err("[CacheMgr][rpc_cache_remove_field] load_document failed! coll_name={}, primary={}, field={}", coll_name, primary_id, field) return ccode end doc:remove_field(field) - log_debug("[CacheMgr][rpc_cache_remove_field] coll_name=%s, primary=%s, field=%s", coll_name, primary_id, field) + log_debug("[CacheMgr][rpc_cache_remove_field] coll_name={}, primary={}, field={}", coll_name, primary_id, field) return SUCCESS end @@ -280,27 +280,27 @@ function CacheMgr:rpc_cache_delete(primary_id, coll_name) local _ = thread_mgr:lock(sformat("%s.%s", group_name, primary_id), true) local ccode, doc = self:load_document(coll_name, primary_id) if qfailed(ccode) then - log_err("[CacheMgr][rpc_cache_delete] load_document failed! coll_name=%s, primary=%s", coll_name, primary_id) + log_err("[CacheMgr][rpc_cache_delete] load_document failed! coll_name={}, primary={}", coll_name, primary_id) return ccode end local ok, code = doc:destory() if qfailed(code, ok) then self.del_documents[doc] = true - log_err("[CacheMgr][rpc_cache_delete] delete failed! coll_name=%s, primary=%s", coll_name, primary_id) + log_err("[CacheMgr][rpc_cache_delete] delete failed! coll_name={}, primary={}", coll_name, primary_id) return DELETE_FAILD end - log_debug("[CacheMgr][rpc_cache_delete] coll_name=%s, primary=%s", coll_name, primary_id) + log_debug("[CacheMgr][rpc_cache_delete] coll_name={}, primary={}", coll_name, primary_id) return SUCCESS end --复制缓存 function CacheMgr:rpc_cache_copy(to_id, src_id, coll_name) - log_debug("[CacheMgr][rpc_cache_copy] coll_name=%s, src_id=%s, to_id=%s", coll_name, src_id, to_id) + log_debug("[CacheMgr][rpc_cache_copy] coll_name={}, src_id={}, to_id={}", coll_name, src_id, to_id) local group_name = self.collections[coll_name] local _ = thread_mgr:lock(sformat("%s.%s", group_name, to_id), true) local src_code, src_doc, from_mem = self:load_document(coll_name, src_id) if qfailed(src_code) then - log_err("[CacheMgr][rpc_cache_copy] load_document failed! coll_name=%s, src_id=%s", coll_name, src_id) + log_err("[CacheMgr][rpc_cache_copy] load_document failed! coll_name={}, src_id={}", coll_name, src_id) return src_code end --原表是否为空 @@ -312,7 +312,7 @@ function CacheMgr:rpc_cache_copy(to_id, src_id, coll_name) end local to_code, doc = self:load_document(coll_name, to_id) if qfailed(to_code) then - log_err("[CacheMgr][rpc_cache_copy] load_document failed! coll_name=%s, to_id=%s", coll_name, to_id) + log_err("[CacheMgr][rpc_cache_copy] load_document failed! coll_name={}, to_id={}", coll_name, to_id) if not from_mem then self:clear_document(coll_name, src_id) end @@ -333,10 +333,10 @@ function CacheMgr:rpc_cache_signed(primary_id, coll_name) local _ = thread_mgr:lock(sformat("%s.%s", group_name, primary_id), true) local ccode, doc = self:load_document(coll_name, primary_id) if qfailed(ccode) then - log_err("[CacheMgr][rpc_cache_signed] load_document failed! coll_name=%s, primary=%s, field=%s", coll_name, primary_id, field) + log_err("[CacheMgr][rpc_cache_signed] load_document failed! coll_name={}, primary={}, field={}", coll_name, primary_id, field) return ccode end - log_debug("[CacheMgr][rpc_cache_signed] coll_name=%s, primary=%s, field=%s, data:%s", coll_name, primary_id, field, field_data) + log_debug("[CacheMgr][rpc_cache_signed] coll_name={}, primary={}, field={}, data:{}", coll_name, primary_id, field, field_data) doc:update_field(field, field_data) --强制落库 doc:update() diff --git a/server/cache/document.lua b/server/cache/document.lua index 44ef48ca..a73c2b53 100644 --- a/server/cache/document.lua +++ b/server/cache/document.lua @@ -56,7 +56,7 @@ function Document:load() local query = { [self.primary_key] = pid } local code, res = mongo_mgr:find_one(MAIN_DBID, pid, self.coll_name, query, { _id = 0 }) if qfailed(code) then - log_err("[Document][load] failed: %s=> table: %s", res, self.coll_name) + log_err("[Document][load] failed: {}=> table: {}", res, self.coll_name) return code end self.datas = res or {} @@ -67,7 +67,7 @@ end function Document:merge() local code, res = redis_mgr:execute(MAIN_DBID, "HGETALL", self.hotkey) if qfailed(code) then - log_err("[Document][merge] failed: %s=> table: %s", res, self.coll_name) + log_err("[Document][merge] failed: {}=> table: {}", res, self.coll_name) return code end if next(res) then @@ -94,12 +94,12 @@ function Document:destory() local query = { [self.primary_key] = self.primary_id } local code, res = mongo_mgr:delete(MAIN_DBID, self.primary_id, self.coll_name, query, true) if qfailed(code) then - log_err("[Document][destory] del failed: %s=> table: %s", res, self.coll_name) + log_err("[Document][destory] del failed: {}=> table: {}", res, self.coll_name) return false, code end local rcode, rres = redis_mgr:execute(MAIN_DBID, "DEL", self.hotkey) if qfailed(rcode) then - log_err("[Document][destory] del failed: %s=> hotkey: %s", rres, self.hotkey) + log_err("[Document][destory] del failed: {}=> hotkey: {}", rres, self.hotkey) return false, code end return true, SUCCESS @@ -120,7 +120,7 @@ function Document:update() channel:push(function() local rcode, rres = redis_mgr:execute(MAIN_DBID, "DEL", self.hotkey) if qfailed(rcode) then - log_err("[Document][update] del failed: %s=> hotkey: %s", rres, self.hotkey) + log_err("[Document][update] del failed: {}=> hotkey: {}", rres, self.hotkey) return false, rcode end self.flushing = false @@ -130,7 +130,7 @@ function Document:update() local selector = { [self.primary_key] = self.primary_id } local code, res = mongo_mgr:update(MAIN_DBID, self.primary_id, self.coll_name, self.datas, selector, true) if qfailed(code) then - log_err("[Document][update] update failed: %s=> table: %s", res, self.coll_name) + log_err("[Document][update] update failed: {}=> table: {}", res, self.coll_name) return false, code end return true, SUCCESS @@ -240,7 +240,7 @@ end function Document:cmomit_redis(field, value) local code, res = redis_mgr:execute(MAIN_DBID, "HSET", self.hotkey, field, { val = value }) if qfailed(code) then - log_err("[Document][cmomit_redis] failed: %s=> hotkey: %s", res, self.hotkey) + log_err("[Document][cmomit_redis] failed: {}=> hotkey: {}", res, self.hotkey) self:flush() return end diff --git a/server/cache/group.lua b/server/cache/group.lua index 06f30757..1caf0674 100644 --- a/server/cache/group.lua +++ b/server/cache/group.lua @@ -27,7 +27,7 @@ function Group:load(primary_id, gconfs) local doc = Document(conf, primary_id) local code = doc:load() if qfailed(code) then - log_err("[Group][load] load doc failed: tab_name=%s", sheet) + log_err("[Group][load] load doc failed: tab_name={}", sheet) return false, code end self.documents[sheet] = doc diff --git a/server/center/center_gm.lua b/server/center/center_gm.lua index abe00767..4e7b0876 100644 --- a/server/center/center_gm.lua +++ b/server/center/center_gm.lua @@ -74,21 +74,21 @@ end -- 添加协议屏蔽(多个) function CenterGM:add_proto_shield(start_cmd_id, count) - log_info("[CenterGM][add_proto_shield] start_cmd_id=%s count=%s", start_cmd_id, count) + log_info("[CenterGM][add_proto_shield] start_cmd_id={} count={}", start_cmd_id, count) -- 通知服务 self:call_command_service(start_cmd_id, "rpc_add_proto_shield", start_cmd_id, count) end -- 删除协议屏蔽(多个) function CenterGM:del_proto_shield(start_cmd_id, count) - log_info("[CenterGM][del_proto_shield] start_cmd_id=%s count=%s", start_cmd_id, count) + log_info("[CenterGM][del_proto_shield] start_cmd_id={} count={}", start_cmd_id, count) -- 通知服务 self:call_command_service(start_cmd_id, "rpc_del_proto_shield", start_cmd_id, count) end -- 屏蔽服务协议 function CenterGM:shield_service_proto(service_type, status) - log_info("[CenterGM][shield_service_proto] service_type: %s, status:%s", service_type, status) + log_info("[CenterGM][shield_service_proto] service_type: {}, status:{}", service_type, status) -- 通知服务 if service_type ~= 0 then router_mgr:call_gateway_all("rpc_shield_service_proto", service_type, status) @@ -100,7 +100,7 @@ end -- 设置日志等级 function CenterGM:set_logger_level(service_id, level) - log_info("[CenterGM][set_logger_level] service_id: %s, level:%s", service_id, level) + log_info("[CenterGM][set_logger_level] service_id: {}, level:{}", service_id, level) -- 通知服务 router_mgr:broadcast(service_id, "rpc_set_logger_level", level) end diff --git a/server/center/gm_mgr.lua b/server/center/gm_mgr.lua index 6fb85734..615af598 100644 --- a/server/center/gm_mgr.lua +++ b/server/center/gm_mgr.lua @@ -240,7 +240,7 @@ end function GM_Mgr:exec_global_cmd(service_id, cmd_name, ...) local ok, codeoe, res = router_mgr:call_master(service_id, "rpc_command_execute" , cmd_name, ...) if not ok then - log_err("[GM_Mgr][exec_global_cmd] rpc_command_execute failed! service_id:%s, cmd_name=%s", service_id, cmd_name) + log_err("[GM_Mgr][exec_global_cmd] rpc_command_execute failed! service_id:{}, cmd_name={}", service_id, cmd_name) return { code = 1, msg = codeoe } end return { code = codeoe, msg = res } @@ -252,7 +252,7 @@ function GM_Mgr:exec_system_cmd(service_id, cmd_name, target_id, ...) local quanta_id = make_sid(service_id, index) local ok, codeoe, res = router_mgr:call_target(quanta_id, "rpc_command_execute" , cmd_name, target_id, ...) if not ok then - log_err("[GM_Mgr][exec_system_cmd] rpc_command_execute failed! cmd_name=%s", cmd_name) + log_err("[GM_Mgr][exec_system_cmd] rpc_command_execute failed! cmd_name={}", cmd_name) return { code = 1, msg = codeoe } end return { code = codeoe, msg = res } @@ -262,7 +262,7 @@ end function GM_Mgr:exec_service_cmd(service_id, cmd_name, ...) local ok, codeoe = router_mgr:broadcast(service_id, "rpc_command_execute" , cmd_name, ...) if not ok then - log_err("[GM_Mgr][exec_service_cmd] rpc_command_execute failed! cmd_name=%s", cmd_name) + log_err("[GM_Mgr][exec_service_cmd] rpc_command_execute failed! cmd_name={}", cmd_name) return { code = 1, msg = codeoe } end return { code = codeoe, msg = "success" } @@ -272,7 +272,7 @@ end function GM_Mgr:exec_hash_cmd(service_id, cmd_name, target_id, ...) local ok, codeoe, res = router_mgr:call_hash(service_id, target_id, "rpc_command_execute", cmd_name, target_id, ...) if not ok then - log_err("[GM_Mgr][exec_hash_cmd] rpc_command_execute failed! cmd_name=%s", cmd_name) + log_err("[GM_Mgr][exec_hash_cmd] rpc_command_execute failed! cmd_name={}", cmd_name) return { code = 1, msg = codeoe } end return { code = codeoe, msg = res } @@ -286,16 +286,16 @@ end --兼容在线和离线的玩家指令 function GM_Mgr:exec_offline_cmd(service_id, cmd_name, player_id, ...) - log_debug("[GM_Mgr][exec_offline_cmd] cmd_name:%s player_id:%s", cmd_name, player_id) + log_debug("[GM_Mgr][exec_offline_cmd] cmd_name:{} player_id:{}", cmd_name, player_id) local ok, codeoe, res = online:call_lobby(player_id, "rpc_command_execute", cmd_name, player_id, ...) if not ok then - log_err("[GM_Mgr][exec_offline_cmd] rpc_command_execute failed! cmd_name=%s player_id=%s", cmd_name, player_id) + log_err("[GM_Mgr][exec_offline_cmd] rpc_command_execute failed! cmd_name={} player_id={}", cmd_name, player_id) return { code = 1, msg = codeoe } end if codeoe == PLAYER_NOT_EXIST then ok, codeoe, res = router_mgr:call_lobby_hash(player_id, "rpc_command_execute", cmd_name, player_id, ...) if not ok then - log_err("[GM_Mgr][exec_offline_cmd] rpc_command_execute failed! player_id:%s, cmd_name=%s", player_id, cmd_name) + log_err("[GM_Mgr][exec_offline_cmd] rpc_command_execute failed! player_id:{}, cmd_name={}", player_id, cmd_name) return { code = 1, msg = codeoe } end return { code = codeoe, msg = res } @@ -308,14 +308,14 @@ function GM_Mgr:exec_player_cmd(service_id, cmd_name, player_id, ...) if player_id == 0 then local ok, codeoe, res = router_mgr:call_lobby_random("rpc_command_execute", cmd_name, player_id, ...) if not ok then - log_err("[GM_Mgr][exec_player_cmd] rpc_command_execute failed! cmd_name=%s player_id=%s", cmd_name, player_id) + log_err("[GM_Mgr][exec_player_cmd] rpc_command_execute failed! cmd_name={} player_id={}", cmd_name, player_id) return { code = 1, msg = codeoe } end return { code = codeoe, msg = res } end local ok, codeoe, res = online:call_lobby(player_id, "rpc_command_execute", cmd_name, player_id, ...) if not ok then - log_err("[GM_Mgr][exec_player_cmd] rpc_command_execute failed! cmd_name=%s player_id=%s", cmd_name, player_id) + log_err("[GM_Mgr][exec_player_cmd] rpc_command_execute failed! cmd_name={} player_id={}", cmd_name, player_id) return { code = 1, msg = codeoe } end return { code = codeoe, msg = res } diff --git a/server/center/gm_page.lua b/server/center/gm_page.lua index 9ad5e84e..4878b737 100644 --- a/server/center/gm_page.lua +++ b/server/center/gm_page.lua @@ -12,64 +12,64 @@ return [[
@@ -81,11 +81,6 @@ return [[ - - - - -
@@ -118,179 +113,217 @@ return [[ ]] diff --git a/server/center/page/gm.css b/server/center/page/gm.css new file mode 100644 index 00000000..317d206b --- /dev/null +++ b/server/center/page/gm.css @@ -0,0 +1,58 @@ +html,body,div,h1,h2,h3,h4,h5,h6,p,span{ + padding: 0; + margin: 0; +} +body{ + padding-top: 10px; + overflow: auto; +} +.gmDumpContainer { + float: left; + border: 1px solid black; + height: 800px; + width: 30%; + margin-top:30px; + overflow: auto; +} +.gmContainer { + padding: 2px; + border: 1px solid black; + margin-top:30px; + height: 800px; + width: 70%; + overflow: auto; +} +.historyMsg{ + top: 5px; + border: 1px solid black; + height: 660px; + padding: 3px; + overflow: auto; +} +.newMsg{ + text-align: left; + margin-top: 5px; +} +.myMsg{ + background-color: grey; + color: white; + text-align: left; + margin-top: 5px; +} +.control{ + border: 1px solid black; + height: 130px; +} +.control-row{ + margin-top: 10px; +} +.inputMsg{ + height: 110px !important; + resize: none; +} +.sendBtn{ + height: 100px; +} +footer{ + text-align: center; +} \ No newline at end of file diff --git a/server/center/page/gm.html b/server/center/page/gm.html new file mode 100644 index 00000000..4e32e7a5 --- /dev/null +++ b/server/center/page/gm.html @@ -0,0 +1,61 @@ +-- luacheck: ignore +return [[ + + + + + + + + + GM Console + + + + +
+ +
+ +
+ 服务器: + + + + +
+
+
    +
  • 请选择服务器
  • +
+
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ Designed and built by quanta +
+ + + + + +]] diff --git a/server/center/page/gm.js b/server/center/page/gm.js new file mode 100644 index 00000000..34545763 --- /dev/null +++ b/server/center/page/gm.js @@ -0,0 +1,212 @@ + +function changeServer(){ + var tx = document.getElementById("curServer").value; + window.open(tx, "_self"); +} + +function onfocusServer(){ + document.getElementById("curServer").value = ""; +} + +window.onload = function(){ + var host = window.location.host ; + var selectDiv = document.getElementById("curServer"); + selectDiv.value = host + var gmconsole = new GMConsole(); + gmconsole.init(); +}; + +var GMConsole = function(){ +}; + +GMConsole.prototype = { + init: function(){ + var that = this; + var cmd_index = 0; + var historyCmds = []; + var treeNodes = [{}]; + //获取服务器列表 + var fusion_url = "http://183.66.202.114:18080/server_mgr/query"; + + // 加载命令列表 + $.ajax({ + url: "/gmlist", + type: "GET", + dataType: "json", + contentType: "utf-8", + success: function (res) { + treeNodes[0] = res; + that._showConsole(treeNodes); + }, + error: function(status) { + document.write(JSON.stringify(status)); + } + }); + + // 加载命令列表 + $.ajax({ + url: fusion_url, + type: "GET", + dataType: "json", + contentType: "utf-8", + success: function (res) { + console.log(JSON.stringify(res)); + that._showServers(res); + }, + error: function(status) { + document.write(JSON.stringify(status)); + } + }); + + //sendMsg事件 + document.getElementById('send').addEventListener('click', function(){ + that._sendCommand(historyCmds); + cmd_index = historyCmds.length + }, false); + + //inputMsg事件 + document.getElementById('inputMsg').addEventListener('keyup', function(e){ + if (e.keyCode == 13 && e.ctrlKey){ + that._sendCommand(historyCmds); + cmd_index = historyCmds.length + } else if (e.keyCode == 38){ + if (cmd_index > 0) cmd_index = cmd_index - 1 + that._showCommand(historyCmds[cmd_index]) + } else if (e.keyCode == 40){ + if (cmd_index < historyCmds.length - 1) cmd_index = cmd_index + 1 + that._showCommand(historyCmds[cmd_index]) + } + }, false); + }, + + _showCommand: function(cmd) { + var inputMsg = document.getElementById('inputMsg'); + inputMsg.value = cmd; + inputMsg.focus(); + }, + + _showConsole: function(treeNodes) { + var that = this; + $('#consoleTree').treeview({data: treeNodes}); + //consoleTree事件 + $('#consoleTree').on('nodeSelected', function(event, data) { + if (data.tag == "gm") { + //参数数组 + var arg_arr = ["
命令: ", data.text,"  参数: ", data.command];
+                if (data.example) {
+                    arg_arr.push("
示例:"); + arg_arr.push(data.example); + } + if (data.tip) { + arg_arr.push("
说明:"); + arg_arr.push(data.tip); + } + arg_arr.push("
"); + var msg = arg_arr.join("") + that._displayNewMsg("historyMsg", msg, "myMsg"); + that._showCommand(data.name + " ") + } else if (data.tag == "log") { + window.open("http://" + data.text); + } + }); + }, + + _isJson(data){ + try{ + JSON.parse(data); + } + catch(err){ + return false; + } + return true; + }, + + _showServers: function(res){ + var curServerList = document.getElementById('curServerList'); + curServerList.value = ""; + + var host = window.location.host ; + var selectDiv = document.getElementById("curServer"); + selectDiv.value = host + + for (i = 0; i < res.data.length; i++) { + var option = new Option(); + option.innerHTML = res.data[i].name; + option.value = res.data[i].web; + + curServerList.appendChild(option); + console.log(option.value) + } + }, + + _inputMsgTrim(historyCmds){ + var that = this; + var inputMsg = document.getElementById('inputMsg'); + var msg = inputMsg.value.replace('\n', ''); + if (msg == ''){ + inputMsg.focus(); + return null; + } + historyCmds.push(msg); + var result = { cmdType : "cmd", data : {} }; + that._displayNewMsg("historyMsg", msg, "myMsg"); + if(that._isJson(msg)){ + result.cmdType = "json"; + result.data = JSON.stringify({ data : JSON.parse(msg) }); + return result; + } + result.data = JSON.stringify({ data : msg }) + return result; + }, + + _sendCommand: function(historyCmds) { + var that = this; + var result = that._inputMsgTrim(historyCmds); + if(!result){ + that._displayNewMsg("historyMsg", "error", "newMsg"); + return; + } + var url = result.cmdType == "cmd" ? "/command" : "/message"; + $.ajax({ + url: url, + type: "POST", + dataType: "json", + contentType: "application/json", + data: result.data, + success: function (res) { + var result = res.msg + if (res.code != 0) { + var data = "
" + result + "
"; + that._displayNewMsg("historyMsg", data, "newMsg"); + return + } + if (typeof(result) == "object") { + var data = JSON.stringify(result, null, " "); + data = "
" + data + "
"; + that._displayNewMsg("historyMsg", data, "newMsg"); + } else { + var data = "
" + result + "
"; + that._displayNewMsg("historyMsg", data, "newMsg"); + } + }, + error: function(status) { + var data = status.responseText; + data = data.replace(new RegExp("\n",'g'),"
"); + that._displayNewMsg("historyMsg", data, "newMsg"); + } + }); + inputMsg.value = ""; + inputMsg.focus(); + }, + + _displayNewMsg: function(container_id, msg, type){ + var container = document.getElementById(container_id); + var p = document.createElement('p'); + var text = document.createElement("span"); + text.innerHTML = msg; + p.setAttribute('class', type); + p.appendChild(text); + container.appendChild(p); + container.scrollTop = container.scrollHeight; + }, +}; \ No newline at end of file diff --git a/server/gateway/gateway.lua b/server/gateway/gateway.lua index 4e70bb32..2ffbe43d 100644 --- a/server/gateway/gateway.lua +++ b/server/gateway/gateway.lua @@ -74,7 +74,7 @@ end --lobby关闭 ---------------------------------------------------------------- function Gateway:on_service_close(id, name, info) - log_debug("[Gateway][on_service_close] node: %s-%s", name, id) + log_debug("[Gateway][on_service_close] node: {}-{}", name, id) for player_id, player in pairs(self.players) do if player:get_lobby_id() == id then self:kickout_client(player, player_id, SERVER_UPHOLD) @@ -115,12 +115,12 @@ end --更新分组信息 function Gateway:rpc_update_group(player_id, group_name, group_id) - log_debug("[Gateway][rpc_update_group] player(%s) group_name(%s) group_id(%s)", player_id, group_name, group_id) + log_debug("[Gateway][rpc_update_group] player({}) group_name({}) group_id({})", player_id, group_name, group_id) local player = self:get_player(player_id) if player then player:update_group(group_name, group_id) else - log_warn("[Gateway][rpc_update_group] not player player(%s) group_name(%s) group_id(%s)", player_id, group_name, group_id) + log_warn("[Gateway][rpc_update_group] not player player({}) group_name({}) group_id({})", player_id, group_name, group_id) end end @@ -167,7 +167,7 @@ function Gateway:rpc_forward_client(player_id, cmd_id, data) self.ntf_counter:count_increase() local player = self:get_player(player_id) if not player then - log_warn("[Gateway][rpc_forward_client] cmd_id(%s) player(%s) not exist!", cmd_id, player_id) + log_warn("[Gateway][rpc_forward_client] cmd_id({}) player({}) not exist!", cmd_id, player_id) return end player:send_message(cmd_id, data, self:is_print_cmd(cmd_id)) @@ -234,13 +234,13 @@ end --玩家登陆 function Gateway:on_role_login_req(session, cmd_id, body, session_id) local open_id, player_id, lobby, token = body.open_id, body.role_id, body.lobby, body.token - log_debug("[Gateway][on_role_login_req] user(%s) player(%s) login start!", open_id, player_id) + log_debug("[Gateway][on_role_login_req] user({}) player({}) login start!", open_id, player_id) local player = self:get_player(player_id) if player then local osession = player:get_session() if osession == session then --重复发送 - log_err("[Gateway][on_role_login_req] player (%s) call repeated login req", player_id) + log_err("[Gateway][on_role_login_req] player ({}) call repeated login req", player_id) return client_mgr:callback_errcode(session, cmd_id, ROLE_IS_INLINE, session_id) end --踢掉老连接,设置新连接 @@ -252,12 +252,12 @@ function Gateway:on_role_login_req(session, cmd_id, body, session_id) online:login_service(player_id, "gateway", quanta.id) local code, new_token = self:call_lobby(lobby, "rpc_player_login", player_id, open_id, token) if qfailed(code) then - log_err("[Gateway][on_role_login_req] player (%s) call rpc_player_login code %s failed: %s", player_id, code, new_token) + log_err("[Gateway][on_role_login_req] player ({}) call rpc_player_login code {} failed: {}", player_id, code, new_token) return client_mgr:callback_errcode(session, cmd_id, code, session_id) end session.player_id = player_id self:add_player(player, player_id, lobby, new_token) - log_info("[Gateway][on_role_login_req] user:%s player:%s, new_token:%s login success!", open_id, player_id, new_token) + log_info("[Gateway][on_role_login_req] user:{} player:{}, new_token:{} login success!", open_id, player_id, new_token) local callback_data = { error_code = code, token = new_token} client_mgr:callback_by_id(session, cmd_id, callback_data, session_id) end @@ -265,16 +265,16 @@ end --玩家登出 function Gateway:on_role_logout_req(session, cmd_id, body, session_id) local player_id = body.role_id - log_debug("[Gateway][on_role_logout_req] player(%s) logout start!", player_id) + log_debug("[Gateway][on_role_logout_req] player({}) logout start!", player_id) local player = self:get_player(player_id) if player then local code, err = self:call_lobby(player:get_lobby_id(), "rpc_player_logout", player_id) if qfailed(code) then - log_err("[Gateway][on_role_logout_req] call rpc_player_logout code %s failed: %s", code, err) + log_err("[Gateway][on_role_logout_req] call rpc_player_logout code {} failed: {}", code, err) return client_mgr:callback_errcode(session, cmd_id, code, session_id) end online:login_service(player_id, "gateway", 0) - log_info("[Gateway][on_role_logout_req] player(%s) logout success!", player_id) + log_info("[Gateway][on_role_logout_req] player({}) logout success!", player_id) client_mgr:callback_errcode(session, cmd_id, code, session_id) self:close_client(player, player_id) end @@ -283,13 +283,13 @@ end --玩家重登 function Gateway:on_role_reload_req(session, cmd_id, body, session_id) local open_id, player_id, lobby, token = body.open_id, body.role_id, body.lobby, body.token - log_debug("[Gateway][on_role_reload_req] user:%s player:%s token:%s reload start!", open_id, player_id, token) + log_debug("[Gateway][on_role_reload_req] user:{} player:{} token:{} reload start!", open_id, player_id, token) local player = self:get_player(player_id) if player then local osession = player:get_session() if osession == session then --重复发送 - log_err("[Gateway][on_role_reload_req] player (%s) call repeated reload req", player_id) + log_err("[Gateway][on_role_reload_req] player ({}) call repeated reload req", player_id) return client_mgr:callback_errcode(session, cmd_id, ROLE_IS_INLINE, session_id) end --踢掉老连接,设置新连接 @@ -303,7 +303,7 @@ function Gateway:on_role_reload_req(session, cmd_id, body, session_id) end local code, new_token = self:call_lobby(lobby, "rpc_player_reload", player_id, token) if qfailed(code) then - log_err("[Gateway][on_role_reload_req] call rpc_player_reload code %s failed: %s", code, new_token) + log_err("[Gateway][on_role_reload_req] call rpc_player_reload code {} failed: {}", code, new_token) return client_mgr:callback_by_id(session, cmd_id, { error_code = 0, token = 0 }, session_id) end if new_token > 0 then @@ -311,7 +311,7 @@ function Gateway:on_role_reload_req(session, cmd_id, body, session_id) self:add_player(player, player_id, lobby, new_token) end online:login_service(player_id, "gateway", quanta.id) - log_info("[Gateway][on_role_reload_req] user:%s player:%s new_token:%s reload success!", open_id, player_id, new_token) + log_info("[Gateway][on_role_reload_req] user:{} player:{} new_token:{} reload success!", open_id, player_id, new_token) local callback_data = { error_code = code, token = new_token} client_mgr:callback_by_id(session, cmd_id, callback_data, session_id) end @@ -320,7 +320,7 @@ end ---------------------------------------------------------------------- --客户端连上 function Gateway:on_socket_accept(session) - --log_debug("[Gateway][on_socket_accept] %s connected!", session.token) + --log_debug("[Gateway][on_socket_accept] {} connected!", session.token) end --客户端连接断开 @@ -328,7 +328,7 @@ function Gateway:on_socket_error(session, token, err) local player_id = session.player_id local player = self:get_player(player_id) if player then - log_warn("[Gateway][on_socket_error] session(%s-%s) lost, because: %s!", token, player_id, err) + log_warn("[Gateway][on_socket_error] session({}-{}) lost, because: {}!", token, player_id, err) self:remove_player(player, player_id) online:login_service(player_id, "gateway", 0) player:notify_disconnect() @@ -341,7 +341,7 @@ function Gateway:on_socket_cmd(session, service_type, cmd_id, body, session_id) self.req_counter:count_increase() local result = event_mgr:notify_listener("on_proto_filter", cmd_id, service_type) if result[1] and result[2] then - log_warn("[Gateway][on_socket_cmd] on_proto_filter false, cmd_id=%s", cmd_id) + log_warn("[Gateway][on_socket_cmd] on_proto_filter false, cmd_id={}", cmd_id) client_mgr:callback_errcode(session, cmd_id, FRAME_UPHOLD, session_id) return end @@ -354,7 +354,7 @@ function Gateway:on_socket_cmd(session, service_type, cmd_id, body, session_id) local player_id = session.player_id local player = self:get_player(player_id) if not player then - log_warn("[Gateway][on_socket_cmd] need login, cmd_id=%s, player_id=%s", cmd_id, player_id) + log_warn("[Gateway][on_socket_cmd] need login, cmd_id={}, player_id={}", cmd_id, player_id) client_mgr:callback_errcode(session, cmd_id, FRAME_FAILED, session_id) return end diff --git a/server/gateway/group_mgr.lua b/server/gateway/group_mgr.lua index 68496853..a0871f0c 100644 --- a/server/gateway/group_mgr.lua +++ b/server/gateway/group_mgr.lua @@ -14,7 +14,7 @@ end --更新服务网关 function GroupMgr:add_member(group_id, player_id, player) - log_info("[GroupMgr][add_member] group_id(%s) player_id(%s)!", group_id, player_id) + log_info("[GroupMgr][add_member] group_id({}) player_id({})!", group_id, player_id) local group = self.groups[group_id] local token = player:get_session_token() if not group then @@ -26,7 +26,7 @@ end --更新分组信息 function GroupMgr:remove_member(group_id, player_id) - log_info("[GroupMgr][remove_member] group_id(%s) player_id(%s)!", group_id, player_id) + log_info("[GroupMgr][remove_member] group_id({}) player_id({})!", group_id, player_id) local group = self.groups[group_id] if group then group[player_id] = nil diff --git a/server/gateway/player.lua b/server/gateway/player.lua index e1517af6..2e8694c3 100644 --- a/server/gateway/player.lua +++ b/server/gateway/player.lua @@ -35,7 +35,7 @@ end --更新分组信息 function GatePlayer:update_group(group_name, group_id) - log_info("[GatePlayer][update_group] player(%d) group(%s) id(%s)!", self.player_id, group_name, group_id) + log_info("[GatePlayer][update_group] player({}) group({}) id({})!", self.player_id, group_name, group_id) local old_group = self.groups[group_name] self.groups[group_name] = group_id --管理 玩家 group 信息 @@ -64,7 +64,7 @@ end function GatePlayer:send_message(cmd_id, data, display) client_mgr:send(self.session, cmd_id, data) if display then - log_debug("[GatePlayer][send_message] player(%s) send message(%s-%s) !", self.player_id, cmd_id, data) + log_debug("[GatePlayer][send_message] player({}) send message({}-{}) !", self.player_id, cmd_id, data) end end @@ -73,12 +73,12 @@ function GatePlayer:notify_command(service_id, cmd_id, body, session_id, display local pla_id = self.player_id local ok, codeoe, res = router_mgr:forward_call(pla_id, service_id, "rpc_player_command", pla_id, cmd_id, body) if qfailed(codeoe, ok) then - log_err("[GatePlayer][notify_command] player(%s) rpc_player_command(%s) code %s, failed: %s", pla_id, cmd_id, codeoe, res) + log_err("[GatePlayer][notify_command] player({}) rpc_player_command({}) code {}, failed: {}", pla_id, cmd_id, codeoe, res) client_mgr:callback_errcode(self.session, cmd_id, codeoe, session_id) return end if display then - log_debug("[GatePlayer][notify_command] player(%s) response message(%s-%s) !", pla_id, cmd_id, res) + log_debug("[GatePlayer][notify_command] player({}) response message({}-{}) !", pla_id, cmd_id, res) end client_mgr:callback_by_id(self.session, cmd_id, res, session_id) end diff --git a/server/lobby/player/player.lua b/server/lobby/player/player.lua index 0d385fa6..d4a635bf 100644 --- a/server/lobby/player/player.lua +++ b/server/lobby/player/player.lua @@ -85,7 +85,7 @@ function Player:load(conf) self:invoke("_load", channel, self.id) local ok, code = channel:execute() if not ok then - log_warn("[Player][load] player(%s) failed: %s!", self.id, code) + log_warn("[Player][load] player({}) failed: {}!", self.id, code) end return ok end @@ -127,7 +127,7 @@ function Player:check(now) if self.status == ONL_LOADING then --加载失败 if now_ms - self.active_time > SECOND_5_MS then - log_warn("[Player][check] player(%s) load too long, will be destory!", self.id) + log_warn("[Player][check] player({}) load too long, will be destory!", self.id) self:set_release(true) self.status = ONL_CLOSE end @@ -136,7 +136,7 @@ function Player:check(now) if self.status == ONL_OFFLINE then --掉线清理 if now_ms - self.active_time > OFFTIMEOUT then - log_warn("[Player][check] player(%s) offline too long, will be destory!", self.id) + log_warn("[Player][check] player({}) offline too long, will be destory!", self.id) self:set_release(true) self.status = ONL_CLOSE end @@ -161,7 +161,7 @@ function Player:online() --load success self:save_login_time(quanta.now) self.load_success = true - log_info("[Player][online] player(%s) is online!", self.id) + log_info("[Player][online] player({}) is online!", self.id) end --掉线 @@ -170,7 +170,7 @@ function Player:offline() self.active_time = quanta.now_ms --invoke self:invoke("_offline") - log_warn("[Player][offline] player(%s) is offline!", self.id) + log_warn("[Player][offline] player({}) is offline!", self.id) end function Player:relive() @@ -179,7 +179,7 @@ function Player:relive() self.active_time = quanta.now_ms --invoke self:invoke("_relive") - log_warn("[Player][relive] player(%s) is relive!", self.id) + log_warn("[Player][relive] player({}) is relive!", self.id) end --unload diff --git a/server/lobby/player/player_mgr.lua b/server/lobby/player/player_mgr.lua index ddf79155..840dc715 100644 --- a/server/lobby/player/player_mgr.lua +++ b/server/lobby/player/player_mgr.lua @@ -87,7 +87,7 @@ end function PlayerMgr:load_account(open_id, player_id) local account = Account(open_id) if not account:load() then - log_err("[PlayerMgr][load_account] (%s-%s)load account failed", open_id, player_id) + log_err("[PlayerMgr][load_account] ({}-{})load account failed", open_id, player_id) return end return account @@ -102,7 +102,7 @@ end --群发信息 function PlayerMgr:group_message(players, cmd_id, data) - log_debug("[PlayerMgr][group_message] players: %s, cmdid: %s", players, cmd_id) + log_debug("[PlayerMgr][group_message] players: {}, cmdid: {}", players, cmd_id) for _, player_id in pairs(players) do local player = self:get_entity(player_id) if player then diff --git a/server/lobby/servlet/lobby_servlet.lua b/server/lobby/servlet/lobby_servlet.lua index 60669946..bff1bf0e 100644 --- a/server/lobby/servlet/lobby_servlet.lua +++ b/server/lobby/servlet/lobby_servlet.lua @@ -51,7 +51,7 @@ function LobbyServlet:check_login_token(open_id, token) end function LobbyServlet:rpc_update_login_token(open_id, token) - log_debug("[LobbyServlet][rpc_update_login_token] open_id(%s) token(%s)!", open_id, token) + log_debug("[LobbyServlet][rpc_update_login_token] open_id({}) token({})!", open_id, token) self.login_tokens[open_id] = { token, quanta.now + MINUTE_5_S } return FRAME_SUCCESS end @@ -68,7 +68,7 @@ end function LobbyServlet:rpc_player_disconnect(player_id) local player = player_mgr:get_entity(player_id) if player then - log_warn("[LobbyServlet][rpc_player_disconnect] player(%s) offline", player_id) + log_warn("[LobbyServlet][rpc_player_disconnect] player({}) offline", player_id) player:offline() end end @@ -85,7 +85,7 @@ end function LobbyServlet:rpc_player_command(player_id, cmd_id, message) local player = player_mgr:get_entity(player_id) if not player then - log_err("[LobbyServlet][rpc_player_command] need login cmd_id=%s, player_id=%s", cmd_id, player_id) + log_err("[LobbyServlet][rpc_player_command] need login cmd_id={}, player_id={}", cmd_id, player_id) return ROLE_NOT_EXIST end local result = event_mgr:notify_command(cmd_id, player, player_id, message) @@ -96,7 +96,7 @@ function LobbyServlet:rpc_player_command(player_id, cmd_id, message) end function LobbyServlet:rpc_player_login(player_id, open_id, token) - log_debug("[LobbyServlet][rpc_player_login] open_id(%s) player(%s) token(%s) login req!", open_id, player_id, token) + log_debug("[LobbyServlet][rpc_player_login] open_id({}) player({}) token({}) login req!", open_id, player_id, token) local account = player_mgr:load_account(open_id, player_id) if not account then return ROLE_TOKEN_ERR @@ -104,12 +104,12 @@ function LobbyServlet:rpc_player_login(player_id, open_id, token) --验证token local ok, login_token = self:check_login_token(open_id, token) if not ok then - log_err("[LobbyServlet][rpc_player_login] token verify failed! player:%s, token: %s-%s", player_id, token, login_token) + log_err("[LobbyServlet][rpc_player_login] token verify failed! player:{}, token: {}-{}", player_id, token, login_token) return ROLE_TOKEN_ERR end local player = player_mgr:load_player(account, player_id) if not player then - log_err("[LobbyServlet][rpc_player_login] load_player failed! player:%s", player_id) + log_err("[LobbyServlet][rpc_player_login] load_player failed! player:{}", player_id) return FRAME_FAILED end --通知登陆成功 @@ -122,23 +122,23 @@ function LobbyServlet:rpc_player_login(player_id, open_id, token) --通知登陆成功 event_mgr:notify_trigger("on_login_success", player_id, player) end) - log_info("[LobbyServlet][rpc_player_login] player(%s) login success!", player_id) + log_info("[LobbyServlet][rpc_player_login] player({}) login success!", player_id) return FRAME_SUCCESS, new_token end function LobbyServlet:rpc_player_logout(player_id) - log_debug("[LobbyServlet][rpc_player_logout] player(%s) logout req!", player_id) + log_debug("[LobbyServlet][rpc_player_logout] player({}) logout req!", player_id) local player = player_mgr:get_entity(player_id) if not player then return ROLE_NOT_EXIST end player_mgr:remove_entity(player, player_id) - log_info("[LobbyServlet][rpc_player_logout] player(%s) logout success!", player_id) + log_info("[LobbyServlet][rpc_player_logout] player({}) logout success!", player_id) return FRAME_SUCCESS end function LobbyServlet:rpc_player_reload(player_id, token) - log_debug("[LobbyServlet][rpc_player_reload] player(%s) reload req!", player_id) + log_debug("[LobbyServlet][rpc_player_reload] player({}) reload req!", player_id) local player = player_mgr:get_entity(player_id) if not player then return ROLE_NOT_EXIST @@ -150,14 +150,14 @@ function LobbyServlet:rpc_player_reload(player_id, token) --验证token local old_token = account:get_reload_token() if token ~= old_token then - log_err("[LobbyServlet][rpc_player_login] token verify failed! player:%s, token: %s-%s", player_id, token, old_token) + log_err("[LobbyServlet][rpc_player_login] token verify failed! player:{}, token: {}-{}", player_id, token, old_token) return ROLE_TOKEN_ERR end player:relive() local new_token = mrandom() account:set_reload_token(new_token) event_mgr:notify_trigger("on_reload_success", player_id, player) - log_debug("[LobbyServlet][rpc_player_reload] player(%s) reload success!", player_id) + log_debug("[LobbyServlet][rpc_player_reload] player({}) reload success!", player_id) return FRAME_SUCCESS, new_token end diff --git a/server/login/login_dao.lua b/server/login/login_dao.lua index e5f0227b..3bc71789 100644 --- a/server/login/login_dao.lua +++ b/server/login/login_dao.lua @@ -26,7 +26,7 @@ end function LoginDao:get_autoinc_id(user_id) local aok, acode, role_id = redis_agent:execute({ "INCR", AUTOINCKEY }) if qfailed(acode, aok) then - log_err("[LoginDao][get_autoinc_id] user_id: %s get_autoinc_id failed! code: %s, res: %s", user_id, acode, role_id) + log_err("[LoginDao][get_autoinc_id] user_id: {} get_autoinc_id failed! code: {}, res: {}", user_id, acode, role_id) return false end return true, SUCCESS, BENCHMARK + role_id @@ -35,7 +35,7 @@ end function LoginDao:check_name_exist(name) local ok, code, udata = mongo_agent:find_one({ "player", { nick = name }, { nick = 1 } }) if qfailed(code, ok) then - log_err("[LoginDao][check_name_exist] name: %s find failed! code: %s, res: %s", name, code, udata) + log_err("[LoginDao][check_name_exist] name: {} find failed! code: {}, res: {}", name, code, udata) return false end return (udata ~= nil) @@ -53,7 +53,7 @@ function LoginDao:create_player(open_id, player_id, data) } local ok, code, udata = mongo_agent:insert({ "player", pdata }) if qfailed(code, ok) then - log_err("[LoginDao][create_player] player_id: %s create failed! code: %s, res: %s", player_id, code, udata) + log_err("[LoginDao][create_player] player_id: {} create failed! code: {}, res: {}", player_id, code, udata) return false end return true @@ -66,7 +66,7 @@ function LoginDao:check_player(user_id, name) local check_res = event_mgr:notify_listener("on_safe_text", user_id, name) local check_ok, code, result_name = tunpack(check_res) if qfailed(code, check_ok) then - log_err("[LoginDao][check_player] user_id:%s ok:%s code:%s result_name:%s", user_id, check_ok, code, result_name) + log_err("[LoginDao][check_player] user_id:{} ok:{} code:{} result_name:{}", user_id, check_ok, code, result_name) end return check_ok, code end) diff --git a/server/login/login_mgr.lua b/server/login/login_mgr.lua index 77fbb92a..c67dd279 100644 --- a/server/login/login_mgr.lua +++ b/server/login/login_mgr.lua @@ -27,15 +27,15 @@ end --客户端连上 function LoginMgr:on_socket_accept(session) - log_debug("[LoginMgr][on_socket_accept] %s connected!", session.token) + log_debug("[LoginMgr][on_socket_accept] {} connected!", session.token) end --客户端连接断开 function LoginMgr:on_socket_error(session, token, err) - log_debug("[LoginMgr][on_socket_error] %s lost, because: %s!", token, err) + log_debug("[LoginMgr][on_socket_error] {} lost, because: {}!", token, err) local account = session.account if account then - log_debug("[LoginMgr][on_socket_error] (t:%s-o:%s-u:%s) lost, because: %s!", token, account.open_id, account.user_id, err) + log_debug("[LoginMgr][on_socket_error] (t:{}-o:{}-u:{}) lost, because: {}!", token, account.open_id, account.user_id, err) end end @@ -43,7 +43,7 @@ end function LoginMgr:on_socket_cmd(session, service_type, cmd_id, body, session_id) local result = event_mgr:notify_listener("on_proto_filter", cmd_id, service_type) if result[1] and result[2] then - log_warn("[LoginMgr][on_socket_cmd] on_proto_filter false, cmd_id=%s", cmd_id) + log_warn("[LoginMgr][on_socket_cmd] on_proto_filter false, cmd_id={}", cmd_id) client_mgr:callback_errcode(session, cmd_id, FRAME_UPHOLD, session_id) return end diff --git a/server/login/login_servlet.lua b/server/login/login_servlet.lua index 043e1654..20dd236e 100644 --- a/server/login/login_servlet.lua +++ b/server/login/login_servlet.lua @@ -56,7 +56,7 @@ end --账号登陆 function LoginServlet:on_account_login_req(session, cmd_id, body, session_id) local open_id, access_token, platform = body.openid, body.session, body.platform - log_debug("[LoginServlet][on_account_login_req] open_id(%s) token(%s) body:%s login req!", open_id, access_token, body) + log_debug("[LoginServlet][on_account_login_req] open_id({}) token({}) body:{} login req!", open_id, access_token, body) if session.account then return client_mgr:callback_errcode(session, cmd_id, ACCOUTN_INLINE, session_id) end @@ -64,11 +64,12 @@ function LoginServlet:on_account_login_req(session, cmd_id, body, session_id) local account_params = {} if platform >= PLATFORM_PASSWORD then --登录验证 + body.ip = session.ip local result = event_mgr:notify_listener("on_platform_login", platform, open_id, access_token, body, account_params) local ok, code, sdk_open_id, sdk_device_id = tunpack(result) local login_failed, login_code = qfailed(code, ok) if login_failed then - log_err("[LoginServlet][on_account_login_req] verify failed! open_id: %s token:%s code:%s", open_id, access_token, login_code) + log_err("[LoginServlet][on_account_login_req] verify failed! open_id: {} token:{} code:{}", open_id, access_token, login_code) client_mgr:callback_errcode(session, cmd_id, login_code, session_id) return false end @@ -78,25 +79,25 @@ function LoginServlet:on_account_login_req(session, cmd_id, body, session_id) --加载账号信息 local account = login_dao:load_account(open_id) if not account then - log_err("[LoginServlet][on_account_login_req] load account failed! open_id: %s token:%s", open_id, access_token) + log_err("[LoginServlet][on_account_login_req] load account failed! open_id: {} token:{}", open_id, access_token) return client_mgr:callback_errcode(session, cmd_id, FRAME_FAILED, session_id) end --创建账号 if account:is_newbee() then if not account:create(access_token, device_id, account_params) then - log_err("[LoginServlet][on_account_login_req] open_id(%s) create account failed!", open_id) + log_err("[LoginServlet][on_account_login_req] open_id({}) create account failed!", open_id) return client_mgr:callback_errcode(session, cmd_id, FRAME_FAILED, session_id) end session.account = account event_mgr:notify_listener("on_account_create", account, device_id, session.ip, account_params.lang, account_params.dev_plat) client_mgr:callback_by_id(session, cmd_id, account:pack2client(), session_id) - log_info("[LoginServlet][on_account_login_req] newbee success! open_id: %s", open_id) + log_info("[LoginServlet][on_account_login_req] newbee success! open_id: {}", open_id) return end --密码验证 if platform == PLATFORM_PASSWORD and account:get_token() ~= access_token then - log_err("[LoginServlet][on_password_login] verify failed! open_id: %s token: %s-%s", open_id, access_token, account:get_token()) + log_err("[LoginServlet][on_password_login] verify failed! open_id: {} token: {}-{}", open_id, access_token, account:get_token()) return client_mgr:callback_errcode(session, cmd_id, VERIFY_FAILED, session_id) end session.account = account @@ -105,144 +106,144 @@ function LoginServlet:on_account_login_req(session, cmd_id, body, session_id) account:update_params(account_params) event_mgr:notify_listener("on_account_login", account:get_user_id(), open_id, device_id, session.ip, account_params.lang, account_params.dev_plat) if not client_mgr:callback_by_id(session, cmd_id, account:pack2client(), session_id) then - log_info("[LoginServlet][on_account_login_req] callback failed! open_id: %s, user_id: %s", open_id, account:get_user_id()) + log_info("[LoginServlet][on_account_login_req] callback failed! open_id: {}, user_id: {}", open_id, account:get_user_id()) return end - log_info("[LoginServlet][on_account_login_req] success! open_id: %s, user_id: %s", open_id, account:get_user_id()) + log_info("[LoginServlet][on_account_login_req] success! open_id: {}, user_id: {}", open_id, account:get_user_id()) end --创建角色 function LoginServlet:on_role_create_req(session, cmd_id, body, session_id) local user_id, name = body.user_id, body.name - log_debug("[LoginServlet][on_role_create_req] user(%s) name(%s) create role req!", user_id, name) + log_debug("[LoginServlet][on_role_create_req] user({}) name({}) create role req!", user_id, name) local account = session.account if not account or account.user_id ~= user_id then - log_err("[LoginServlet][on_role_create_req] user_id(%s) need login!", user_id) + log_err("[LoginServlet][on_role_create_req] user_id({}) need login!", user_id) return client_mgr:callback_errcode(session, cmd_id, ACCOUTN_OFFLINE, session_id) end if account:get_role_count() > 1 then - log_err("[LoginServlet][on_role_create_req] user_id(%s) role num limit!", user_id) + log_err("[LoginServlet][on_role_create_req] user_id({}) role num limit!", user_id) return client_mgr:callback_errcode(session, cmd_id, ROLE_NUM_LIMIT, session_id) end --检查名称合法性 local ok, codatas = login_dao:check_player(user_id, name) - log_debug("[LoginServlet][on_role_create_req] ok:%s codatas:%s", ok, codatas) + log_debug("[LoginServlet][on_role_create_req] ok:{} codatas:{}", ok, codatas) if not ok then return client_mgr:callback_errcode(session, cmd_id, codatas, session_id) end --创建角色 local role_id = codatas[3] if not login_dao:create_player(account:get_open_id(), role_id, body) then - log_err("[LoginServlet][on_role_create_req] user_id(%s) create role failed!", user_id) + log_err("[LoginServlet][on_role_create_req] user_id({}) create role failed!", user_id) return client_mgr:callback_errcode(session, cmd_id, FRAME_FAILED, session_id) end account:save_roles_field(role_id, body) event_mgr:notify_listener("on_role_create", user_id, role_id, body) local rdata = { role_id = role_id, gender = body.gender, name = body.name } if not client_mgr:callback_by_id(session, cmd_id, { error_code = 0, role = rdata }, session_id) then - log_info("[LoginServlet][on_role_create_req] user_id(%s) create role %s callback failed!", user_id, name) + log_info("[LoginServlet][on_role_create_req] user_id({}) create role {} callback failed!", user_id, name) return end - log_info("[LoginServlet][on_role_create_req] user_id(%s) create role %s success!", user_id, name) + log_info("[LoginServlet][on_role_create_req] user_id({}) create role {} success!", user_id, name) end --选择角色 function LoginServlet:on_role_choose_req(session, cmd_id, body, session_id) local user_id, role_id = body.user_id, body.role_id - log_debug("[LoginServlet][on_role_choose_req] user_id(%s) role_id(%s) choose req!", user_id, role_id) + log_debug("[LoginServlet][on_role_choose_req] user_id({}) role_id({}) choose req!", user_id, role_id) local account = session.account if not account then - log_err("[LoginServlet][on_role_choose_req] user_id(%s) need login!", user_id) + log_err("[LoginServlet][on_role_choose_req] user_id({}) need login!", user_id) return client_mgr:callback_errcode(session, cmd_id, ACCOUTN_OFFLINE, session_id) end local role = account:get_role(role_id) if not role then - log_err("[LoginServlet][on_role_choose_req] user_id(%s) role_id(%s) role nit exist!", user_id, role_id) + log_err("[LoginServlet][on_role_choose_req] user_id({}) role_id({}) role nit exist!", user_id, role_id) return client_mgr:callback_errcode(session, cmd_id, ROLE_NOT_EXIST, session_id) end local fok, gateway = self:find_gateway(account) - log_debug("[LoginServlet][on_role_choose_req] choose gateway(%s)!", gateway) + log_debug("[LoginServlet][on_role_choose_req] choose gateway({})!", gateway) if not fok then - log_err("[LoginServlet][on_role_choose_req] user_id(%s) role_id(%s) server uphold!", user_id, role_id) + log_err("[LoginServlet][on_role_choose_req] user_id({}) role_id({}) server uphold!", user_id, role_id) return client_mgr:callback_errcode(session, cmd_id, SERVER_UPHOLD, session_id) end local ok, code = router_mgr:call_target(gateway.lobby, "rpc_update_login_token", account.open_id, gateway.token) if qfailed(code, ok) then - log_err("[LoginServlet][on_role_choose_req] user_id(%s) role_id(%s) update token failed!", user_id, role_id) + log_err("[LoginServlet][on_role_choose_req] user_id({}) role_id({}) update token failed!", user_id, role_id) return client_mgr:callback_errcode(session, cmd_id, SERVER_UPHOLD, session_id) end account:save_lobby(gateway.lobby) if not client_mgr:callback_by_id(session, cmd_id, gateway, session_id) then - log_info("[LoginServlet][on_role_choose_req] user_id(%s) role_id(%s) callback failed!", user_id, role_id) + log_info("[LoginServlet][on_role_choose_req] user_id({}) role_id({}) callback failed!", user_id, role_id) return end - log_info("[LoginServlet][on_role_choose_req] user_id(%s) role_id(%s) choose success!", user_id, role_id) + log_info("[LoginServlet][on_role_choose_req] user_id({}) role_id({}) choose success!", user_id, role_id) end --删除角色 function LoginServlet:on_role_delete_req(session, cmd_id, body, session_id) local user_id, role_id = body.user_id, body.role_id - log_debug("[LoginServlet][on_role_delete_req] user_id(%s) role_id(%s) delete req!", user_id, role_id) + log_debug("[LoginServlet][on_role_delete_req] user_id({}) role_id({}) delete req!", user_id, role_id) local account = session.account if not account or account:get_user_id() ~= user_id then - log_err("[LoginServlet][on_role_delete_req] user_id(%s) need login!", user_id) + log_err("[LoginServlet][on_role_delete_req] user_id({}) need login!", user_id) return client_mgr:callback_errcode(session, cmd_id, ACCOUTN_OFFLINE, session_id) end if not account:del_role(role_id) then - log_err("[LoginServlet][on_role_delete_req] user_id(%s) role_id(%s) role nit exist!", user_id, role_id) + log_err("[LoginServlet][on_role_delete_req] user_id({}) role_id({}) role nit exist!", user_id, role_id) return client_mgr:callback_errcode(session, cmd_id, ROLE_NOT_EXIST, session_id) end if not client_mgr:callback_errcode(session, cmd_id, FRAME_SUCCESS, session_id) then - log_info("[LoginServlet][on_role_delete_req] user_id(%s) role_id(%s) callback failed!", user_id, role_id) + log_info("[LoginServlet][on_role_delete_req] user_id({}) role_id({}) callback failed!", user_id, role_id) return end - log_info("[LoginServlet][on_role_delete_req] user_id(%s) role_id(%s) delete success!", user_id, role_id) + log_info("[LoginServlet][on_role_delete_req] user_id({}) role_id({}) delete success!", user_id, role_id) end --账号重登 function LoginServlet:on_account_reload_req(session, cmd_id, body, session_id) local open_id, token, device_id = body.openid, body.session, body.device_id - log_debug("[LoginServlet][on_account_reload_req] openid(%s) token(%s) reload req!", open_id, token) + log_debug("[LoginServlet][on_account_reload_req] openid({}) token({}) reload req!", open_id, token) if session.account then return client_mgr:callback_errcode(session, cmd_id, ACCOUTN_INLINE, session_id) end --验证token local account = login_dao:load_account(open_id) if not account then - log_err("[LoginServlet][on_account_login_req] load account failed! open_id: %s token:%s", open_id, token) + log_err("[LoginServlet][on_account_login_req] load account failed! open_id: {} token:{}", open_id, token) return client_mgr:callback_errcode(session, cmd_id, FRAME_FAILED, session_id) end if account:is_newbee() then - log_err("[LoginServlet][on_account_reload_req] open_id(%s) load account status failed!", open_id) + log_err("[LoginServlet][on_account_reload_req] open_id({}) load account status failed!", open_id) return client_mgr:callback_errcode(session, cmd_id, FRAME_FAILED, session_id) end local old_token = account:get_token() if token ~= old_token or device_id ~= account:get_device_id() then - log_err("[LoginServlet][on_account_reload_req] verify failed! open_id: %s, token: %s-%s", open_id, token, old_token) + log_err("[LoginServlet][on_account_reload_req] verify failed! open_id: {}, token: {}-{}", open_id, token, old_token) return client_mgr:callback_errcode(session, cmd_id, VERIFY_FAILED, session_id) end session.account = account if not client_mgr:callback_by_id(session, cmd_id, account:pack2client(), session_id) then - log_info("[LoginServlet][on_account_reload_req] callback failed! open_id: %s", open_id) + log_info("[LoginServlet][on_account_reload_req] callback failed! open_id: {}", open_id) return end - log_info("[LoginServlet][on_account_reload_req] success! open_id: %s, user_id: %s", open_id, account:get_user_id()) + log_info("[LoginServlet][on_account_reload_req] success! open_id: {}, user_id: {}", open_id, account:get_user_id()) end --随机名字 function LoginServlet:on_random_name_req(session, cmd_id, body, session_id) local rname = guid_encode() - log_debug("[LoginServlet][on_random_name_req] open_id(%s) randname: %s!", session.open_id, rname) + log_debug("[LoginServlet][on_random_name_req] open_id({}) randname: {}!", session.open_id, rname) local callback_data = { error_code = 0, name = rname } if not client_mgr:callback_by_id(session, cmd_id, callback_data, session_id) then - log_info("[LoginServlet][on_random_name_req] callback failed! open_id: %s", session.open_id) + log_info("[LoginServlet][on_random_name_req] callback failed! open_id: {}", session.open_id) end end --网关和lobby相关接口 ---------------------------------------------------------------- function LoginServlet:on_service_close(id, name, info) - log_debug("[LoginServlet][on_service_close] node: %s-%s", name, id) + log_debug("[LoginServlet][on_service_close] node: {}-{}", name, id) if name == "lobby" then self.lobbys[id] = nil return @@ -258,7 +259,7 @@ function LoginServlet:on_service_close(id, name, info) end function LoginServlet:on_service_ready(id, name, info) - log_debug("[LoginServlet][on_service_ready] node: %s-%s, info: %s", name, id, info) + log_debug("[LoginServlet][on_service_ready] node: {}-{}, info: {}", name, id, info) if name == "lobby" then self.lobbys[id] = info return diff --git a/server/monitor/hotfix_mgr.lua b/server/monitor/hotfix_mgr.lua index d268f94b..b2297e27 100644 --- a/server/monitor/hotfix_mgr.lua +++ b/server/monitor/hotfix_mgr.lua @@ -35,10 +35,10 @@ function HotfixMgr:setup() thread_mgr:fork(function() self.config = import("hotfix/version.lua") self.dictionary = import("hotfix/dictionary.lua") - log_debug("[HotfixMgr][init_nacos] versions:%s", self.config) + log_debug("[HotfixMgr][init_nacos] versions:{}", self.config) --回调函数 local config_changed = function(data_id, group, md5, cvalue) - log_debug("[HotfixMgr][config_changed]: dataid:%s md5:%s", data_id, md5) + log_debug("[HotfixMgr][config_changed]: dataid:{} md5:{}", data_id, md5) self:hotfix_callback(group, md5, cvalue) end nacos:listen_config(self.config.data_id, self.config.group, self.config.md5, config_changed) @@ -76,11 +76,11 @@ end function HotfixMgr:update_config(data_id, group, path) local content = nacos:get_config(data_id, group); if not content then - log_warn("[HotfixMgr][update_config] update script:%s failed!", path) + log_warn("[HotfixMgr][update_config] update script:{} failed!", path) return end self:encrypt(path, content) - log_debug("[HotfixMgr][update_config] update script: %s success!", path) + log_debug("[HotfixMgr][update_config] update script: {} success!", path) end --热更 @@ -88,7 +88,7 @@ function HotfixMgr:hotfix_callback(group, md5, cvalue) --加载字典文件 local dic_func, err = load(cvalue) if not dic_func then - log_warn("[HotfixMgr][hotfix_callback] load dictionary failed: %s !", err) + log_warn("[HotfixMgr][hotfix_callback] load dictionary failed: {} !", err) return end --更新版本配置 diff --git a/server/monitor/monitor_mgr.lua b/server/monitor/monitor_mgr.lua index 38079cf5..4bf3b9ae 100644 --- a/server/monitor/monitor_mgr.lua +++ b/server/monitor/monitor_mgr.lua @@ -66,7 +66,7 @@ end function MonitorMgr:on_client_register(client, node) local token = client.token - log_debug("[MonitorMgr][on_service_register] node:%s, token: %s", node.name, token) + log_debug("[MonitorMgr][on_service_register] node:{}, token: {}", node.name, token) self.discovery:register(node) self.monitor_nodes[token] = node --返回所有服务 @@ -80,7 +80,7 @@ end -- 会话关闭回调 function MonitorMgr:on_client_error(client, token, err) - log_info("[MonitorMgr][on_client_error] node:%s, token:%s", client.name, token) + log_info("[MonitorMgr][on_client_error] node:{}, token:{}", client.name, token) local node = self.monitor_nodes[token] if node then self.discovery:unregister(client.id) @@ -114,7 +114,7 @@ end -- command处理 function MonitorMgr:on_monitor_command(url, body) - log_debug("[MonitorMgr][on_monitor_command]: %s", body) + log_debug("[MonitorMgr][on_monitor_command]: {}", body) --执行函数 local function handler_cmd(jbody) if body.token then @@ -125,7 +125,7 @@ function MonitorMgr:on_monitor_command(url, body) --开始执行 local ok, res = pcall(handler_cmd, body) if not ok then - log_warn("[MonitorMgr:on_monitor_post] pcall: %s", res) + log_warn("[MonitorMgr:on_monitor_post] pcall: {}", res) return {code = 1, msg = res} end return res @@ -138,7 +138,7 @@ function MonitorMgr:on_server_shutdown(url, body, request) self:broadcast_all("rpc_server_shutdown") -- 关闭会话连接 timer_mgr:loop(SECOND_10_MS, function() - log_warn("[MonitorMgr][on_server_shutdown]->service:%s", quanta.name) + log_warn("[MonitorMgr][on_server_shutdown]->service:{}", quanta.name) signal_quit() end) diff --git a/server/monitor/nacos_discovery.lua b/server/monitor/nacos_discovery.lua index 13d45fc5..5348c524 100644 --- a/server/monitor/nacos_discovery.lua +++ b/server/monitor/nacos_discovery.lua @@ -56,7 +56,7 @@ function NacosDiscovery:refresh_services() local old = self.services[service_name] local sadd, sdel = tdiff(old, curr) if next(sadd) or next(sdel) then - log_debug("[NacosDiscovery][check_services] sadd:%s, sdel: %s", sadd, sdel) + log_debug("[NacosDiscovery][check_services] sadd:{}, sdel: {}", sadd, sdel) self.trigger:broadcast("rpc_service_changed", service_name, sadd, sdel) self.services[service_name] = curr --设置状态 @@ -101,7 +101,7 @@ function NacosDiscovery:unregister(node_id) local sdata = self.locals[node_id] if sdata then self.locals[node_id] = nil - log_debug("[RedisDiscovery][unregister] node %s", node_id) + log_debug("[RedisDiscovery][unregister] node {}", node_id) nacos:del_instance(sdata.service_name, sdata.host, sdata.port) self:refresh_services() end diff --git a/server/monitor/redis_discovery.lua b/server/monitor/redis_discovery.lua index e84de456..203b1ddf 100644 --- a/server/monitor/redis_discovery.lua +++ b/server/monitor/redis_discovery.lua @@ -93,7 +93,7 @@ function RedisDiscovery:on_subscribe_ready(channel, data) local node_id = node_data.id local sname = sid2name(node_id) if channel == CHANNEL_UP then - log_debug("[RedisDiscovery][quanta_register] data:%s", data) + log_debug("[RedisDiscovery][quanta_register] data:{}", data) if sname == "router" then self.routers[node_id] = node_data self.trigger:broadcast("rpc_service_changed", sname, { [node_id] = node_data }, {}) @@ -103,7 +103,7 @@ function RedisDiscovery:on_subscribe_ready(channel, data) self.trigger:broadcast_legal("rpc_service_changed", sname, { [node_id] = node_data }, {}) end if channel == CHANNEL_DN then - log_debug("[RedisDiscovery][quanta_unregister] data:%s", data) + log_debug("[RedisDiscovery][quanta_unregister] data:{}", data) if sname == "router" then self.routers[node_id] = nil self.trigger:broadcast("rpc_service_changed", sname, {}, { [node_id] = node_data }) @@ -142,7 +142,7 @@ function RedisDiscovery:unregister(node_id) local sdata = self.locals[node_id] if sdata then self.locals[node_id] = nil - log_debug("[RedisDiscovery][unregister] node %s", node_id) + log_debug("[RedisDiscovery][unregister] node {}", node_id) self:del_instance(sdata) end end @@ -157,7 +157,7 @@ function RedisDiscovery:query_instances() repeat local ok, next_cur, datas = self.redis:execute("HSCAN", SERVICE_KEY, cur, "count", 200) if not ok or not next_cur or not datas then - log_err("[RedisDiscovery][query_instances] query failed: cur:%s, datas:%s", next_cur, datas) + log_err("[RedisDiscovery][query_instances] query failed: cur:{}, datas:{}", next_cur, datas) return end for node_data, score in pairs(datas) do diff --git a/server/robot/module/login.lua b/server/robot/module/login.lua index 9a7e6e49..3c73be33 100644 --- a/server/robot/module/login.lua +++ b/server/robot/module/login.lua @@ -63,12 +63,12 @@ function LoginModule:guest_login_req() } local ok, res = self:call("NID_LOGIN_ACCOUNT_LOGIN_REQ", req_data) if self:check_callback(ok, res) then - log_warn("[LoginModule][guest_login_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, res) + log_warn("[LoginModule][guest_login_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) return false end self.roles = res.roles self.user_id = res.user_id - log_debug("[LoginModule][guest_login_req] robot:%s success", self:get_title()) + log_debug("[LoginModule][guest_login_req] robot:{} success", self:get_title()) return true end @@ -80,14 +80,14 @@ function LoginModule:account_login_req() platform = PLATFORM_PASSWORD, } local ok, res = self:call("NID_LOGIN_ACCOUNT_LOGIN_REQ", req_data) - log_warn("[LoginModule][account_login_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, req_data) + log_warn("[LoginModule][account_login_req] robot:{}, ok={}, res={}", self:get_title(), ok, req_data) if self:check_callback(ok, res) then - log_warn("[LoginModule][account_login_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, res) + log_warn("[LoginModule][account_login_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) return false end self.roles = res.roles self.user_id = res.user_id - log_debug("[LoginModule][account_login_req] robot:%s success", self:get_title()) + log_debug("[LoginModule][account_login_req] robot:{} success", self:get_title()) return true end @@ -133,10 +133,10 @@ end function LoginModule:random_name_req() local ok, res = self:call("NID_LOGIN_RANDOM_NAME_REQ", {}) if self:check_callback(ok, res) then - log_warn("[LoginModule][random_name_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, res) + log_warn("[LoginModule][random_name_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) return end - log_debug("[LoginModule][random_name_req] robot:%s success", self:get_title()) + log_debug("[LoginModule][random_name_req] robot:{} success", self:get_title()) return res.name end @@ -150,18 +150,18 @@ function LoginModule:create_role_req(name) } local ok, res = self:call("NID_LOGIN_ROLE_CREATE_REQ", req_data) if self:check_callback(ok, res) then - log_warn("[LoginModule][create_role_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, res) + log_warn("[LoginModule][create_role_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) return false end tinsert(self.roles, res.role) - log_debug("[LoginModule][create_role_req] robot:%s success", self:get_title()) + log_debug("[LoginModule][create_role_req] robot:{} success", self:get_title()) return true end function LoginModule:choose_role_req() local role = trandarray(self.roles) if not role then - log_warn("[LoginModule][choose_role_req] robot:%s roles is empty", self:get_title()) + log_warn("[LoginModule][choose_role_req] robot:{} roles is empty", self:get_title()) return false end local req_data = { @@ -170,7 +170,7 @@ function LoginModule:choose_role_req() } local ok, res = self:call("NID_LOGIN_ROLE_CHOOSE_REQ", req_data) if self:check_callback(ok, res) then - log_warn("[LoginModule][choose_role_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, res) + log_warn("[LoginModule][choose_role_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) return false end self.lobby = res.lobby @@ -178,14 +178,14 @@ function LoginModule:choose_role_req() self.gate_port = res.port self.lobby_token = res.token self.player_id = role.role_id - log_debug("[LoginModule][choose_role_req] robot:%s success", self:get_title()) + log_debug("[LoginModule][choose_role_req] robot:{} success", self:get_title()) return true end function LoginModule:delete_role_req() local role = trandarray(self.roles) if not role then - log_warn("[LoginModule][delete_role_req] robot:%s roles is empty", self:get_title()) + log_warn("[LoginModule][delete_role_req] robot:{} roles is empty", self:get_title()) return false end local req_data = { @@ -194,11 +194,11 @@ function LoginModule:delete_role_req() } local ok, res = self:call("NID_LOGIN_ROLE_DELETE_REQ", req_data) if self:check_callback(ok, res) then - log_warn("[LoginModule][delete_role_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, res) + log_warn("[LoginModule][delete_role_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) return false end tdelete(self.roles, role) - log_debug("[LoginModule][delete_role_req] robot:%s success", self:get_title()) + log_debug("[LoginModule][delete_role_req] robot:{} success", self:get_title()) return true end @@ -210,12 +210,12 @@ function LoginModule:account_reload_req() } local ok, res = self:call("NID_LOGIN_ACCOUNT_RELOAD_REQ", req_data) if self:check_callback(ok, res) then - log_warn("[LoginModule][account_reload_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, res) + log_warn("[LoginModule][account_reload_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) return false end self.roles = res.roles self.user_id = res.user_id - log_debug("[LoginModule][account_reload_req] robot:%s success", self:get_title()) + log_debug("[LoginModule][account_reload_req] robot:{} success", self:get_title()) return true end @@ -229,11 +229,11 @@ function LoginModule:role_login_req() } local ok, res = self:call("NID_LOGIN_ROLE_LOGIN_REQ", req_data) if self:check_callback(ok, res) then - log_warn("[LoginModule][role_login_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, res) + log_warn("[LoginModule][role_login_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) return false end self.lobby_token = res.token - log_debug("[LoginModule][role_login_req] robot:%s success", self:get_title()) + log_debug("[LoginModule][role_login_req] robot:{} success", self:get_title()) return true end @@ -241,11 +241,11 @@ function LoginModule:role_logout_req() local req_data = { role_id = self.player_id } local ok, res = self:call("NID_LOGIN_ROLE_LOGOUT_REQ", req_data) if self:check_callback(ok, res) then - log_warn("[LoginModule][role_logout_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, res) + log_warn("[LoginModule][role_logout_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) return false end self.player_id = nil - log_debug("[LoginModule][role_logout_req] robot:%s success", self:get_title()) + log_debug("[LoginModule][role_logout_req] robot:{} success", self:get_title()) return true end @@ -258,11 +258,11 @@ function LoginModule:role_reload_req() } local ok, res = self:call("NID_LOGIN_ROLE_RELOAD_REQ", req_data) if self:check_callback(ok, res) then - log_warn("[LoginModule][role_reload_req] robot:%s, ok=%s, res=%s", self:get_title(), ok, res) + log_warn("[LoginModule][role_reload_req] robot:{}, ok={}, res={}", self:get_title(), ok, res) return false end self.lobby_token = res.token - log_debug("[LoginModule][role_reload_req] robot:%s success", self:get_title()) + log_debug("[LoginModule][role_reload_req] robot:{} success", self:get_title()) return true end diff --git a/server/robot/node_factory.lua b/server/robot/node_factory.lua index 5bbd4380..c6dcdb24 100644 --- a/server/robot/node_factory.lua +++ b/server/robot/node_factory.lua @@ -21,19 +21,19 @@ function NodeFactory:__init() end function NodeFactory:register(id, func) - log_info("[NodeFactory][register] Node %s register!", id) + log_info("[NodeFactory][register] Node {} register!", id) self.nodes[id] = func end function NodeFactory:register_factory(factory) - log_info("[NodeFactory][register] factory %s register!", factory) + log_info("[NodeFactory][register] factory {} register!", factory) tinsert(self.factorys, factory) end function NodeFactory:create(id) local func = self.nodes[id] if not func then - log_err("[NodeFactory][create] Node %s not define!", id) + log_err("[NodeFactory][create] Node {} not define!", id) return end return func() diff --git a/server/robot/report_mgr.lua b/server/robot/report_mgr.lua index 81e62177..c92a79e1 100644 --- a/server/robot/report_mgr.lua +++ b/server/robot/report_mgr.lua @@ -81,7 +81,7 @@ end function ReportMgr:dump_event(event, data) local avg_time = data.total_time / data.number - log_info("%s=>avg:%.2fms, min:%dms, max:%dms, succ:%d/%d", event, avg_time, data.min_time, data.max_time, data.number, data.total) + log_info("{}=>avg:{}ms, min:{}ms, max:{}ms, succ:{}/{}", event, avg_time, data.min_time, data.max_time, data.number, data.total) end function ReportMgr:dump(whole) @@ -99,7 +99,7 @@ function ReportMgr:dump(whole) for event, data in pairs(robot_data) do output = sformat("%s %s=%.3f", output, event, data.tick / 1000) end - log_info("robot-%s=>%s", robot_id, output) + log_info("robot-{}=>{}", robot_id, output) end log_info("----------------------------------------------------") end diff --git a/server/robot/robot.lua b/server/robot/robot.lua index 6ac3a150..dd9cbc72 100644 --- a/server/robot/robot.lua +++ b/server/robot/robot.lua @@ -46,7 +46,7 @@ function Robot:on_second5() end function Robot:push_message(cmd_id, msg) - log_debug("recv server msg:%d %s",cmd_id, msg) + log_debug("recv server msg:{} {}",cmd_id, msg) msg.cmd_id = cmd_id msg_mgr:args_convert(cmd_id, msg) self.messages:push(msg) diff --git a/server/robot/robot_bt.lua b/server/robot/robot_bt.lua index 496da724..ee6d17a0 100644 --- a/server/robot/robot_bt.lua +++ b/server/robot/robot_bt.lua @@ -25,15 +25,15 @@ function RobotBT:__init(conf, index) local tree_id = env_number("QUANTA_TREE_ID", conf.tree_id) local node = node_factory:create(tree_id) if not node then - log_err("[RobotBT][init] robot(%s) create tree(%s) failed!", index, tree_id) + log_err("[RobotBT][init] robot({}) create tree({}) failed!", index, tree_id) return end self.lua_tree = LuaBT(self, node) --设置行为树参数 if conf.args then - local ok, args = pcall(load(sformat("return %s", conf.args))) + local ok, args = pcall(load(sformat("return {}", conf.args))) if not ok then - log_err("[RobotBT][init] robot(%s) load args failed: %s", index, args) + log_err("[RobotBT][init] robot({}) load args failed: {}", index, args) return end if args and args[index] then diff --git a/server/robot/robot_mgr.lua b/server/robot/robot_mgr.lua index f9d7652b..296c88ab 100644 --- a/server/robot/robot_mgr.lua +++ b/server/robot/robot_mgr.lua @@ -36,11 +36,11 @@ function RobotMgr:load_robot() local robot_db = config_mgr:init_table("robot", "index") local conf = robot_db:find_one(index) if not conf then - log_err("[RobotMgr][setup] robot config(%s) is empty", index) + log_err("[RobotMgr][setup] robot config({}) is empty", index) signalquit() return end - log_debug("[RobotMgr][setup] robot config(%s) is loading!", index) + log_debug("[RobotMgr][setup] robot config({}) is loading!", index) local ip, port = env_addr("QUANTA_ROBOT_ADDR") local robot_count = env_number("QUANTA_COUNT", conf.count) --指定账号模式,只能一个机器人 @@ -59,7 +59,7 @@ end -- setup function RobotMgr:create_robot_bt(ip, port, conf, index) - log_debug("[RobotMgr][create_robot_bt]: %s:%s %s(%s)", ip, port, index, conf) + log_debug("[RobotMgr][create_robot_bt]: {}:{} {}({})", ip, port, index, conf) local robot = RobotBT(conf, index) if conf.openid_type == RRANDOM then robot:set_open_id(guid_string()) @@ -86,7 +86,7 @@ end -- setup function RobotMgr:create_robot(ip, port, open_id, passwd) - log_debug("[RobotMgr][create_robot]: %s:%s %s(%s)", ip, port, open_id, passwd) + log_debug("[RobotMgr][create_robot]: {}:{} {}({})", ip, port, open_id, passwd) local robot = Robot() robot:set_ip(ip) robot:set_port(port) diff --git a/server/router/router_server.lua b/server/router/router_server.lua index 53ee91a3..0065fcd4 100644 --- a/server/router/router_server.lua +++ b/server/router/router_server.lua @@ -37,18 +37,18 @@ end --其他服务器节点关闭 function RouterServer:on_client_error(client, client_token, err) - log_info("[RouterServer][on_client_error] %s lost: %s", client.name, err) + log_info("[RouterServer][on_client_error] {} lost: {}", client.name, err) local new_master = socket_mgr.map_token(client.id) - log_info("[RouterServer][on_socket_error] %s master --> %s", client.service_name, new_master) + log_info("[RouterServer][on_socket_error] {} master --> {}", client.service_name, new_master) end --accept事件 function RouterServer:on_client_accept(client) - log_info("[RouterServer][on_client_accept] new connection, token=%s", client.token) + log_info("[RouterServer][on_client_accept] new connection, token={}", client.token) client.on_forward_error = function(session_id, target_id, source_id, rpc) thread_mgr:fork(function() local target, source = id2name(target_id), id2name(source_id) - log_err("[RouterServer][on_client_accept] on_forward_error, ssid:%s, tar:%s, src:%s, rpc:%s)", session_id, target, source, rpc) + log_err("[RouterServer][on_client_accept] on_forward_error, ssid:{}, tar:{}, src:{}, rpc:{})", session_id, target, source, rpc) self.rpc_server:callback(client, session_id, false, UNREACHABLE, "router con't find target!") end) end @@ -63,9 +63,9 @@ end ------------------------------------------------------------------ --注册服务器 function RouterServer:on_client_register(client, node, client_id) - log_info("[RouterServer][on_client_register] service: %s", client.name) + log_info("[RouterServer][on_client_register] service: {}", client.name) local new_master = socket_mgr.map_token(client_id, client.token) - log_info("[RouterServer][on_client_register] %s master --> %s", client.service_name, new_master) + log_info("[RouterServer][on_client_register] {} master --> {}", client.service_name, new_master) end -- 会话信息 diff --git a/server/router/transfer_mgr.lua b/server/router/transfer_mgr.lua index 39fc7cb0..6ce6f9c4 100644 --- a/server/router/transfer_mgr.lua +++ b/server/router/transfer_mgr.lua @@ -39,7 +39,7 @@ end ------------------------------------------------------------------------------ --踢出玩家 function TransferMgr:rpc_router_clean(client, player_id) - log_info("[TransferMgr][rpc_router_clean] player_id : %s", player_id) + log_info("[TransferMgr][rpc_router_clean] player_id : {}", player_id) self.routers[player_id] = nil return SUCCESS end @@ -48,10 +48,10 @@ end function TransferMgr:rpc_login_service(client, player_id, serv_name, serv_id) local routers = self:update_service(player_id, serv_name, serv_id) if routers then - log_info("[TransferMgr][rpc_login_service]: %s, service: %s-%s", player_id, serv_name, serv_id) + log_info("[TransferMgr][rpc_login_service]: {}, service: {}-{}", player_id, serv_name, serv_id) return SUCCESS end - log_warn("[TransferMgr][rpc_login_service]: %s, service: %s-%s failed!", player_id, serv_name, serv_id) + log_warn("[TransferMgr][rpc_login_service]: {}, service: {}-{} failed!", player_id, serv_name, serv_id) return RPC_FAILED end @@ -73,7 +73,7 @@ function TransferMgr:on_broadcast_rpc(client, player_id, slice) routers = self:query_routers(player_id, NODE_ID) end if not routers then - log_warn("[TransferMgr][on_broadcast_rpc]: %s find routers failed!", player_id) + log_warn("[TransferMgr][on_broadcast_rpc]: {} find routers failed!", player_id) return end for _, server_id in pairs(routers) do @@ -95,7 +95,7 @@ function TransferMgr:on_transfer_rpc(client, session_id, service_id, player_id, if session_id > 0 then self.rpc_server:callback(client, session_id, false, PLAYER_NOT_EXIST) end - log_warn("[TransferMgr][on_transfer_rpc]: %s, service: %s failed!", player_id, serv_name) + log_warn("[TransferMgr][on_transfer_rpc]: {}, service: {} failed!", player_id, serv_name) return end self.rpc_server:transfer_call(session_id, routers[serv_name], slice) @@ -122,7 +122,7 @@ function TransferMgr:update_service(pla_id, serv_name, serv_id) local routers = self:query_routers(pla_id, router_id, serv_name, serv_id) if not routers then self.routers[pla_id][serv_name] = old_serv_id - log_warn("[TransferMgr][update_service]: %s service: %s failed!", pla_id, serv_name) + log_warn("[TransferMgr][update_service]: {} service: {} failed!", pla_id, serv_name) return end return routers @@ -136,7 +136,7 @@ function TransferMgr:query_service(player_id, serv_name) end local rrouters = self:query_routers(player_id, NODE_ID) if not rrouters then - log_warn("[TransferMgr][query_service]: %s service: %s failed!", player_id, serv_name) + log_warn("[TransferMgr][query_service]: {} service: {} failed!", player_id, serv_name) return RPC_FAILED end return SUCCESS, rrouters[serv_name] diff --git a/server/test.lua b/server/test.lua index 3ce0c88c..8e936581 100644 --- a/server/test.lua +++ b/server/test.lua @@ -33,5 +33,5 @@ quanta.startup(function()--初始化test import("test/detour_test.lua") import("test/bitarray_test.lua") ]] - import("test/ws_test.lua") + import("test/log_test.lua") end) diff --git a/server/test/bitarray_test.lua b/server/test/bitarray_test.lua index 42830bfc..8a0311ac 100644 --- a/server/test/bitarray_test.lua +++ b/server/test/bitarray_test.lua @@ -3,28 +3,28 @@ local log_debug = logger.debug local array = codec.bitarray(32) -log_debug("array1: %s", array.to_string()) +log_debug("array1: {}", array.to_string()) array.fill(1) -log_debug("array11: %s", array.to_string()) +log_debug("array11: {}", array.to_string()) array.flip(1) -log_debug("array12: %s", array.to_string()) +log_debug("array12: {}", array.to_string()) array.flip_bit(3) -log_debug("array13: %s-%s", array.to_string(), array.get_bit(3)) +log_debug("array13: {}-{}", array.to_string(), array.get_bit(3)) array.from_uint32(65535) -log_debug("array2: %s-%s", array.to_string(), array.to_uint32()) +log_debug("array2: {}-{}", array.to_string(), array.to_uint32()) array.rshift(1) -log_debug("array3: %s-%s", array.to_string(), array.to_uint32()) +log_debug("array3: {}-{}", array.to_string(), array.to_uint32()) array.lshift(1) -log_debug("array4: %s-%s", array.to_string(), array.to_uint32()) +log_debug("array4: {}-{}", array.to_string(), array.to_uint32()) array.set_bit(32, 1) local a2 = array.clone() -log_debug("array5: %s", a2.to_string()) +log_debug("array5: {}", a2.to_string()) local a3 = a2.slice(1, 16) -log_debug("array51: %s", a3.to_string()) +log_debug("array51: {}", a3.to_string()) local a4 = a2.slice(17) -log_debug("array52: %s", a4.to_string()) +log_debug("array52: {}", a4.to_string()) a4.concat(a3) -log_debug("array6: %s", a4.to_string()) +log_debug("array6: {}", a4.to_string()) a4.reverse() -log_debug("array7: %s", a4.to_string()) -log_debug("array8: %s-%s", a4.equal(a2), a3.equal(a2)) +log_debug("array7: {}", a4.to_string()) +log_debug("array8: {}-{}", a4.equal(a2), a3.equal(a2)) diff --git a/server/test/clickhouse_test.lua b/server/test/clickhouse_test.lua index d1fe1bf9..d6af8146 100644 --- a/server/test/clickhouse_test.lua +++ b/server/test/clickhouse_test.lua @@ -10,14 +10,14 @@ local MAIN_DBID = environ.number("QUANTA_DB_MAIN_ID") timer_mgr:once(2000, function() local code, res_oe = ck_mgr:query(MAIN_DBID, MAIN_DBID, "drop table if exists test_ck") - log_debug("db drop table code: %s, err = %s", code, res_oe) + log_debug("db drop table code: {}, err = {}", code, res_oe) code, res_oe = ck_mgr:query(MAIN_DBID, MAIN_DBID, "create table if not exists test_ck (id int, pid int, value int, primary key (id)) ENGINE = MergeTree") - log_debug("db create table code: %s, err = %s", code, res_oe) + log_debug("db create table code: {}, err = {}", code, res_oe) code, res_oe = ck_mgr:query(MAIN_DBID, MAIN_DBID, "select count(*) as count from test_ck where pid=123456") - log_debug("db select code: %s, count = %s", code, res_oe) + log_debug("db select code: {}, count = {}", code, res_oe) code, res_oe = ck_mgr:query(MAIN_DBID, MAIN_DBID, "insert into test_ck (id, pid, value) values (1, 123456, 40)") - log_debug("db insert code: %s, count = %s", code, res_oe) + log_debug("db insert code: {}, count = {}", code, res_oe) code, res_oe = ck_mgr:query(MAIN_DBID, MAIN_DBID, "select * from test_ck where pid = 123456") - log_debug("db select code: %s, res_oe = %s", code, res_oe) + log_debug("db select code: {}, res_oe = {}", code, res_oe) end) diff --git a/server/test/cmdline_test.lua b/server/test/cmdline_test.lua index 87e29dcf..b940f6f2 100644 --- a/server/test/cmdline_test.lua +++ b/server/test/cmdline_test.lua @@ -33,7 +33,7 @@ for _, command in pairs(commands) do for i, value in ipairs(result.args) do local atype = type(value) local name = result.info[i] - log_debug("parse command %s args->(%s, %s[%s])", command.name, name, value, atype) + log_debug("parse command {} args->({}, {}[{}])", command.name, name, value, atype) end end local result2 = cmdline:parser_data(command.data) @@ -41,7 +41,7 @@ for _, command in pairs(commands) do for i, value in ipairs(result2.args) do local atype = type(value) local name = result2.info[i] - log_debug("parse data %s args->(%s, %s[%s])", command.name, name, value, atype) + log_debug("parse data {} args->({}, {}[{}])", command.name, name, value, atype) end end end diff --git a/server/test/codec_test.lua b/server/test/codec_test.lua index 66708322..3b132a8b 100644 --- a/server/test/codec_test.lua +++ b/server/test/codec_test.lua @@ -30,65 +30,65 @@ codec.ketama_insert("test10", quanta.id + 9) local map = codec.ketama_map() local qmap = qtable.mapsort(map) for _, value in pairs(qmap) do - log_debug("ketama_map: %s, %s", value[1], value[2]) + log_debug("ketama_map: {}, {}", value[1], value[2]) end -log_debug("ketama_insert number: %s", qtable.size(map)) +log_debug("ketama_insert number: {}", qtable.size(map)) ]] --hash ---------------------------------------------------------------- local hash_n1 = hash_code(12345) local hash_n2 = hash_code(123346456545464, 1000) -log_debug("hash_code number: %s, %s", hash_n1, hash_n2) +log_debug("hash_code number: {}, {}", hash_n1, hash_n2) local hash_s1 = hash_code("12345") local hash_s2 = hash_code("a0b0c0d0a0b0c0d0", 1000) -log_debug("hash_code string: %s, %s", hash_s1, hash_s2) +log_debug("hash_code string: {}, {}", hash_s1, hash_s2) local fnv_s1 = fnv_32("") local fnv_s2 = fnv_32("12345", fnv_s1) local fnv_s3 = fnv_32("12345", fnv_s2) -log_debug("fnv_32 string: %s, %s, %s", fnv_s1, fnv_s2, fnv_s3) +log_debug("fnv_32 string: {}, {}, {}", fnv_s1, fnv_s2, fnv_s3) local fnv_as1 = fnv_32a("12345") local fnv_as2 = fnv_32a("12345", fnv_as1) local fnv_as3 = fnv_32a("12345", fnv_as2) -log_debug("fnv_32a string: %s, %s, %s", fnv_as1, fnv_as2, fnv_as3) +log_debug("fnv_32a string: {}, {}, {}", fnv_as1, fnv_as2, fnv_as3) --fnv_32 string: 2930711257, 991336454, 3269464323 --fnv_32a string: 3601286043, 177295730, 3384461241 local jmpv = jumphash("", 3) -log_debug("jumphash value: %s", jmpv) +log_debug("jumphash value: {}", jmpv) --guid ---------------------------------------------------------------- local guid = codec.guid_new(5, 512) local sguid = codec.guid_tostring(guid) -log_debug("newguid-> guid: %s, n2s: %s", guid, sguid) +log_debug("newguid-> guid: {}, n2s: {}", guid, sguid) local nguid = codec.guid_number(sguid) local s2guid = codec.guid_tostring(nguid) -log_debug("convert-> guid: %s, n2s: %s", nguid, s2guid) +log_debug("convert-> guid: {}, n2s: {}", nguid, s2guid) local eguid = codec.guid_encode(9223372036854775807) local eguid1 = codec.guid_encode(0x7fffffffffffffff) -log_debug("encode-> eguid: %s", eguid) -log_debug("encode-> eguid: %s", eguid1) +log_debug("encode-> eguid: {}", eguid) +log_debug("encode-> eguid: {}", eguid1) local dguid = codec.guid_decode(eguid) local dguid1 = codec.guid_decode(eguid1) -log_debug("encode-> dguid: %s", dguid) -log_debug("encode-> dguid: %s", dguid1) +log_debug("encode-> dguid: {}", dguid) +log_debug("encode-> dguid: {}", dguid1) local nsguid = codec.guid_string(5, 512) -log_debug("newguid: %s", nsguid) +log_debug("newguid: {}", nsguid) local group = codec.guid_group(nsguid) local index = codec.guid_index(guid) local time = codec.guid_time(guid) -log_debug("ssource-> group: %s, index: %s, time:%s", group, index, time) +log_debug("ssource-> group: {}, index: {}, time:{}", group, index, time) local group2, index2, time2 = codec.guid_source(guid) -log_debug("nsource-> group: %s, index: %s, time:%s", group2, index2, time2) +log_debug("nsource-> group: {}, index: {}, time:{}", group2, index2, time2) -log_debug("crc8: %s", crc8("123214345345345")) -log_debug("crc8: %s", crc8("dfsdfsdfsdfgsdg")) -log_debug("crc8: %s", crc8("2213weerwbdfgd")) -log_debug("crc8: %s", crc8("++dsfsdf++gbdfgdfg")) +log_debug("crc8: {}", crc8("123214345345345")) +log_debug("crc8: {}", crc8("dfsdfsdfsdfgsdg")) +log_debug("crc8: {}", crc8("2213weerwbdfgd")) +log_debug("crc8: {}", crc8("++dsfsdf++gbdfgdfg")) --serialize ---------------------------------------------------------------- @@ -103,23 +103,23 @@ local t = { g = m, } local ss = serialize(t) -log_debug("serialize-> aaa: %s", ss) +log_debug("serialize-> aaa: {}", ss) local tt = unserialize(ss) for k, v in pairs(tt) do - log_debug("unserialize k=%s, v=%s", k, v) + log_debug("unserialize k={}, v={}", k, v) end --encode local e = {a = 1, c = {ab = 2}} local bufe = encode(e) -log_debug("encode-> bufe: %d, %s", #bufe, lhex_encode(bufe)) +log_debug("encode-> bufe: {}, {}", #bufe, lhex_encode(bufe)) local datae = decode(bufe, #bufe) -log_debug("decode-> %s", datae) +log_debug("decode-> {}", datae) local ip = luabus.dns("mtae-global-test-outer-zone-a-2-89e65514de3445cc.elb.us-east-1.amazonaws.com") -log_debug("luabus dns-> %s", ip) +log_debug("luabus dns-> {}", ip) --dump -log_dump("dump-> a: %s", t) +log_dump("dump-> a: {}", t) diff --git a/server/test/crypt_test.lua b/server/test/crypt_test.lua index c9bec11d..745c6122 100644 --- a/server/test/crypt_test.lua +++ b/server/test/crypt_test.lua @@ -25,40 +25,40 @@ local lhmac_sha512 = crypt.hmac_sha512 local ran = lrandomkey() local nonce = lb64encode(ran) local dnonce = lb64decode(nonce) -log_info("b64encode-> ran: %s, nonce: %s, dnonce:%s", lhex_encode(ran), lhex_encode(nonce), lhex_encode(dnonce)) +log_info("b64encode-> ran: {}, nonce: {}, dnonce:{}", lhex_encode(ran), lhex_encode(nonce), lhex_encode(dnonce)) --sha local value = "123456779" local sha1 = lhex_encode(lsha1(value)) -log_info("sha1: %s", sha1) +log_info("sha1: {}", sha1) local sha224 = lhex_encode(lsha224(value)) -log_info("sha224: %s", sha224) +log_info("sha224: {}", sha224) local sha256 = lhex_encode(lsha256(value)) -log_info("sha256: %s", sha256) +log_info("sha256: {}", sha256) local sha384 = lhex_encode(lsha384(value)) -log_info("sha384: %s", sha384) +log_info("sha384: {}", sha384) local sha512 = lhex_encode(lsha512(value)) -log_info("sha512: %s", sha512) +log_info("sha512: {}", sha512) --md5 local omd5 = lmd5(value) local nmd5 = lmd5(value, 1) local hmd5 = lhex_encode(omd5) -log_info("md5: %s", nmd5) -log_info("omd5: %s, hmd5: %s", omd5, hmd5) +log_info("md5: {}", nmd5) +log_info("omd5: {}, hmd5: {}", omd5, hmd5) --hmac_sha local key = "1235456" local hmac_sha1 = lhex_encode(lhmac_sha1(key, value)) -log_info("hmac_sha1: %s", hmac_sha1) +log_info("hmac_sha1: {}", hmac_sha1) local hmac_sha224 = lhex_encode(lhmac_sha224(key, value)) -log_info("hmac_sha224: %s", hmac_sha224) +log_info("hmac_sha224: {}", hmac_sha224) local hmac_sha256 = lhex_encode(lhmac_sha256(key, value)) -log_info("hmac_sha256: %s", hmac_sha256) +log_info("hmac_sha256: {}", hmac_sha256) local hmac_sha384 = lhex_encode(lhmac_sha384(key, value)) -log_info("hmac_sha384: %s", hmac_sha384) +log_info("hmac_sha384: {}", hmac_sha384) local hmac_sha512 = lhex_encode(lhmac_sha512(key, value)) -log_info("hmac_sha512: %s", hmac_sha512) +log_info("hmac_sha512: {}", hmac_sha512) --rsa local pem_pub = [[ @@ -85,20 +85,20 @@ RfSHi27F/Ew6pENe4AwY2sfEV2TXrwEdrvfjNWFSPw== ]] local pub_pem_b64 = lb64decode(string.gsub(pem_pub, "\n", "") ) -log_info("pub_pem_b64: %s", lhex_encode(pub_pem_b64)) +log_info("pub_pem_b64: {}", lhex_encode(pub_pem_b64)) local pri_pem_b64 = lb64decode(string.gsub(pem_pri, "\n", "") ) -log_info("pri_pem_b64: %s", lhex_encode(pri_pem_b64)) +log_info("pri_pem_b64: {}", lhex_encode(pri_pem_b64)) local code1 = rsa_init_pkey(pub_pem_b64) local code2 = rsa_init_skey(pri_pem_b64) -log_info("rsa_init: %s, %s", code1, code2) +log_info("rsa_init: {}, {}", code1, code2) local rsav1 = crypt.rsa_pencode("xiyoo0812") -log_info("rsa_pencode: %s, %s", #rsav1, lhex_encode(rsav1)) +log_info("rsa_pencode: {}, {}", #rsav1, lhex_encode(rsav1)) local rsav2 = crypt.rsa_sdecode(rsav1) -log_info("rsa_sdecode: %s", rsav2) +log_info("rsa_sdecode: {}", rsav2) local rsav3 = crypt.rsa_sencode("xiyoo0812") -log_info("rsa_sencode: %s, %s", #rsav3, lhex_encode(rsav3)) +log_info("rsa_sencode: {}, {}", #rsav3, lhex_encode(rsav3)) local rsav4 = crypt.rsa_pdecode(rsav3) -log_info("rsa_pdecode: %s", rsav4) +log_info("rsa_pdecode: {}", rsav4) diff --git a/server/test/detour_test.lua b/server/test/detour_test.lua index 99790665..5d8c61e7 100644 --- a/server/test/detour_test.lua +++ b/server/test/detour_test.lua @@ -17,7 +17,7 @@ if not mesh then end local tiles = mesh.get_max_tiles() -log_debug("load navmesh success, tiles : %s!", tiles) +log_debug("load navmesh success, tiles : {}!", tiles) local query = mesh.create_query(64, 1) if not query then log_err("create navmesh query failed!") @@ -29,17 +29,17 @@ for i = 1, 33000 do local x1, y1, z1 = query.random_point() local x2, y2, z2 = query.random_point() if (not query.point_valid(x1, y1, z1)) then - log_err('point (%s, %s, %s) is not valid', x1, y1, z1) + log_err('point ({}, {}, {}) is not valid', x1, y1, z1) end query.find_path(x1, y1, z1, x2, y2, z2) end local t2 = timer.time() -log_debug("find_path : %s!", t2 - t1) +log_debug("find_path : {}!", t2 - t1) local pos_x, pos_y, pos_z = query.random_point() --- log_debug('pos: %s', { x = pos_x, y = pos_y, z = pos_z, }) +-- log_debug('pos: {}', { x = pos_x, y = pos_y, z = pos_z, }) local rnd_x, rnd_y, rnd_z = query.around_point(pos_x, pos_y, pos_z, 30) --- log_debug('rnd: %s', { x = rnd_x, y = rnd_y, z = rnd_z, }) +-- log_debug('rnd: {}', { x = rnd_x, y = rnd_y, z = rnd_z, }) if (not query.point_valid(rnd_x, rnd_y, rnd_z)) then - log_err('point (%s, %s, %s) is not valid', rnd_x, rnd_y, rnd_z) + log_err('point ({}, {}, {}) is not valid', rnd_x, rnd_y, rnd_z) end diff --git a/server/test/http_test.lua b/server/test/http_test.lua index 9dbad731..7eda90df 100644 --- a/server/test/http_test.lua +++ b/server/test/http_test.lua @@ -10,19 +10,19 @@ local data = {aaa = 123} if quanta.index == 1 then local on_post = function(path, body, params) - log_debug("on_post: %s, %s, %s", path, body, params) + log_debug("on_post: {}, {}, {}", path, body, params) return data end local on_get = function(path, params) - log_debug("on_get: %s, %s", path, params) + log_debug("on_get: {}, {}", path, params) return data end local on_put = function(path, body, params) - log_debug("on_put: %s, %s, %s", path, body, params) + log_debug("on_put: {}, {}, {}", path, body, params) return data end local on_del = function(path, params) - log_debug("on_del: %s, %s", path, params) + log_debug("on_del: {}, {}", path, params) return data end local HttpServer = import("network/http_server.lua") @@ -37,27 +37,27 @@ elseif quanta.index == 2 then local tk1 = ltime() thread_mgr:fork(function() local tk2 = ltime() - log_debug("node_status1 : %s, %s, %s", tk2 - tk1, tk2, tk1) + log_debug("node_status1 : {}, {}, {}", tk2 - tk1, tk2, tk1) local ok, status, res = http_client:call_post("http://127.0.0.1:8888/node_status1", data) - log_debug("node_status1 : %s, %s, %s, %s", ltime() - tk2, ok, status, res) + log_debug("node_status1 : {}, {}, {}, {}", ltime() - tk2, ok, status, res) end) thread_mgr:fork(function() local tk2 = ltime() - log_debug("node_status2 : %s, %s, %s", tk2 - tk1, tk2, tk1) + log_debug("node_status2 : {}, {}, {}", tk2 - tk1, tk2, tk1) local ok, status, res = http_client:call_get("http://127.0.0.1:8888/node_status2", data) - log_debug("node_status2 : %s, %s, %s, %s", ltime() - tk2, ok, status, res) + log_debug("node_status2 : {}, {}, {}, {}", ltime() - tk2, ok, status, res) end) thread_mgr:fork(function() local tk2 = ltime() - log_debug("node_status3 : %s, %s, %s", tk2 - tk1, tk2, tk1) + log_debug("node_status3 : {}, {}, {}", tk2 - tk1, tk2, tk1) local ok, status, res = http_client:call_put("http://127.0.0.1:8888/node_status3", data) - log_debug("node_status3 : %s, %s, %s, %s", ltime() - tk2, ok, status, res) + log_debug("node_status3 : {}, {}, {}, {}", ltime() - tk2, ok, status, res) end) thread_mgr:fork(function() local tk2 = ltime() - log_debug("node_status4 : %s, %s, %s", tk2 - tk1, tk2, tk1) + log_debug("node_status4 : {}, {}, {}", tk2 - tk1, tk2, tk1) local ok, status, res = http_client:call_del("http://127.0.0.1:8888/node_status4", data) - log_debug("node_status4 : %s, %s, %s, %s", ltime() - tk2, ok, status, res) + log_debug("node_status4 : {}, {}, {}, {}", ltime() - tk2, ok, status, res) end) end end diff --git a/server/test/influx_test.lua b/server/test/influx_test.lua index 4c545594..5a146086 100644 --- a/server/test/influx_test.lua +++ b/server/test/influx_test.lua @@ -15,17 +15,17 @@ local influx = Influx(ip, port, org, bucket, token) timer_mgr:once(2000, function() local _, orgs = influx:find_org() - log_debug("find_org: %s", orgs) + log_debug("find_org: {}", orgs) local _, bucket1 = influx:create_bucket("testdb") - log_debug("create_bucket: %s", bucket1) + log_debug("create_bucket: {}", bucket1) local _, bucket2 = influx:find_bucket("testdb") - log_debug("find_bucket: %s", bucket2) + log_debug("find_bucket: {}", bucket2) local res = influx:delete_bucket_by_id(bucket2.id) - log_debug("delete_bucket_by_id: %s", res) + log_debug("delete_bucket_by_id: {}", res) local _, bucket3 = influx:create_bucket("testdb") - log_debug("create_bucket: %s", bucket3) + log_debug("create_bucket: {}", bucket3) local ok1, wres = influx:write("test_tab", {type = 3}, {id = 5, name = "3333", exp = 666}) - log_debug("write: ok1: %s, res:%s", ok1, wres) + log_debug("write: ok1: {}, res:{}", ok1, wres) local ok2, qres = influx:query([[from(bucket: "testdb") |> range(start: -12h) |> filter(fn: (r) => r["_measurement"] == "test_tab") @@ -33,5 +33,5 @@ timer_mgr:once(2000, function() |> filter(fn: (r) => r["type"] == "3") |> aggregateWindow(every: 1h, fn: mean, createEmpty: false) |> yield(name: "mean")]]) - log_debug("query: ok2: %s, res:%s", ok2, qres) + log_debug("query: ok2: {}, res:{}", ok2, qres) end) diff --git a/server/test/json_test.lua b/server/test/json_test.lua index 1d444dd2..3c03f436 100644 --- a/server/test/json_test.lua +++ b/server/test/json_test.lua @@ -45,43 +45,43 @@ local vv = { detail = protobuf_mgr:encode_byname("ncmd_cs.login_account_login_res", value) } -log_debug("%s, %s", #vv.detail, vv.detail) +log_debug("{}, {}", #vv.detail, vv.detail) local c = jpretty(vv) -log_debug("json_encode: %s", c) +log_debug("json_encode: {}", c) local d = jdecode(c) -log_debug("json_decode: %s", d) +log_debug("json_decode: {}", d) local dd = protobuf_mgr:decode_byname("ncmd_cs.login_account_login_res", d.detail) -log_debug("decode_byname: %s", dd) +log_debug("decode_byname: {}", dd) local a = jencode(test, 1) -log_debug("json_encode: %s", a) +log_debug("json_encode: {}", a) local b = jdecode(a, 1) log_debug(type(b.tid), b.tid) log_debug(type(b.player_id), b.player_id) -log_debug("json_decode: %s", b) +log_debug("json_decode: {}", b) -log_debug("%s", b.c) -log_debug("%s, %s", type(b.tid), b.tid) -log_debug("%s, %s", type(b.player_id), b.player_id) +log_debug("{}", b.c) +log_debug("{}, {}", type(b.tid), b.tid) +log_debug("{}, {}", type(b.player_id), b.player_id) for k, v in pairs(b.c) do - log_debug("c %s, %s", type(k), k) - log_debug("c %s, %s", type(v), v) + log_debug("c {}, {}", type(k), k) + log_debug("c {}, {}", type(v), v) end local x1 = jencode(test) -log_debug("tt1:%s%s", x1, #x1) +log_debug("tt1:{}", x1, #x1) local aaa = lencode(test) local bbb = ldecode(aaa) -log_debug("tt22:%s%s", bbb, #aaa) +log_debug("tt22:{}", bbb, #aaa) local aaa1 = bencode(test) local bbb1 = bdecode(aaa1) -log_debug("tt23:%s%s", bbb1, #aaa1) +log_debug("tt23:{}", bbb1, #aaa1) local tt1 = ltime() for i = 1, 100000 do @@ -112,7 +112,7 @@ local tt7 = ltime() for i = 1, 100000 do local x = bdecode(aaa1) if i == 10000 then - log_debug("tt24:%s", x) + log_debug("tt24:{}", x) end end local tt8 = ltime() @@ -121,5 +121,5 @@ for i = 1, 100000 do end local tt9 = ltime() -log_debug("tt1:%s, tt2:%s, tt3:%s, tt4:%s", tt2 - tt1, tt3 - tt2, tt4 - tt3, tt5 - tt4) -log_debug("tt5:%s, tt6:%s, tt7:%s, tt8:%s", tt6 - tt5, tt7 - tt6, tt8 - tt7, tt9 - tt8) +log_debug("tt1:{}, tt2:{}, tt3:{}, tt4:{}", tt2 - tt1, tt3 - tt2, tt4 - tt3, tt5 - tt4) +log_debug("tt5:{}, tt6:{}, tt7:{}, tt8:{}", tt6 - tt5, tt7 - tt6, tt8 - tt7, tt9 - tt8) diff --git a/server/test/lock_test.lua b/server/test/lock_test.lua index 2b073ab8..8ab4083a 100644 --- a/server/test/lock_test.lua +++ b/server/test/lock_test.lua @@ -7,30 +7,30 @@ local thread_mgr = quanta.get("thread_mgr") local function test_a(index) local _ = thread_mgr:lock("sync_lock_test", true) thread_mgr:sleep(10) - log_debug("test_a:%s", index) + log_debug("test_a:{}", index) end local function test_b(index) local _ = thread_mgr:lock("sync_lock_test", true) thread_mgr:sleep(10) test_a(index) - log_debug("test_b:%s", index) + log_debug("test_b:{}", index) end local function test_c(index) local _ = thread_mgr:lock("sync_lock_test", true) thread_mgr:sleep(10) test_b(index) - log_debug("test_c:%s", index) + log_debug("test_c:{}", index) end local function test_loop_lock(index) - log_debug("lock:%s", index) + log_debug("lock:{}", index) local _ = thread_mgr:lock("test_loop", true) if 1 == index then thread_mgr:sleep(10) end - log_debug("unlock:%s", index) + log_debug("unlock:{}", index) end local function test1() diff --git a/server/test/log_test.lua b/server/test/log_test.lua index 721eba79..eea8b477 100644 --- a/server/test/log_test.lua +++ b/server/test/log_test.lua @@ -8,22 +8,22 @@ local log_dump = logfeature.dump("bilogs", "./bilogs/", true) local function logger_test(cycle) local t1 = lnow_ms() for i = 1, cycle do - log_info("logger_test : now output logger cycle : %d", i) + log_info("logger_test : now output logger cycle : {}", i) end local t2 = lnow_ms() return t2 - t1 end -local params = { 1, 2, } +local params = { 100000 } for _, cycle in ipairs(params) do local time = logger_test(cycle) - log_debug(string.format("logger_test: cycle %d use time %s ms!", cycle, time)) + log_debug("logger_test: cycle {} use time {} ms!", cycle, time) end -local params2 = { 1, 2, } +local params2 = { 100000 } for _, cycle in ipairs(params2) do local time = logger_test(cycle) - log_dump(string.format("logger_test: cycle %d use time %s ms!", cycle, time)) + log_dump("logger_test: cycle {} use time {} ms!", cycle, time) end log_info("logger test end") diff --git a/server/test/mongo_test.lua b/server/test/mongo_test.lua index 9991225d..20fcd273 100644 --- a/server/test/mongo_test.lua +++ b/server/test/mongo_test.lua @@ -12,36 +12,36 @@ local MAIN_DBID = environ.number("QUANTA_DB_MAIN_ID") timer_mgr:once(2000, function() local code, count = mongo_mgr:count(MAIN_DBID, "test_mongo_1", {pid = 123456}) - log_debug("db count code: %s, count = %s", code, count) + log_debug("db count code: {}, count = {}", code, count) local icode, ierr = mongo_mgr:insert(MAIN_DBID, primary_id, "test_mongo_1", {pid = 123456, data = {a =1, b=2}}) - log_debug("db insert code: %s, err = %s", icode, ierr) + log_debug("db insert code: {}, err = {}", icode, ierr) icode, ierr = mongo_mgr:insert(MAIN_DBID, primary_id, "test_mongo_1", {pid = 123457, data = {a =1, b=2}}) - log_debug("db insert code: %s, err = %s", icode, ierr) + log_debug("db insert code: {}, err = {}", icode, ierr) local fcode, res = mongo_mgr:find(MAIN_DBID, primary_id, "test_mongo_1", {}, {_id = 0}) - log_debug("db find code: %s, res = %s", fcode, res) + log_debug("db find code: {}, res = {}", fcode, res) local f1code, f1res = mongo_mgr:find_one(MAIN_DBID, primary_id, "test_mongo_1", {pid = 123456}, {_id = 0}) - log_debug("db find code: %s, res = %s", f1code, f1res) + log_debug("db find code: {}, res = {}", f1code, f1res) local ucode, uerr = mongo_mgr:update(MAIN_DBID, primary_id, "test_mongo_1", {pid = 123458, data = {a =1, b=4}}, {pid = 123457}) - log_debug("db update code: %s, err = %s", ucode, uerr) + log_debug("db update code: {}, err = {}", ucode, uerr) code, count = mongo_mgr:count(MAIN_DBID, "test_mongo_1", {pid = 123456}) - log_debug("db count code: %s, count = %s", code, count) + log_debug("db count code: {}, count = {}", code, count) local ecode, eres = mongo_mgr:delete(MAIN_DBID, primary_id, "test_mongo_1", {pid = 123456}) - log_debug("db delete code: %s, count = %s", ecode, eres) + log_debug("db delete code: {}, count = {}", ecode, eres) code, count = mongo_mgr:count(MAIN_DBID, "test_mongo_1", {pid = 123456}) - log_debug("db count code: %s, count = %s", code, count) + log_debug("db count code: {}, count = {}", code, count) icode, ierr = mongo_mgr:create_indexes(MAIN_DBID, "test_mongo_2", {{key={userid=1},name="test_uid", unique = true}}) - log_debug("db create_indexes code: %s, err = %s", icode, ierr) + log_debug("db create_indexes code: {}, err = {}", icode, ierr) icode, ierr = mongo_mgr:execute(MAIN_DBID, primary_id, "listIndexes", "test_mongo_2") - log_debug("db listIndexes code: %s, err = %s", icode, ierr) + log_debug("db listIndexes code: {}, err = {}", icode, ierr) icode, ierr = mongo_mgr:drop_indexes(MAIN_DBID, "test_mongo_2", "test_uid") - log_debug("db drop_indexes code: %s, err = %s", icode, ierr) + log_debug("db drop_indexes code: {}, err = {}", icode, ierr) --[[ fcode, res = mongo_mgr:find(MAIN_DBID, "test_mongo_1", {}, {_id = 0}, {pid = 1}) for _, v in pairs(res) do - log_debug("db find sort code: %s, v = %s", fcode, v) + log_debug("db find sort code: {}, v = {}", fcode, v) end local acode, id = mongo_mgr:get_autoinc_id(MAIN_DBID, "splayer") - log_debug("db autoinc code: %s, id = %s", acode, id) + log_debug("db autoinc code: {}, id = {}", acode, id) ]] end) diff --git a/server/test/mysql_test.lua b/server/test/mysql_test.lua index 51cdcee4..bb4e387b 100644 --- a/server/test/mysql_test.lua +++ b/server/test/mysql_test.lua @@ -11,27 +11,27 @@ local MAIN_DBID = environ.number("QUANTA_DB_MAIN_ID") timer_mgr:once(3000, function() log_debug("mysql db start test!") local code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "drop table test_mysql") - log_debug("db drop table code: %s, res = %s", code, res_oe) + log_debug("db drop table code: {}, res = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "create table if not exists test_mysql (id int auto_increment, pid int, value int, primary key (id))") - log_debug("db create table code: %s, res = %s", code, res_oe) + log_debug("db create table code: {}, res = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "insert into test_mysql (pid, value) values (123457, 40)") - log_debug("db insert code: %s, res_oe = %s", code, res_oe) + log_debug("db insert code: {}, res_oe = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "insert into test_mysql (pid, value) values (123456, 40)") - log_debug("db insert code: %s, res_oe = %s", code, res_oe) + log_debug("db insert code: {}, res_oe = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "select count(*) as count from test_mysql where pid=123457") - log_debug("db select code: %s, count = %s", code, res_oe) + log_debug("db select code: {}, count = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "select * from test_mysql where pid = 123456") - log_debug("db select code: %s, res_oe = %s", code, res_oe) + log_debug("db select code: {}, res_oe = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "update test_mysql set pid = 123454, value = 20 where pid = 123456 limit 1") - log_debug("db update code: %s, err = %s", code, res_oe) + log_debug("db update code: {}, err = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "select * from test_mysql") - log_debug("db select code: %s, res_oe = %s", code, res_oe) + log_debug("db select code: {}, res_oe = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "delete from test_mysql where pid = 123457") - log_debug("db delete code: %s, err = %s", code, res_oe) + log_debug("db delete code: {}, err = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "replace into test_mysql (id, pid, value) values (1, 123457, 40)") - log_debug("db replace code: %s, count = %s", code, res_oe) + log_debug("db replace code: {}, count = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "select * from test_mysql") - log_debug("db select code: %s, res_oe = %s", code, res_oe) + log_debug("db select code: {}, res_oe = {}", code, res_oe) code, res_oe = mysql_mgr:query(MAIN_DBID, MAIN_DBID, "select count(*) as count from test_mysql where pid=123454") - log_debug("db count code: %s, count = %s", code, res_oe) + log_debug("db count code: {}, count = {}", code, res_oe) end) \ No newline at end of file diff --git a/server/test/nacos_test.lua b/server/test/nacos_test.lua index 075167c9..a89a1066 100644 --- a/server/test/nacos_test.lua +++ b/server/test/nacos_test.lua @@ -11,55 +11,55 @@ local thread_mgr = quanta.get("thread_mgr") thread_mgr:fork(function() local cres = nacos:create_namespace("1234567", "quanta", "test create_namespace") - log_debug("create_namespace: %s", cres) + log_debug("create_namespace: {}", cres) local nss = nacos:query_namespaces() - log_debug("query_namespaces: %s", nss) + log_debug("query_namespaces: {}", nss) --[[ local mres = nacos:modify_namespace("1234567", "quanta", "test create_namespace2") - log_debug("modify_namespace: %s", mres) + log_debug("modify_namespace: {}", mres) local nss3 = nacos:query_namespaces() - log_debug("query_namespaces3: %s", nss3) + log_debug("query_namespaces3: {}", nss3) local dres = nacos:del_namespace("1234567") - log_debug("del_namespace: %s", dres) + log_debug("del_namespace: {}", dres) local nss4 = nacos:query_namespaces() - log_debug("query_namespaces4: %s", nss4) + log_debug("query_namespaces4: {}", nss4) ]] local value = lhex_encode(lrandomkey()) local pfres = nacos:modify_config("test2", value) - log_debug("modify_config: test-> %s, success-> %s", value, pfres) + log_debug("modify_config: test-> {}, success-> {}", value, pfres) local cfres = nacos:get_config("test2") - log_debug("get_config: test-> %s", cfres) + log_debug("get_config: test-> {}", cfres) local dfres = nacos:del_config("test2") - log_debug("del_config: test-> %s", dfres) + log_debug("del_config: test-> {}", dfres) local sres = nacos:create_service("lobby", "quanta") - log_debug("create_service: lobby-> %s", sres) + log_debug("create_service: lobby-> {}", sres) local sres2 = nacos:create_service("lobby2", "quanta") - log_debug("create_service: lobby2-> %s", sres2) + log_debug("create_service: lobby2-> {}", sres2) local mres = nacos:modify_service("lobby2", "quanta") - log_debug("modify_service: lobby-> %s", mres) + log_debug("modify_service: lobby-> {}", mres) local qres = nacos:query_service("lobby", "quanta") - log_debug("query_service: lobby-> %s", qres) + log_debug("query_service: lobby-> {}", qres) local qlres = nacos:query_services(1, 20, "quanta") - log_debug("query_services: quanta-> %s", qlres) + log_debug("query_services: quanta-> {}", qlres) local dres = nacos:del_service("lobby2", "quanta") - log_debug("del_service: quanta-> %s", dres) + log_debug("del_service: quanta-> {}", dres) local rres = nacos:regi_instance("lobby2", quanta.host, 1, "quanta") - log_debug("regi_instance: lobby2-> %s", rres) + log_debug("regi_instance: lobby2-> {}", rres) local ilres = nacos:query_instances("lobby2", "quanta") - log_debug("query_instances: lobby2-> %s", ilres) + log_debug("query_instances: lobby2-> {}", ilres) local ires = nacos:query_instance("lobby2", quanta.host, 1, "quanta") - log_debug("query_instance: lobby2-> %s", ires) + log_debug("query_instance: lobby2-> {}", ires) local dires = nacos:del_instance("lobby2", quanta.host, 1, "quanta") - log_debug("del_instance: lobby2-> %s", dires) + log_debug("del_instance: lobby2-> {}", dires) nacos:listen_config("test", nil, nil, function(data_id, group, md5, cvalue) - log_debug("listen_config: test-> %s", cvalue) + log_debug("listen_config: test-> {}", cvalue) end) end) @@ -67,11 +67,11 @@ timer_mgr:loop(3000, function() --[[ local value = lhex_encode(lrandomkey()) local pfres = nacos:modify_config("test", value) - log_debug("modify_config: test-> %s, success-> %s", value, pfres) + log_debug("modify_config: test-> {}, success-> {}", value, pfres) ]] local ilres = nacos:query_instances("lobby2", "quanta") - log_debug("query_instances: lobby2-> %s", ilres) + log_debug("query_instances: lobby2-> {}", ilres) --local bres = nacos:sent_beat("lobby2", 2, "quanta") - --log_debug("sent_beat: lobby-> %s", bres) + --log_debug("sent_beat: lobby-> {}", bres) end) diff --git a/server/test/pack_test.lua b/server/test/pack_test.lua index aba7b5bb..c4ea9981 100644 --- a/server/test/pack_test.lua +++ b/server/test/pack_test.lua @@ -23,7 +23,7 @@ function PackTest:on_service_ready(quanta_id) args[#args + 1] = ss end local _, send_len = router.socket.call_target(quanta_id, "test_log", 0, "arg_1", args, "arg_3") - log_info("[PackTest][on_service_ready] send size : %s", send_len) + log_info("[PackTest][on_service_ready] send size : {}", send_len) end end diff --git a/server/test/protobuf_test.lua b/server/test/protobuf_test.lua index 068c8bfe..fa9a23dc 100644 --- a/server/test/protobuf_test.lua +++ b/server/test/protobuf_test.lua @@ -13,12 +13,12 @@ local pb_str1 = protobuf_mgr:encode("NID_HEARTBEAT_REQ", pb_data) local data1 = protobuf_mgr:decode("NID_HEARTBEAT_REQ", pb_str1) local pb_str2 = protobuf_mgr:encode(NCmdId.NID_HEARTBEAT_REQ, pb_data) local data2 = protobuf_mgr:decode(NCmdId.NID_HEARTBEAT_REQ, pb_str2) -log_debug("name test1:%s", data1) -log_debug("name test2:%s", data2) +log_debug("name test1:{}", data1) +log_debug("name test2:{}", data2) local ppb_data = {master=1001014162,elems={[107216333761938434]={proto_id=0}},part_sync=true} local ppb_str = protobuf_mgr:encode_byname("ncmd_cs.building_building_ntf", ppb_data) local pdata = protobuf_mgr:decode_byname("ncmd_cs.building_building_ntf", ppb_str) -log_debug("pb test:%s", #ppb_str) -log_debug("pb test:%s", pdata) +log_debug("pb test:{}", #ppb_str) +log_debug("pb test:{}", pdata) diff --git a/server/test/redis_cluster.lua b/server/test/redis_cluster.lua index 5b0eb750..aff3ca5f 100644 --- a/server/test/redis_cluster.lua +++ b/server/test/redis_cluster.lua @@ -10,13 +10,13 @@ local MAIN_DBID = environ.number("QUANTA_DB_MAIN_ID") timer_mgr:once(2000, function() local code, res = redis_mgr:execute(MAIN_DBID, "cluster", "nodes") - log_debug("db get code: %s, res(%s) = %s", code, type(res), res) + log_debug("db get code: {}, res({}) = {}", code, type(res), res) code, res = redis_mgr:execute(MAIN_DBID, "cluster", "slots") - log_debug("db get code: %s, res(%s) = %s", code, type(res), res) + log_debug("db get code: {}, res({}) = {}", code, type(res), res) code, res = redis_mgr:execute(MAIN_DBID, "set", "aaa", {abc = 3, ddd = 4}) - log_debug("db set code: %s, res = %s", code, res) + log_debug("db set code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "get", "aaa") - log_debug("db get code: %s, res = %s", code, res) + log_debug("db get code: {}, res = {}", code, res) local code1, res1, res2 = redis_mgr:execute(MAIN_DBID, "scan", "0") - log_debug("db scan code: %s, res = %s, res2=%s", code1, res1, res2) + log_debug("db scan code: {}, res = {}, res2={}", code1, res1, res2) end) \ No newline at end of file diff --git a/server/test/redis_test.lua b/server/test/redis_test.lua index 8c55de03..5f277d86 100644 --- a/server/test/redis_test.lua +++ b/server/test/redis_test.lua @@ -10,71 +10,71 @@ local MAIN_DBID = environ.number("QUANTA_DB_MAIN_ID") timer_mgr:once(2000, function() local code, res = redis_mgr:execute(MAIN_DBID, "get", "aaa") - log_debug("db get code: %s, res = %s", code, res) + log_debug("db get code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "set", "aaa", {abc = 3, ddd = 4}) - log_debug("db set code: %s, res = %s", code, res) + log_debug("db set code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "get", "aaa") - log_debug("db get code: %s, res = %s", code, res) + log_debug("db get code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "get", "aaa") - log_debug("db get code: %s, res = %s", code, res) + log_debug("db get code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "hget", "bb", "k1") - log_debug("db hget code: %s, res = %s", code, res) + log_debug("db hget code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "hset", "bb", "k1", 123) - log_debug("db hset code: %s, res = %s", code, res) + log_debug("db hset code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "hmset", "bb", "k2", 234, "k3", 345) - log_debug("db hmset code: %s, res = %s", code, res) + log_debug("db hmset code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "hget", "bb", "k1") - log_debug("db hget code: %s, res = %s", code, res) + log_debug("db hget code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "hdel", "bb", "k1") - log_debug("db hdel code: %s, res = %s", code, res) + log_debug("db hdel code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "hmget", "bb", "k1", "k2", "k3") - log_debug("db hget code: %s, res = %s", code, res) + log_debug("db hget code: {}, res = {}", code, res) local scode, cur, vals = redis_mgr:execute(MAIN_DBID, "hscan", "bb", 0) - log_debug("db hscan code: %s, cur = %s, vals=%s", scode, cur, vals) + log_debug("db hscan code: {}, cur = {}, vals={}", scode, cur, vals) code, res = redis_mgr:execute(MAIN_DBID, "sadd", "sset", "k1", "k2", "k3") - log_debug("db sadd code: %s, res = %s", code, res) + log_debug("db sadd code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "scard", "sset") - log_debug("db scard code: %s, res = %s", code, res) + log_debug("db scard code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "sismember", "sset", "one") - log_debug("db sismember code: %s, res = %s", code, res) + log_debug("db sismember code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "sismember", "sset", "k2") - log_debug("db sismember code: %s, res = %s", code, res) + log_debug("db sismember code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "smembers", "sset") - log_debug("db smembers code: %s, res = %s", code, res) + log_debug("db smembers code: {}, res = {}", code, res) scode, cur, vals = redis_mgr:execute(MAIN_DBID, "sscan", "sset", 0) - log_debug("db sscan code: %s, cur = %s, vals=%s", scode, cur, vals) + log_debug("db sscan code: {}, cur = {}, vals={}", scode, cur, vals) code, res = redis_mgr:execute(MAIN_DBID, "spop", "sset") - log_debug("db spop code: %s, res = %s", code, res) + log_debug("db spop code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zadd", "zset1",1,"one") - log_debug("db zadd code: %s, res = %s", code, res) + log_debug("db zadd code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zadd", "zset1",1,"uno") - log_debug("db zadd code: %s, res = %s", code, res) + log_debug("db zadd code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zadd", "zset1",2,"two") - log_debug("db zadd code: %s, res = %s", code, res) + log_debug("db zadd code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zadd", "zset1",3,"three") - log_debug("db zadd code: %s, res = %s", code, res) + log_debug("db zadd code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zcard", "zset1") - log_debug("db zcard code: %s, res = %s", code, res) + log_debug("db zcard code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zcount", "zset1",1,2) - log_debug("db zcount code: %s, res = %s", code, res) + log_debug("db zcount code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zrange", "zset1",0,2) - log_debug("db zrange code: %s, res = %s", code, res) + log_debug("db zrange code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zrank", "zset1","two") - log_debug("db zrank code: %s, res = %s", code, res) + log_debug("db zrank code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zscore", "zset1","two") - log_debug("db zscore code: %s, res = %s", code, res) + log_debug("db zscore code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zrange", "zset1", 0, 2, "WITHSCORES") - log_debug("db zrange withscores code: %s, res = %s", code, res) + log_debug("db zrange withscores code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "zrangebyscore", "zset1", 0, 2) - log_debug("db zrange zrangebyscore code: %s, res = %s", code, res) + log_debug("db zrange zrangebyscore code: {}, res = {}", code, res) scode, cur, vals = redis_mgr:execute(MAIN_DBID, "zscan", "zset1", 0) - log_debug("db zscan code: %s, cur = %s, vals=%s", scode, cur, vals) + log_debug("db zscan code: {}, cur = {}, vals={}", scode, cur, vals) --[[ --code, res = redis_mgr:execute(MAIN_DBID, "subscribe", "test") - --log_debug("db subscribe code: %s, res = %s", code, res) + --log_debug("db subscribe code: {}, res = {}", code, res) code, res = redis_mgr:execute(MAIN_DBID, "publish", "test", 123) - log_debug("db publish code: %s, res = %s", code, res) - log_debug("db spop code: %s, res = %s", code, res) + log_debug("db publish code: {}, res = {}", code, res) + log_debug("db spop code: {}, res = {}", code, res) ]] end) \ No newline at end of file diff --git a/server/test/router_test.lua b/server/test/router_test.lua index 9a00918d..24bd1d2b 100644 --- a/server/test/router_test.lua +++ b/server/test/router_test.lua @@ -11,16 +11,16 @@ function RouterTest:__init() timer_mgr:once(4000, function() local ok, code, res = router_mgr:call_mongo_random("rpc_mongo_find", "default", "test_mongo_1", {}, {_id = 0}) - log_debug("db find ok:%s, code: %s, res = %s", ok, code, res) + log_debug("db find ok:{}, code: {}, res = {}", ok, code, res) end) end function RouterTest:on_service_ready(quanta_id) - log_debug("on_service_ready quanta_id :%s", quanta_id) + log_debug("on_service_ready quanta_id :{}", quanta_id) end function RouterTest:on_service_close(quanta_id) - log_debug("on_service_close quanta_id :%s", quanta_id) + log_debug("on_service_close quanta_id :{}", quanta_id) end quanta.router_test = RouterTest() diff --git a/server/test/rpc_test.lua b/server/test/rpc_test.lua index eee7319c..44ef1b70 100644 --- a/server/test/rpc_test.lua +++ b/server/test/rpc_test.lua @@ -25,16 +25,16 @@ function RpcTest:setup() for n = 1, 200 do local ok, rn, rdata = router_mgr:call_target(quanta.id, "on_echo", n, data) if ok then - log_debug("%s res: %s", rn, #rdata) + log_debug("{} res: {}", rn, #rdata) else - log_debug("%s err: %s", n, rn) + log_debug("{} err: {}", n, rn) end end end) end function RpcTest:on_echo(n, data) - log_debug("%s req: %s", n, #data) + log_debug("{} req: {}", n, #data) return n, data end diff --git a/server/test/stdfs_test.lua b/server/test/stdfs_test.lua index 1fb53722..c46f7092 100644 --- a/server/test/stdfs_test.lua +++ b/server/test/stdfs_test.lua @@ -4,87 +4,87 @@ local log_info = logger.info local work_dir = stdfs.current_path() local ltype = stdfs.filetype(work_dir) -log_info("current_path: %s, type: %s", work_dir, ltype) +log_info("current_path: {}, type: {}", work_dir, ltype) local root_name = stdfs.root_name(work_dir) local root_path = stdfs.root_path(work_dir) -log_info("root_name: %s, root_path: %s", root_name, root_path) +log_info("root_name: {}, root_path: {}", root_name, root_path) local parent_path = stdfs.parent_path(work_dir) local relative_path = stdfs.relative_path(work_dir) -log_info("parent_path: %s, relative_path: %s", parent_path, relative_path) +log_info("parent_path: {}, relative_path: {}", parent_path, relative_path) local cur_dirs = stdfs.dir(work_dir) for _, file in pairs(cur_dirs) do - log_info("cur dir -> filename: %s, filetype: %s", file.name, file.type) + log_info("cur dir -> filename: {}, filetype: {}", file.name, file.type) end local recursive_dirs = stdfs.dir(work_dir, true) for _, file in pairs(recursive_dirs) do - log_info("recursive dir -> filename: %s, filetype: %s", file.name, file.type) + log_info("recursive dir -> filename: {}, filetype: {}", file.name, file.type) end local mok, merr = stdfs.mkdir("logs/a/b/c") -log_info("mkdir -> ok: %s, err: %s", mok, merr) +log_info("mkdir -> ok: {}, err: {}", mok, merr) local cok, cerr = stdfs.chdir("logs") local new_dir = stdfs.current_path() local is_dir = stdfs.is_directory(new_dir) -log_info("chdir -> ok: %s, err: %s", cok, cerr) -log_info("chdir -> new_dir: %s, is_dir: %s", new_dir, is_dir) +log_info("chdir -> ok: {}, err: {}", cok, cerr) +log_info("chdir -> new_dir: {}, is_dir: {}", new_dir, is_dir) local absolute1 = stdfs.is_absolute(new_dir) local absolute2 = stdfs.is_absolute(relative_path) -log_info("is_absolute -> absolute1: %s, absolute:%s", absolute1, absolute2) +log_info("is_absolute -> absolute1: {}, absolute:{}", absolute1, absolute2) local exista = stdfs.exists("a") local existb = stdfs.exists("b") local temp_dir = stdfs.temp_dir() -log_info("exists -> exista: %s, existb: %s, temp_dir:%s", exista, existb, temp_dir) +log_info("exists -> exista: {}, existb: {}, temp_dir:{}", exista, existb, temp_dir) local splits = stdfs.split(new_dir) for _, node in pairs(splits) do - log_info("split dir -> node: %s", node) + log_info("split dir -> node: {}", node) end local rok, rerr = stdfs.remove("c") -log_info("remove1 -> rok: %s, rerr: %s", rok, rerr) +log_info("remove1 -> rok: {}, rerr: {}", rok, rerr) local nok, nerr = stdfs.rename("a", "b") -log_info("rename -> nok:%s, nerr:%s", nok, nerr) +log_info("rename -> nok:{}, nerr:{}", nok, nerr) local rbok, rberr = stdfs.remove("b") local raok, raerr = stdfs.remove("b", true) -log_info("remove2 -> rbok: %s, rberr: %s, raok:%s, raerr:%s", rbok, rberr, raok, raerr) +log_info("remove2 -> rbok: {}, rberr: {}, raok:{}, raerr:{}", rbok, rberr, raok, raerr) local cfok, cferr = stdfs.copy_file("test/test-2-20210820-235824.123.p11456.log", "test-2-20210820-235824.123.p11456.log") local cfok2, cferr2 = stdfs.copy_file("test/test-2-20210821-000053.361.p7624.log", "../") -log_info("copy_file -> cfok:%s, cferr:%s, cfok2:%s, cferr2:%s", cfok, cferr, cfok2, cferr2) +log_info("copy_file -> cfok:{}, cferr:{}, cfok2:{}, cferr2:{}", cfok, cferr, cfok2, cferr2) local cok1, cerr1 = stdfs.copy("test", "test2") local cok2, cerr2 = stdfs.remove("test2", true) -log_info("copy_file -> cok:%s, cerr:%s, cok2:%s, cerr2:%s", cok1, cerr1, cok2, cerr2) +log_info("copy_file -> cok:{}, cerr:{}, cok2:{}, cerr2:{}", cok1, cerr1, cok2, cerr2) local n2ok, n2err = stdfs.rename("test-2-20210820-235824.123.p11456.log", "tttt.log") -log_info("rename2 -> n2ok:%s, n2err:%s", n2ok, n2err) +log_info("rename2 -> n2ok:{}, n2err:{}", n2ok, n2err) local absolute = stdfs.absolute("tttt.log") local filename = stdfs.filename(absolute) local extension = stdfs.extension(absolute) local stem = stdfs.stem(absolute) -log_info("info -> absolute:%s, extension:%s, filename:%s, stem:%s", absolute, extension, filename, stem) +log_info("info -> absolute:{}, extension:{}, filename:{}, stem:{}", absolute, extension, filename, stem) local afile = stdfs.append(absolute, "d.log") local apath = stdfs.append(absolute, "dc") local afpath = stdfs.append(afile, "ff") local concat = stdfs.concat("apath", "ff.png") -log_info("append -> afile: %s, apath: %s, afpath: %s, concat: %s", afile, apath, afpath, concat) +log_info("append -> afile: {}, apath: {}, afpath: {}, concat: {}", afile, apath, afpath, concat) local time, terr = stdfs.last_write_time(absolute) local extension2 = stdfs.replace_extension(absolute, "log2") local filename2 = stdfs.replace_filename(absolute, "ffff.log") local newname = stdfs.remove_filename(absolute) -log_info("info -> time:%s, terr:%s, extension2:%s, filename2:%s, newname:%s", time, terr, extension2, filename2, newname) +log_info("info -> time:{}, terr:{}, extension2:{}, filename2:{}, newname:{}", time, terr, extension2, filename2, newname) local rfok, rferr = stdfs.remove("tttt.log") -log_info("remove3 -> rfok: %s, rferr: %s", rfok, rferr) +log_info("remove3 -> rfok: {}, rferr: {}", rfok, rferr) diff --git a/server/test/tcp_test.lua b/server/test/tcp_test.lua index 2db1ceb0..182a101a 100644 --- a/server/test/tcp_test.lua +++ b/server/test/tcp_test.lua @@ -7,7 +7,7 @@ local thread_mgr = quanta.get("thread_mgr") if quanta.index == 1 then local tcp = luabus.tcp() local ok, err = tcp.listen("127.0.0.1", 8700) - log_debug("tcp-svr listen: %s, err: %s", ok, err) + log_debug("tcp-svr listen: {}, err: {}", ok, err) thread_mgr:fork(function() local index = 0 local client = nil @@ -22,12 +22,12 @@ if quanta.index == 1 then local ok2, buf = client.recv() if ok2 then index = index + 1 - log_debug("tcp-svr recv: %s", buf) - local buff = string.format("server send %s", index) + log_debug("tcp-svr recv: {}", buf) + local buff = string.format("server send {}", index) client.send(buff, #buff) else if buf ~= "timeout" then - log_debug("tcp-svr failed: %s", buf) + log_debug("tcp-svr failed: {}", buf) client = nil end end @@ -48,18 +48,18 @@ elseif quanta.index == 2 then client.send(cdata, #cdata) log_debug("tcp-cli connect success!") else - log_debug("tcp-cli connect failed: %s!", err) + log_debug("tcp-cli connect failed: {}!", err) end else local ok, buf = client.recv() if ok then index = index + 1 - log_debug("tcp-cli recv: %s", buf) - local buff = string.format("client send %s", index) + log_debug("tcp-cli recv: {}", buf) + local buff = string.format("client send {}", index) client.send(buff, #buff) else if buf ~= "timeout" then - log_debug("tcp-cli failed: %s", buf) + log_debug("tcp-cli failed: {}", buf) client = nil end end diff --git a/server/test/timer_test.lua b/server/test/timer_test.lua index 2df4944e..ecffd526 100644 --- a/server/test/timer_test.lua +++ b/server/test/timer_test.lua @@ -4,15 +4,15 @@ local log_info = logger.info local Timer = import("feature/timer.lua") local msec, sec = timer.time() -log_info("time: sec:%s, msec:%s", sec, msec) +log_info("time: sec:{}, msec:{}", sec, msec) --timer:sleep(2000) local now = timer.now() local now_ms = timer.now_ms() -log_info("time: now:%s, now_ms:%s", now, now_ms) +log_info("time: now:{}, now_ms:{}", now, now_ms) local clock = timer.clock() local clock_ms = timer.clock_ms() -log_info("time: clock:%s, clock_ms:%s", clock, clock_ms) +log_info("time: clock:{}, clock_ms:{}", clock, clock_ms) local timer_mgr = quanta.get("timer_mgr") local thread_mgr = quanta.get("thread_mgr") @@ -20,31 +20,31 @@ local thread_mgr = quanta.get("thread_mgr") thread_mgr:fork(function() log_info("once") timer_mgr:once(500, function(escape_ms) - log_info("once: %s", escape_ms) + log_info("once: {}", escape_ms) end, 3) log_info("loop") timer_mgr:loop(1000, function(escape_ms) - log_info("loop: %s", escape_ms) + log_info("loop: {}", escape_ms) end) log_info("register") timer_mgr:register(500, 1000, 5, function(escape_ms) - log_info("register: %s", escape_ms) + log_info("register: {}", escape_ms) end) local ttimer1 = Timer() ttimer1:once(1000, function(escape_ms) - log_info("ttimer once=====: %s", escape_ms) + log_info("ttimer once=====: {}", escape_ms) end) local ttimer2 = Timer() ttimer2:loop(1000, function(escape_ms) - log_info("ttimer loop=====: %s", escape_ms) + log_info("ttimer loop=====: {}", escape_ms) end) local time = 1 local ttimer3 = Timer() ttimer3:register(500, 1000, 5, function() - log_info("ttimer register===: %s", time) + log_info("ttimer register===: {}", time) time = time + 1 if time == 5 then quanta.ttimer2 = nil diff --git a/server/test/udp_test.lua b/server/test/udp_test.lua index 7136f94e..92062ef2 100644 --- a/server/test/udp_test.lua +++ b/server/test/udp_test.lua @@ -7,19 +7,19 @@ local thread_mgr = quanta.get("thread_mgr") if quanta.index == 1 then local udp = luabus.udp() local ok, err = udp.listen("127.0.0.1", 8600) - log_debug("udp-svr listen: %s, err: %s", ok, err) + log_debug("udp-svr listen: {}, err: {}", ok, err) thread_mgr:fork(function() local index = 0 while true do local ok2, buf, ip, port = udp.recv() if ok2 then index = index + 1 - log_debug("udp-svr recv: %s from %s:%s", buf, ip, port) - local buff = string.format("server send %s", index) + log_debug("udp-svr recv: {} from {}:{}", buf, ip, port) + local buff = string.format("server send {}", index) udp.send(buff, #buff, ip, port) else if buf ~= "EWOULDBLOCK" then - log_debug("udp-svr recv failed: %s", buf) + log_debug("udp-svr recv failed: {}", buf) end end thread_mgr:sleep(1000) @@ -35,12 +35,12 @@ elseif quanta.index == 2 then local ok, buf, ip, port = udp.recv() if ok then index = index + 1 - log_debug("udp-cli recv: %s from %s:%s", buf, ip, port) - local buff = string.format("client send %s", index) + log_debug("udp-cli recv: {} from {}:{}", buf, ip, port) + local buff = string.format("client send {}", index) udp.send(buff, #buff, ip, port) else if buf ~= "EWOULDBLOCK" then - log_debug("udp-cli recv failed: %s", buf) + log_debug("udp-cli recv failed: {}", buf) end end thread_mgr:sleep(1000) diff --git a/server/test/worker_test.lua b/server/test/worker_test.lua index 75fd9be7..6b1952d7 100644 --- a/server/test/worker_test.lua +++ b/server/test/worker_test.lua @@ -17,7 +17,7 @@ function MaterTest:__init() end function MaterTest:test_master_rpc(a, b, c, d) - log_debug("[MaterTest][test_master_rpc] %s, %s, %s, %s", a, b, c, d) + log_debug("[MaterTest][test_master_rpc] {}, {}, {}, {}", a, b, c, d) return a + b, c + d end @@ -26,8 +26,8 @@ quanta.master_test = MaterTest() timer_mgr:loop(2000, function() local ok, res1, res2 = scheduler:call("wtest", "test_worker_rpc", 1, 2, 3, 4) if not ok then - log_err("[scheduler][call] test_worker_rpc failed: %s", res1) + log_err("[scheduler][call] test_worker_rpc failed: {}", res1) return end - log_debug("[scheduler][call] test_worker_rpc success: %s, %s", res1, res2) + log_debug("[scheduler][call] test_worker_rpc success: {}, {}", res1, res2) end) diff --git a/server/worker/proxy.lua b/server/worker/proxy.lua deleted file mode 100644 index 177463b7..00000000 --- a/server/worker/proxy.lua +++ /dev/null @@ -1,8 +0,0 @@ ---proxy.lua -import("feature/worker.lua") - ---启动worker -quanta.startup(function() - import("worker/proxy/proxy_mgr.lua") - import("worker/proxy/statis_mgr.lua") -end) diff --git a/server/worker/proxy/proxy_mgr.lua b/server/worker/proxy/proxy_mgr.lua deleted file mode 100644 index fbea6913..00000000 --- a/server/worker/proxy/proxy_mgr.lua +++ /dev/null @@ -1,48 +0,0 @@ ---proxy_mgr.lua -import("driver/webhook.lua") -import("driver/graylog.lua") -import("network/http_client.lua") - -local webhook = quanta.get("webhook") -local event_mgr = quanta.get("event_mgr") -local http_client = quanta.get("http_client") - -local ProxyMgr = singleton() - -function ProxyMgr:__init() - -- 注册事件 - event_mgr:add_listener(self, "rpc_fire_webhook") - -- 通用http请求 - event_mgr:add_listener(self, "rpc_http_post") - event_mgr:add_listener(self, "rpc_http_get") - event_mgr:add_listener(self, "rpc_http_put") - event_mgr:add_listener(self, "rpc_http_del") -end - ---日志上报 -function ProxyMgr:rpc_fire_webhook(title, content) - webhook:notify(title, content) -end - ---通用http请求 -function ProxyMgr:rpc_http_get(url, querys, headers) - local ok, status, res = http_client:call_get(url, querys, headers) - return ok and status or 404, res -end - -function ProxyMgr:rpc_http_post(url, post_data, headers, querys) - local ok, status, res = http_client:call_post(url, post_data, headers, querys) - return ok and status or 404, res -end - -function ProxyMgr:rpc_http_put(url, put_data, headers, querys) - local ok, status, res = http_client:call_put(url, put_data, headers, querys) - return ok and status or 404, res -end - -function ProxyMgr:rpc_http_del(url, querys, headers) - local ok, status, res = http_client:call_del(url, querys, headers) - return ok and status or 404, res -end - -quanta.proxy_mgr = ProxyMgr() diff --git a/server/worker/proxy/statis_mgr.lua b/server/worker/proxy/statis_mgr.lua deleted file mode 100644 index b063d67e..00000000 --- a/server/worker/proxy/statis_mgr.lua +++ /dev/null @@ -1,121 +0,0 @@ ---statis_mgr.lua -import("feature/worker.lua") -import("feature/linux.lua") - -local json_encode = json.encode - -local log_path = environ.get("QUANTA_STATIS_PATH") -local log_dump = logfeature.dump("statis", log_path, true) - -local event_mgr = quanta.get("event_mgr") -local update_mgr = quanta.get("update_mgr") -local linux_statis = quanta.get("linux_statis") - -local StatisMgr = singleton() -local prop = property(StatisMgr) -prop:reader("statis_datas", {}) -prop:reader("statis_enable", false) --统计开关 - -function StatisMgr:__init() - local statis_enable = environ.status("QUANTA_STATIS") - if statis_enable then - self.statis_enable = statis_enable - --定时处理 - update_mgr:attach_second5(self) - --系统监控 - if quanta.platform == "linux" then - linux_statis:setup() - end - end - --事件监听 - event_mgr:add_listener(self, "on_rpc_send") - event_mgr:add_listener(self, "on_rpc_recv") - event_mgr:add_listener(self, "on_perfeval") - event_mgr:add_listener(self, "on_proto_recv") - event_mgr:add_listener(self, "on_proto_send") - event_mgr:add_listener(self, "on_conn_update") -end - ---输出到日志 -function StatisMgr:flush() - for _, measure in pairs(self.statis_datas) do - log_dump(json_encode(measure)) - end - self.statis_datas = {} -end - -function StatisMgr:write_log(name, type, add_count) - if self.statis_enable then - self.statis_datas[#self.statis_datas + 1] = { - name = name, - type = type, - value = add_count, - index = quanta.index, - service = quanta.service, - ser_name = quanta.service_name, - } - end -end - --- 统计proto协议发送(KB) -function StatisMgr:on_proto_recv(cmd_id, send_len) - self:write_log(cmd_id, "proto_recv", send_len) -end - --- 统计proto协议接收(KB) -function StatisMgr:on_proto_send(cmd_id, recv_len) - self:write_log( cmd_id, "proto_send", recv_len) -end - --- 统计rpc协议发送(KB) -function StatisMgr:on_rpc_send(rpc, send_len) - self:write_log(rpc, "rpc_send", send_len) -end - --- 统计rpc协议接收(KB) -function StatisMgr:on_rpc_recv(rpc, recv_len) - self:write_log( rpc, "rpc_recv", recv_len) -end - --- 统计cmd协议连接 -function StatisMgr:on_conn_update(conn_type, conn_count) - self:write_log( conn_type, "conn", conn_count) -end - --- 统计性能 -function StatisMgr:on_perfeval(eval_data, clock_ms) - self:write_log(eval_data.eval_name, "perfeval", eval_data.yield_time) -end - --- 统计系统信息 -function StatisMgr:on_second5() - self:write_log("all_mem","system", self:_calc_mem_use()) - self:write_log("lua_mem","system", self:_calc_lua_mem()) - self:write_log("cpu_rate","system", self:_calc_cpu_rate()) - self:flush() -end - --- 计算lua内存信息(KB) -function StatisMgr:_calc_lua_mem() - return collectgarbage("count") -end - --- 计算内存信息(KB) -function StatisMgr:_calc_mem_use() - if quanta.platform == "linux" then - return linux_statis:calc_memory() - end - return 5000 -end - --- 计算cpu使用率 -function StatisMgr:_calc_cpu_rate() - if quanta.platform == "linux" then - return linux_statis:calc_cpu_rate() - end - return 0.1 -end - -quanta.statis_mgr = StatisMgr() - -return StatisMgr diff --git a/server/worker/wtest.lua b/server/worker/wtest.lua index 7c7cc510..f47fa4ff 100644 --- a/server/worker/wtest.lua +++ b/server/worker/wtest.lua @@ -13,7 +13,7 @@ function WorkerTest:__init() end function WorkerTest:test_worker_rpc(a, b, c, d) - log_debug("[WorkerTest][test_worker_rpc] %s, %s, %s, %s", a, b, c, d) + log_debug("[WorkerTest][test_worker_rpc] {}, {}, {}, {}", a, b, c, d) return a + b, c + d end @@ -23,9 +23,9 @@ quanta.startup(function() timer_mgr:loop(2000, function() local ok, res1, res2 = quanta.call_master("test_master_rpc", 1, 2, 3, 4) if not ok then - log_err("[worker][call_master] test_master_rpc failed: %s", res1) + log_err("[worker][call_master] test_master_rpc failed: {}", res1) return end - log_debug("[worker][call_master] test_master_rpc success: %s, %s", res1, res2) + log_debug("[worker][call_master] test_master_rpc success: {}, {}", res1, res2) end) end) diff --git a/tools/accord.bat b/tools/accord.bat deleted file mode 100644 index b18e8b63..00000000 --- a/tools/accord.bat +++ /dev/null @@ -1,12 +0,0 @@ -@echo off - -chcp 65001 - -:: 解析xlsm文件为lua - -set LUA_PATH=!/../tools/accord/?.lua;!/../script/?.lua;; - -..\bin\quanta.exe --entry=accord --proto=../bin/proto/ --input=./accord/ --output=../server/robot/accord/ - -pause - diff --git a/tools/accord/accord.lua b/tools/accord/accord.lua deleted file mode 100644 index e7085acd..00000000 --- a/tools/accord/accord.lua +++ /dev/null @@ -1,145 +0,0 @@ ---accord.lua -local ldir = stdfs.dir -local lstem = stdfs.stem -local lmkdir = stdfs.mkdir -local lappend = stdfs.append -local lfilename = stdfs.filename -local lextension = stdfs.extension -local lcurdir = stdfs.current_path -local serialize = luakit.serialize -local pb_enum_id = protobuf.enum -local json_encode = json.encode -local tunpack = table.unpack -local sformat = string.format -local supper = string.upper -local ogetenv = os.getenv - -local pb_indexs = {} - -local function ssplit(str, token) - local t = {} - while #str > 0 do - local pos = str:find(token) - if not pos then - t[#t + 1] = str - break - end - if pos > 1 then - t[#t + 1] = str:sub(1, pos - 1) - end - str = str:sub(pos + 1, #str) - end - return t -end - -local function sends_with(str, ending) - return str:sub(-#ending) == ending -end - -local function parse_message(full_name, proto_name) - local proto_isreq = sends_with(proto_name, "_req") - if proto_isreq then - local package_name = tunpack(ssplit(full_name, "%.")) - print("[accord][parse_message] full_name(%s) proto_name(%s) package_name(%s)", full_name, proto_name, ssplit(full_name, ".")) - local enum_type = package_name .. ".NCmdId" - local msg_name = "NID_" .. supper(proto_name) - local msg_id = pb_enum_id(enum_type, msg_name) - if msg_id then - local fields = {} - for name, _, typ in protobuf.fields(full_name) do - fields[name] = (typ == "string") and "xxx" or 0 - end - pb_indexs[msg_name] = { - msg_id = msg_id, - name = msg_name, - fields = fields, - } - end - end - return pb_indexs -end - ---加载pb文件 -local function load_pbfiles(proto_dir, proto_file) - local full_name = lappend(proto_dir, proto_file) - --加载PB文件 - protobuf.loadfile(full_name) - --注册CMDID和PB的映射 - for name, basename, typ in protobuf.types() do - if typ == "message" then - parse_message(name, basename) - end - end -end - ---加载pb文件 -local function load_protocol(proto_path) - local dir_files = ldir(proto_path) - for _, file in pairs(dir_files) do - if lextension(file.name) == ".pb" then - load_pbfiles(proto_path, lfilename(file.name)) - end - end -end - ---加载case文件 -local function load_cases(tool_dir, case_dir) - local tcases = {} - local case_path = lappend(tool_dir, case_dir) - local dir_files = ldir(case_path) - for _, file in pairs(dir_files or {}) do - if lextension(file.name) == ".lua" then - local name = lstem(file.name) - tcases[name] = require(sformat("%s.%s", case_dir, name)) - end - end - return tcases -end - -local function export_json(input, output) - local configs = {} - configs.accord = pb_indexs - configs.servers = require("server") - configs.cases = load_cases(input, "cases") - --export - local jdata = json_encode(configs) - local ldata = serialize(configs) - local jsonname = lappend(input, "accord_conf.json") - local json_file = io.open(jsonname, "w") - json_file:write(jdata) - json_file:close() - local confname = lappend(output, "accord_conf.lua") - local conf_file = io.open(confname, "w") - conf_file:write("--luacheck: ignore 631\n") - conf_file:write(sformat("return {\n lua = %s,\n json = [[%s]]\n}\n", ldata, jdata)) - conf_file:close() - print("export accord config success!") -end - -local proto = lcurdir() -local input = lcurdir() -local output = lcurdir() -local env_proto = ogetenv("QUANTA_PROTO") -if not env_proto or #env_proto == 0 then - print("proto dir not config!") -else - proto = lappend(proto, env_proto) -end -local env_input = ogetenv("QUANTA_INPUT") -if not env_input or #env_input == 0 then - print("input dir not config!") -else - input = lappend(input, env_input) -end -local env_output = ogetenv("QUANTA_OUTPUT") -if not env_output or #env_output == 0 then - print("output dir not config!") -else - output = lappend(output, env_output) - lmkdir(output) -end - -load_protocol(proto) -export_json(input, output) - -os.exit() diff --git a/tools/accord/accord_conf.json b/tools/accord/accord_conf.json deleted file mode 100644 index 175f322b..00000000 --- a/tools/accord/accord_conf.json +++ /dev/null @@ -1 +0,0 @@ -{"servers":["127.0.0.1:20013"],"cases":{"login":{"protocols":[{"id":10009,"name":"NID_LOGIN_ROLE_CHOOSE_REQ","args":{"role_id":0,"user_id":0}},{"id":10011,"name":"NID_LOGIN_ROLE_DELETE_REQ","args":{"role_id":0,"user_id":0}}],"name":"login","openid":"test001","password":"123456","server":"127.0.0.1:20013"}},"accord":{"NID_LOGIN_ROLE_LOGOUT_REQ":{"msg_id":10015,"name":"NID_LOGIN_ROLE_LOGOUT_REQ","fields":{"role_id":0}},"NID_LOGIN_ROLE_RELOAD_REQ":{"msg_id":10017,"name":"NID_LOGIN_ROLE_RELOAD_REQ","fields":{"role_id":0,"token":0,"lobby":0,"user_id":0}},"NID_HEARTBEAT_REQ":{"msg_id":1001,"name":"NID_HEARTBEAT_REQ","fields":{"time":0,"serial":0}},"NID_LOGIN_RANDOM_NAME_REQ":{"msg_id":10005,"name":"NID_LOGIN_RANDOM_NAME_REQ","fields":{}},"NID_LOGIN_ACCOUNT_RELOAD_REQ":{"msg_id":10003,"name":"NID_LOGIN_ACCOUNT_RELOAD_REQ","fields":{"openid":"xxx","account_token":0}},"NID_LOGIN_ROLE_CHOOSE_REQ":{"msg_id":10009,"name":"NID_LOGIN_ROLE_CHOOSE_REQ","fields":{"role_id":0,"user_id":0}},"NID_LOGIN_ROLE_CREATE_REQ":{"msg_id":10007,"name":"NID_LOGIN_ROLE_CREATE_REQ","fields":{"model":0,"gender":0,"name":"xxx","user_id":0}},"NID_LOGIN_ACCOUNT_LOGIN_REQ":{"msg_id":10001,"name":"NID_LOGIN_ACCOUNT_LOGIN_REQ","fields":{"platform":0,"openid":"xxx","session":"xxx"}},"NID_LOGIN_ROLE_LOGIN_REQ":{"msg_id":10013,"name":"NID_LOGIN_ROLE_LOGIN_REQ","fields":{"role_id":0,"token":0,"lobby":0,"user_id":0}},"NID_LOGIN_ROLE_DELETE_REQ":{"msg_id":10011,"name":"NID_LOGIN_ROLE_DELETE_REQ","fields":{"role_id":0,"user_id":0}}}} \ No newline at end of file diff --git a/tools/accord/cases/login.lua b/tools/accord/cases/login.lua deleted file mode 100644 index d716dc9e..00000000 --- a/tools/accord/cases/login.lua +++ /dev/null @@ -1,20 +0,0 @@ ---login.lua - -return { - name = "login", - openid = "test001", - password = "123456", - server = "127.0.0.1:20013", - protocols = { - { - id = 10009, - name = "NID_LOGIN_ROLE_CHOOSE_REQ", - args = { user_id = 0, role_id = 0 } - }, - { - id = 10011, - name = "NID_LOGIN_ROLE_DELETE_REQ", - args = { user_id = 0, role_id = 0 } - } - } -} \ No newline at end of file diff --git a/tools/accord/server.lua b/tools/accord/server.lua deleted file mode 100644 index 09c77a23..00000000 --- a/tools/accord/server.lua +++ /dev/null @@ -1,5 +0,0 @@ ---server.lua - -return { - "127.0.0.1:20013" -} diff --git a/tools/gmbuild.bat b/tools/gmbuild.bat new file mode 100644 index 00000000..a1169661 --- /dev/null +++ b/tools/gmbuild.bat @@ -0,0 +1,12 @@ +@echo off + +set JS=../server/center/page/gm.js +set CSS=../server/center/page/gm.css +set TPL=../server/center/page/gm.html +set OUT=../server/center/gm_page.lua +set SCRIPT=../extend/lmake/ltemplate.lua + +..\bin\lua.exe %SCRIPT% %TPL% %OUT% GM_CSS %CSS% GM_SCRIPT %JS% + +pause + diff --git a/tools/mongo/index.lua b/tools/mongo/index.lua index ef416f90..19d57e24 100644 --- a/tools/mongo/index.lua +++ b/tools/mongo/index.lua @@ -51,7 +51,7 @@ local function generate_js(input_path, ouput_path) --创建索引,默认升序 idx_file:write(sformat("db.getCollection(\"%s\").createIndex({%s: 1}, {name: \"%s\",unique: true});\n", sheet, key, key)) if key2 then - idx_file:write(sformat("db.getCollection(\"%s\").createIndex({%s: 1}, {name: \"%s\",unique: true});\n", sheet, key2, key2)) + idx_file:write(sformat("db.getCollection(\"%s\").createIndex({%s: 1}, {name: \"%s\",unique: true});\n", sheet, key2, key2)) end idx_file:write("//------------------------------------------------------------------------\n\n") end