Skip to content

Commit

Permalink
优化日志&修复CORE
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyoo0812 committed Sep 25, 2023
1 parent 452352b commit a83de03
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
12 changes: 6 additions & 6 deletions extend/lualog/lualog/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ namespace logger {

// class log_message
// --------------------------------------------------------------------------------
void log_message::option(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line) {
void log_message::option(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line) {
log_time_ = log_time::now();
feature_ = feature;
source_ = source;
feature_ = std::move(feature);
source_ = std::move(source);
msg_ = std::move(msg);
tag_ = std::move(tag);
level_ = level;
line_ = line;
msg_ = msg;
tag_ = tag;
}

// class log_message_pool
Expand Down Expand Up @@ -367,7 +367,7 @@ namespace logger {
}
}

void log_service::output(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line) {
void log_service::output(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line) {
if (!log_filter_.is_filter(level)) {
auto logmsg_ = message_pool_->allocate();
logmsg_->option(level, msg, tag, feature, source, line);
Expand Down
6 changes: 3 additions & 3 deletions extend/lualog/lualog/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace logger {
void set_grow(bool grow) { grow_ = grow; }
log_level level() const { return level_; }
const log_time& get_log_time()const { return log_time_; }
void option(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line);
void option(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line);

private:
int line_ = 0;
Expand Down Expand Up @@ -239,7 +239,7 @@ namespace logger {
virtual bool add_file_dest(vstring feature, vstring fname) = 0;
virtual void set_dest_clean_time(vstring feature, size_t clean_time) = 0;
virtual void option(vstring log_path, vstring service, vstring index) = 0;
virtual void output(log_level level, vstring msg, vstring tag, vstring feature = "", vstring source = "", int line = 0) = 0;
virtual void output(log_level level, cstring& msg, cstring& tag, cstring& feature = "", cstring& source = "", int line = 0) = 0;
};

class log_service : public logger {
Expand Down Expand Up @@ -268,7 +268,7 @@ namespace logger {
bool is_filter(log_level lv) { return log_filter_.is_filter(lv); }
void filter(log_level lv, bool on) { log_filter_.filter(lv, on); }

void output(log_level level, vstring msg, vstring tag, vstring feature, vstring source, int line);
void output(log_level level, cstring& msg, cstring& tag, cstring& feature, cstring& source, int line);

protected:
path build_path(vstring feature, vstring fpath);
Expand Down
15 changes: 8 additions & 7 deletions extend/lualog/lualog/lualog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ namespace logger {
return "unsuppert data type";
}

int zformat(lua_State* L, log_level lvl, vstring tag, vstring feature, vstring msg) {
get_logger()->output(lvl, msg, tag, feature);
int zformat(lua_State* L, log_level lvl, cstring& tag, cstring& feature, cstring& msg) {
if (lvl == log_level::LOG_LEVEL_FATAL) {
lua_pushlstring(L, msg.data(), msg.size());
lua_pushlstring(L, msg.c_str(), msg.size());
get_logger()->output(lvl, msg, tag, feature);
return 1;
}
get_logger()->output(lvl, msg, tag, feature);
return 0;
}

template<size_t... integers>
int tformat(lua_State* L, log_level lvl, vstring tag, vstring feature, int flag, vstring vfmt, std::index_sequence<integers...>&&) {
int tformat(lua_State* L, log_level lvl, cstring& tag, cstring& feature, int flag, vstring vfmt, std::index_sequence<integers...>&&) {
try {
auto msg = fmt::format(vfmt, read_args(L, flag, integers + 6)...);
return zformat(L, lvl, tag, feature, msg);
Expand All @@ -68,12 +69,12 @@ namespace logger {
log_level lvl = (log_level)lua_tointeger(L, 1);
if (get_logger()->is_filter(lvl)) return 0;
size_t flag = lua_tointeger(L, 2);
vstring tag = lua_to_native<vstring>(L, 3);
vstring feature = lua_to_native<vstring>(L, 4);
sstring tag = lua_to_native<sstring>(L, 3);
sstring feature = lua_to_native<sstring>(L, 4);
vstring vfmt = lua_to_native<vstring>(L, 5);
int arg_num = lua_gettop(L) - 5;
switch (arg_num) {
case 0: return zformat(L, lvl, tag, feature, vfmt);
case 0: return zformat(L, lvl, tag, feature, string(vfmt.data(), vfmt.size()));
case 1: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<1>{});
case 2: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<2>{});
case 3: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<3>{});
Expand Down
3 changes: 2 additions & 1 deletion extend/luapb/src/luapb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ namespace luapb {
pb_header* header =(pb_header*)m_slice->peek(sizeof(pb_header));
if (!header) return 0;
m_packet_len = header->len;
if (m_packet_len < sizeof(pb_header)) return -1;
if (m_packet_len >= 0xffff) return -1;
if (!m_slice->peek(m_packet_len)) return 0;
if (m_packet_len > 0xffff) return -1;
if (m_packet_len > data_len) return 0;
return m_packet_len;
}
Expand Down

0 comments on commit a83de03

Please sign in to comment.