魔兽世界服务器Trinitycore分析三:日志模块
来源:互联网 发布:手机java软件培训 编辑:程序博客网 时间:2024/04/28 16:34
一:日志接口
TrinityCore的日志有六个级别:Trace,Debug,Info,Warn,Error,Fatal
它们分别对应以下这六个接口,(filterType__也是在配置文件中指定的)
#define TC_LOG_TRACE(filterType__, ...)#define TC_LOG_DEBUG(filterType__, ...)#define TC_LOG_INFO(filterType__, ...)#define TC_LOG_WARN(filterType__, ...)#define TC_LOG_ERROR(filterType__, ...)#define TC_LOG_FATAL(filterType__, ...)
二:日志类型与Appender
说明:这个在配置文件的注释中说得很详细,直接帖两段吧
Appender配置:
# Appender config values: Given a appender "name"# Appender.name# Description: Defines 'where to log'# Format: Type,LogLevel,Flags,optional1,optional2,optional3## Type# 0 - (None)# 1 - (Console)# 2 - (File)# 3 - (DB)## LogLevel# 0 - (Disabled)# 1 - (Trace)# 2 - (Debug)# 3 - (Info)# 4 - (Warn)# 5 - (Error)# 6 - (Fatal)## Flags:# 0 - None# 1 - Prefix Timestamp to the text# 2 - Prefix Log Level to the text# 4 - Prefix Log Filter type to the text# 8 - Append timestamp to the log file name. Format: YYYY-MM-DD_HH-MM-SS (Only used with Type = 2)# 16 - Make a backup of existing file before overwrite (Only used with Mode = w)## Colors (read as optional1 if Type = Console)# Format: "fatal error warn info debug trace"# 0 - BLACK# 1 - RED# 2 - GREEN# 3 - BROWN# 4 - BLUE# 5 - MAGENTA# 6 - CYAN# 7 - GREY# 8 - YELLOW# 9 - LRED# 10 - LGREEN# 11 - LBLUE# 12 - LMAGENTA# 13 - LCYAN# 14 - WHITE## File: Name of the file (read as optional1 if Type = File)# Allows to use one "%s" to create dynamic files## Mode: Mode to open the file (read as optional2 if Type = File)# a - (Append)# w - (Overwrite)## MaxFileSize: Maximum file size of the log file before creating a new log file
日志配置:
# Appender config values: Given a appender "name"# Appender.name# Description: Defines 'where to log'# Format: Type,LogLevel,Flags,optional1,optional2,optional3## Type# 0 - (None)# 1 - (Console)# 2 - (File)# 3 - (DB)## LogLevel# 0 - (Disabled)# 1 - (Trace)# 2 - (Debug)# 3 - (Info)# 4 - (Warn)# 5 - (Error)# 6 - (Fatal)## Flags:# 0 - None# 1 - Prefix Timestamp to the text# 2 - Prefix Log Level to the text# 4 - Prefix Log Filter type to the text# 8 - Append timestamp to the log file name. Format: YYYY-MM-DD_HH-MM-SS (Only used with Type = 2)# 16 - Make a backup of existing file before overwrite (Only used with Mode = w)## Colors (read as optional1 if Type = Console)# Format: "fatal error warn info debug trace"# 0 - BLACK# 1 - RED# 2 - GREEN# 3 - BROWN# 4 - BLUE# 5 - MAGENTA# 6 - CYAN# 7 - GREY# 8 - YELLOW# 9 - LRED# 10 - LGREEN# 11 - LBLUE# 12 - LMAGENTA# 13 - LCYAN# 14 - WHITE## File: Name of the file (read as optional1 if Type = File)# Allows to use one "%s" to create dynamic files## Mode: Mode to open the file (read as optional2 if Type = File)# a - (Append)# w - (Overwrite)## MaxFileSize: Maximum file size of the log file before creating a new log file
三:配置例子:
Appender.Console=1,3,0Appender.Server=2,2,0,Server.log,wLogger.root=2,Console Server
以上这三句,定义了两个Appender:Console, Server,一个log type:root
Appender.Console说明将日志输出到终端上,最低输出级别是Info,输出字体颜色是黑色(因终端的不同而不同)
Appender.Server说明将日志输出到文件,最低输出级别是Debug,输出文件是(Server.log),以重写(非添加)的方式写入
Logger.root最低输出级别是Info,使用Console和Server的配置
四,底层实现
这里简单地说一下,就不太深入了
以 TC_LOG_INFO("qch", "Hello, world"); 为例子
这句实现上是调用了
if(Log::instance()::ShouldLog("qch", LOG_LEVEL_INFO) ) Log::instance()::outMessage ("qch", LOG_LEVEL_INFO, "Hello,world");
ShouldLog比较好理解,直接将配置文件中的最低日志输出级别和LOG_LEVEL_INFO一比较就搞定。
outMessage就比较麻烦了,层层调用,有兴趣的可以去看看,这里就不多作解释了。
如果把Appender的Type设为3(DB),那每写一条日志,就是在auth库的logs表中插入一条记录:
INSERT INTO logs (time, realm, type, level, string) VALUES (1409544332, 0, 'qch', 3,'Hello, world\n')
0 0
- 魔兽世界服务器Trinitycore分析三:日志模块
- 魔兽世界服务器Trinitycore分析一:前言
- 魔兽世界服务器Trinitycore分析二:auth server的main函数
- 魔兽世界服务器Trinitycore分析四:auth server网络事件的处理
- trinitycore数据库模块
- TrinityCore 魔兽世界私服11159 完整配置
- 魔兽世界 Mangos Trinity TrinityCore 数据库 结构 大纲
- nginx日志模块分析
- TrinityCore开发环境搭建及服务器搭建
- 服务器设计系列:日志模块
- web服务器日志分析
- python 服务器日志分析
- 魔兽世界服务器的研究
- nginx日志模块分析详解
- 魔兽世界封包分析(1)
- 魔兽世界角色换装分析
- 魔兽世界角色换装分析
- 服务器日志常规分析方法
- mbps和MB/s是怎么换算的
- 【SSH进阶之路】一步步重构MVC实现Struts框架——从一个简单MVC开始(三)
- [LeetCode] String to Integer (atoi)
- hdu 1045 Fire Net
- UVA 10801 Lift Hopping (最短路)
- 魔兽世界服务器Trinitycore分析三:日志模块
- ubuntu下安装软件包依赖问题
- C++面试题
- DWZ框架原子函数
- JS获取cookie值
- asp.netSession共享的解决方案
- 转载 基础总结篇之五:BroadcastReceiver应用详解
- Linux用户进程间通信机制在内核的实现
- 迭代器模式