日  志  服  务  器

康    林(2011-1-28)

 

一、日志服务器的架构:

日志服务器由三部分组成:

a)         应用程序日志库

作用:输出日志。

依赖库:ACE

b)        客户端日志DAEMON

作用:收集同一台服务器上所有应用程序的日志,并转发到指定的日志服务器上。

组件:

配置服务管理器(windows下ACE_wrappers/netsvcs/servers/ace_netsvcs.exe, linux下ACE_wrappers/netsvcs/servers/main)

配置服务管理器配置文件(svc.conf)

日志服务库(netsvcs)

         依赖库:

                ACE、netsvcs、pthread

         注意,在linux下配置文件中配置 ACE、netsvcs库时,请使用绝对路径

日志存储es 日志存储服务器_服务器

c)        日志服务器

作用:存储各应用程序生成的日志。以便以后查询。

组件:

配置服务管理器(windows下ACE_wrappers/netsvcs/servers/ace_netsvcs.exe, linux下ACE_wrappers/netsvcs/servers/main)

配置服务管理器配置文件(svc.conf)

日志服务库(netsvcs)

依赖库:

                ACE、netsvcs、pthread

         注意,在linux下配置文件中配置 ACE、netsvcs库时,请使用绝对路径

 


 

二、使用:

1)        服务器的配置:

在日志服务器上,配置服务管理器的配置文件,加入日志策略服务和日志服务。

a)        日志策略服务:

dynamic Logger Service_Object * ACE:_make_ACE_Logging_Strategy() " -f STDERR|VERBOSE"

“”中的为参数,可以设置日志的输出位置,详细程序等策略。参数如下:

/**
   * Parse arguments provided in svc.conf file.
   * @arg '-f' Pass in the flags (such as OSTREAM, STDERR, LOGGER, VERBOSE,
   *           SILENT, VERBOSE_LITE) used to control logging.
   * @arg '-i' The interval (in seconds) at which the logfile size is sampled
   *           (default is 0, i.e., do not sample by default).
   * @arg '-k' Set the logging key.
   * @arg '-m' Maximum logfile size in Kbytes.
   * @arg '-n' Set the program name for the %n format specifier.
   * @arg '-N' The maximum number of logfiles that we want created.
   * @arg '-o' Specifies that we want the no standard logfiles ordering
   *           (fastest processing in handle_timeout()).  Default is not to
   *           order logfiles.
   * @arg '-p' Pass in the process-wide priorities to either enable (e.g.,
   *           DEBUG, INFO, WARNING, NOTICE, ERROR, CRITICAL, ALERT,
   *           EMERGENCY) or to disable (e.g., ~DEBUG, ~INFO, ~WARNING,
   *           ~NOTICE, ~ERROR, ~CRITICAL, ~ALERT, ~EMERGENCY).
   * @arg '-s' Ensure that the OSTREAM flag is set and log to the @a filename.
   * @arg '-t' Pass in the thread-wide priorities to either enable (e.g.,
   *           DEBUG, INFO, WARNING, NOTICE, ERROR, CRITICAL, ALERT,
   *           EMERGENCY) or to disable (e.g., ~DEBUG, ~INFO, ~WARNING,
   *           ~NOTICE, ~ERROR, ~CRITICAL, ~ALERT, ~EMERGENCY).
   * @arg '-w' Cause the logfile to be wiped out, both on startup and on
   *           reconfiguration.
   */
b)        日志服务:
dynamic Thr_Server_Logging_Service Service_Object * netsvcs:_make_ACE_Thr_Server_Logging_Acceptor() active "-p 20020"

 

“”中为日志服务的参数:

-p  :日志服务器的监听端口号

 

2)        客户端日志DAEMON

在应用服务器上配置服务管理器(ismg_daemon)的配置文件,加入客户端日志

DAEMON服务。

dynamic Client_Logging_Service Service_Object * netsvcs:_make_ACE_Client_Logging_Acceptor() active "-p 20020 –h 10.10.1.69"
 
“”中为客户端日志DAEMON参数:
-p :日志服务器的端口
-h:日志服务器的IP地址
-l:本机IP
-k: 设置 the logging key.即本地的监听IP和端口
(默认:
# if !defined (ACE_DEFAULT_LOGGER_KEY)
#   
#     
#   
#     
#   
# endif /* ACE_DEFAULT_LOGGER_KEY */
)

3)        应用程序输出日志:

你可以直接使用ACE日志宏进行日志输出,详见《ACE日志库使用》。

一般我们在开发中常使用三种级别的日志输出(调试级别、错误级别、信息级别),所以我定义了三个宏:

LOG_DEBUG(X, …)
LOG_ERROR(X, …)
LOG_INFO(X, …)

如果你不是使用配置服务管理器,为了能使用你的程序可以按指定的策略进行输出。为此定义了一个初始化宏。

LOG_INIT(argn, argv)

你可以按前面策略服务所讲的参数进行设置。如果你要自定日志输出策略,你必须在程序启动时调用这个宏进行日志策略初始化。默认的日志输出是直接输出到stderr。

 

三、日志输出格式约定

a)         信息级别:

各元互素分隔符用 :  分隔,第一个元素为此信息名字

MONITOR:clients:0:close:0:srv_handler:0:recvPackage:0:error:0:heart:0:sends:0:packages:0:resend:0:responsion:0:error:0:buffer:0

b)        错误级别:

请输出错误返回码,和错误内容,第一个元素为此模块名字

c)        调试级别:

输出调试内容,第一个元素为此模块名字