Skip to content

Commit

Permalink
日志模块优化
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed Sep 21, 2023
1 parent 0dfc001 commit 607064d
Show file tree
Hide file tree
Showing 49 changed files with 401 additions and 401 deletions.
6 changes: 3 additions & 3 deletions server/business/admin/shield.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

-- 删除协议过滤
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions server/business/attr/attribute_agent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions server/business/attr/attribute_relay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions server/business/component/attr_component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/business/component/event_component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/business/component/sub_component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions server/business/entity/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/business/entity/entity_mgr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions server/cache/cache_gm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

Expand Down
36 changes: 18 additions & 18 deletions server/cache/cache_mgr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand All @@ -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 _<close> = 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
Expand Down Expand Up @@ -240,10 +240,10 @@ function CacheMgr:rpc_cache_load(primary_id, coll_name)
local _<close> = 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

Expand All @@ -252,10 +252,10 @@ function CacheMgr:rpc_cache_update_field(primary_id, coll_name, field, field_dat
local _<close> = 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
Expand All @@ -266,11 +266,11 @@ function CacheMgr:rpc_cache_remove_field(primary_id, coll_name, field)
local _<close> = 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

Expand All @@ -280,27 +280,27 @@ function CacheMgr:rpc_cache_delete(primary_id, coll_name)
local _<close> = 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 _<close> = 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
--原表是否为空
Expand All @@ -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
Expand All @@ -333,10 +333,10 @@ function CacheMgr:rpc_cache_signed(primary_id, coll_name)
local _<close> = 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()
Expand Down
Loading

0 comments on commit 607064d

Please sign in to comment.