From 0dfc0019a75fcabd1107bae48884fd386a686396 Mon Sep 17 00:00:00 2001 From: xiyoo0812 Date: Thu, 21 Sep 2023 16:50:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=A8=A1=E5=9D=97=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/agent/cache_agent.lua | 8 +++--- script/agent/gm_agent.lua | 4 +-- script/agent/monitor_agent.lua | 6 ++--- script/basic/cmdline.lua | 16 +++++------ script/basic/library.lua | 3 +-- script/basic/listener.lua | 20 +++++++------- script/driver/graylog.lua | 10 +++---- script/driver/influx.lua | 22 +++++++-------- script/driver/mongo.lua | 12 ++++----- script/driver/mysql.lua | 6 ++--- script/driver/nacos.lua | 48 ++++++++++++++++----------------- script/driver/redis.lua | 10 +++---- script/driver/socket.lua | 10 +++---- script/driver/websocket.lua | 11 ++++---- script/driver/zipkin.lua | 6 ++--- script/feature/config.lua | 10 +++---- script/feature/counter.lua | 4 +-- script/feature/scheduler.lua | 2 +- script/feature/timer.lua | 1 - script/feature/worker.lua | 6 ++--- script/kernel.lua | 2 +- script/kernel/config_mgr.lua | 2 +- script/kernel/event_mgr.lua | 2 +- script/kernel/protobuf_mgr.lua | 8 +++--- script/kernel/router_mgr.lua | 10 +++---- script/kernel/thread_mgr.lua | 8 +++--- script/kernel/update_mgr.lua | 18 ++++++------- script/network/http_client.lua | 4 +-- script/network/http_server.lua | 24 ++++++++--------- script/network/net_client.lua | 4 +-- script/network/net_server.lua | 16 +++++------ script/network/rpc_client.lua | 14 +++++----- script/network/rpc_server.lua | 14 +++++----- script/network/ws_server.lua | 12 ++++----- script/quanta.lua | 8 +++--- script/queue/mongo_mq.lua | 10 +++---- script/queue/redis_mq.lua | 8 +++--- script/store/clickhouse_mgr.lua | 28 +------------------ script/store/game_dao.lua | 22 +++++++-------- script/store/mongo_mgr.lua | 10 +++---- script/store/mysql_mgr.lua | 6 ++--- script/store/redis_mgr.lua | 4 +-- 42 files changed, 210 insertions(+), 239 deletions(-) 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 afccb41f..6251f768 100644 --- a/script/agent/monitor_agent.lua +++ b/script/agent/monitor_agent.lua @@ -76,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) @@ -90,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} @@ -119,7 +119,7 @@ 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 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/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/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..b98a9661 100644 --- a/script/feature/worker.lua +++ b/script/feature/worker.lua @@ -126,15 +126,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..cc7574e1 100644 --- a/script/kernel.lua +++ b/script/kernel.lua @@ -134,6 +134,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/protobuf_mgr.lua b/script/kernel/protobuf_mgr.lua index ae4aa8af..4e731fa5 100644 --- a/script/kernel/protobuf_mgr.lua +++ b/script/kernel/protobuf_mgr.lua @@ -120,7 +120,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 {}) @@ -139,7 +139,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) @@ -152,7 +152,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 @@ -197,7 +197,7 @@ 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 29bc9971..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 ed61e32d..8ae430a8 100644 --- a/script/network/net_client.lua +++ b/script/network/net_client.lua @@ -39,7 +39,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,7 +62,7 @@ function NetClient:connect(block) 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) + 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() diff --git a/script/network/net_server.lua b/script/network/net_server.lua index bf252eeb..097f8298 100644 --- a/script/network/net_server.lua +++ b/script/network/net_server.lua @@ -48,22 +48,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,7 +86,7 @@ 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 @@ -104,7 +104,7 @@ function NetServer:on_socket_accept(session) 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) + 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 +116,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 +162,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) diff --git a/script/network/rpc_client.lua b/script/network/rpc_client.lua index 1f8c284a..60a0bf73 100644 --- a/script/network/rpc_client.lua +++ b/script/network/rpc_client.lua @@ -62,7 +62,7 @@ function RpcClient:on_call_router(rpc, token, 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 +75,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 +121,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 +131,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 @@ -162,7 +162,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 +176,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..82a4cdd1 100644 --- a/script/network/rpc_server.lua +++ b/script/network/rpc_server.lua @@ -35,24 +35,24 @@ 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 @@ -96,14 +96,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) 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 +220,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/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"