ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
nlog.h File Reference

日志路由:将日志条目分发到控制台输出和日志actor。 More...

#include "tools/log/nactor_logitem.h"
#include "tools/tab/xml/sysconfig.h"
#include "tools/tools/tools_time.h"
#include "tools/log/logprintf.h"
#include "tools/tools.h"
#include <source_location>
#include <sstream>
#include <format>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>

Classes

class  ngl::elog_name
 日志级别名称工具类。 More...
struct  std::formatter< std::vector< T > >
struct  std::formatter< std::list< T > >
struct  std::formatter< std::set< T > >
struct  std::formatter< std::map< TKEY, TVAL > >
struct  std::formatter< std::unordered_map< TKEY, TVAL > >
struct  std::formatter< google::protobuf::RepeatedField< T > >

Macros

#define Try   try
 异常处理起始宏。
#define Catch
 异常处理结束宏。
#define mk_formatter(NAME)

Typedefs

using ngl::ptr_logitem = std::shared_ptr<nactor_logitem>
 日志项共享指针类型别名

Functions

ptr_logitem ngl::log_debug (const std::source_location &asource)
 获取DEBUG级别日志项
ptr_logitem ngl::log_debug_net (const std::source_location &asource)
 获取DEBUG级别网络日志项
ptr_logitem ngl::log_info (const std::source_location &asource)
 获取INFO级别日志项
ptr_logitem ngl::log_info_net (const std::source_location &asource)
 获取INFO级别网络日志项
ptr_logitem ngl::log_warn (const std::source_location &asource)
 获取WARN级别日志项
ptr_logitem ngl::log_warn_net (const std::source_location &asource)
 获取WARN级别网络日志项
ptr_logitem ngl::log_error (const std::source_location &asource)
 获取ERROR级别日志项
ptr_logitem ngl::log_error_net (const std::source_location &asource)
 获取ERROR级别网络日志项
ptr_logitem ngl::log_bi (const std::source_location &asource)
 获取BI日志项

Detailed Description

日志路由:将日志条目分发到控制台输出和日志actor。

本文件提供了日志系统的入口点和格式化工具,包括:

  • 不同日志级别的日志函数(debug、info、warn、error)
  • 网络相关的日志函数
  • 业务智能日志函数
  • 异常处理宏
  • 容器类型的std::formatter特化

日志系统支持源代码位置捕获,便于调试和错误追踪。

Macro Definition Documentation

◆ Catch

#define Catch
Value:
catch(const char* errormsg) \
{ \
ngl::log_error()->print("function[{}][{}]", __FUNCTION__, errormsg); \
} \
catch(const std::exception& e) \
{ \
ngl::log_error()->print("function[{}][{}]", __FUNCTION__, e.what()); \
} \
catch(...) \
{ \
ngl::log_error()->print("function[{}]", __FUNCTION__); \
}

异常处理结束宏。

捕获并记录异常信息,包括:

  • const char*类型的异常
  • std::exception类型的异常
  • 所有其他类型的异常

所有异常都会记录到错误日志中,包含函数名称和异常信息。

◆ mk_formatter

#define mk_formatter ( NAME)
Value:
template <> \
struct std::formatter<ngl::data_modified<NAME>> \
{ \
constexpr auto parse(const std::format_parse_context& ctx)const \
{ \
return ctx.begin(); \
} \
auto format(const ngl::data_modified<NAME>& aval, std::format_context& ctx)const\
{ \
std::string ldb; \
MODIFIED_RETURN_CONST(lpdbdataconst, aval, ctx.out()) \
ngl::tools::proto2json(*lpdbdataconst, ldb); \
return std::format_to(ctx.out(), #NAME":<{}>\n", ldb); \
} \
};

◆ Try

#define Try   try

异常处理起始宏。

标记异常处理块的开始,与Catch宏配对使用。

Function Documentation

◆ log_bi()

ptr_logitem ngl::log_bi ( const std::source_location & asource)

获取BI日志项

获取业务智能日志入口点。

Parameters
asource源码位置
Returns
日志项共享指针
Parameters
asource源代码位置,默认为当前调用位置
Returns
日志项共享指针

◆ log_debug()

ptr_logitem ngl::log_debug ( const std::source_location & asource)

获取DEBUG级别日志项

获取调试级别日志入口点。

Parameters
asource源码位置
Returns
日志项共享指针

立即捕获源位置,以便最终的actor端格式化器能打印原始调用位置。

Parameters
asource源代码位置,默认为当前调用位置
Returns
日志项共享指针

◆ log_debug_net()

ptr_logitem ngl::log_debug_net ( const std::source_location & asource)

获取DEBUG级别网络日志项

获取网络调试级别日志入口点。

Parameters
asource源码位置
Returns
日志项共享指针
Parameters
asource源代码位置,默认为当前调用位置
Returns
日志项共享指针

◆ log_error()

ptr_logitem ngl::log_error ( const std::source_location & asource)

获取ERROR级别日志项

获取错误级别日志入口点。

Parameters
asource源码位置
Returns
日志项共享指针
Parameters
asource源代码位置,默认为当前调用位置
Returns
日志项共享指针

◆ log_error_net()

ptr_logitem ngl::log_error_net ( const std::source_location & asource)

获取ERROR级别网络日志项

获取网络错误级别日志入口点。

Parameters
asource源码位置
Returns
日志项共享指针
Parameters
asource源代码位置,默认为当前调用位置
Returns
日志项共享指针

◆ log_info()

ptr_logitem ngl::log_info ( const std::source_location & asource)

获取INFO级别日志项

获取信息级别日志入口点。

Parameters
asource源码位置
Returns
日志项共享指针
Parameters
asource源代码位置,默认为当前调用位置
Returns
日志项共享指针

◆ log_info_net()

ptr_logitem ngl::log_info_net ( const std::source_location & asource)

获取INFO级别网络日志项

获取网络信息级别日志入口点。

Parameters
asource源码位置
Returns
日志项共享指针
Parameters
asource源代码位置,默认为当前调用位置
Returns
日志项共享指针

◆ log_warn()

ptr_logitem ngl::log_warn ( const std::source_location & asource)

获取WARN级别日志项

获取警告级别日志入口点。

Parameters
asource源码位置
Returns
日志项共享指针
Parameters
asource源代码位置,默认为当前调用位置
Returns
日志项共享指针

◆ log_warn_net()

ptr_logitem ngl::log_warn_net ( const std::source_location & asource)

获取WARN级别网络日志项

获取网络警告级别日志入口点。

Parameters
asource源码位置
Returns
日志项共享指针
Parameters
asource源代码位置,默认为当前调用位置
Returns
日志项共享指针