2013年(4)
分类: LINUX
2013-08-20 14:07:47
#define MAXFUNIX 20//本地可打开的最大靠接口文件数
int nfunix = 1;//打开的套接口文件数
char *funixn[MAXFUNIX] = { _PATH_LOG };//套接口文件地址
int funix[MAXFUNIX] = { -1, };//套接口文件是否打开
int Debug; /* debug flag */调节开关
char LocalHostName[MAXHOSTNAMELEN+1]; /* our hostname */本地主机名称
char *LocalDomain; /* our local domain name */本机域名
char *emptystring = "";只表示空字符串...
int InetInuse = 0; /* non-zero if INET sockets are being used */是否使用了sockets
int finet = -1; /* Internet datagram socket */保存UDP套接口的信息
int LogPort; /* port number for INET connections */网络连接端口
int Initialized = 0; /* set when we have initialized ourselves */是否初始化,0表示未初始化
int MarkInterval = 20 * 60; /* interval between marks in seconds */间隔时间打"-- MARK --" 标记
int MarkSeq = 0; /* mark sequence number */记录MARK的当前间隔值,但其值大于MarkInterval时,打标记
int NoFork = 0; /* don't fork - don't run in daemon mode */是否以daemon状态启动
int DisableDNS = 0; /* don't look up IP addresses of incoming messages */是否查发送询信息的主机的名称
int AcceptRemote = 0; /* receive messages that come via UDP */是否接收远程端口
char **StripDomains = NULL; /* these domains may be stripped before writing logs */保存域名,在写日志前此域名已经被裁减
char **LocalHosts = NULL; /* these hosts are logged with their hostname */保存本地主机名称
int NoHops = 1; /* Can we bounce syslog messages through an intermediate host. */
char **parts;//文件描述符数组;下标表示文件描述符,数组内容存放文件名;
主要的优先级(12种)
struct code PriNames[] = {
{"alert", LOG_ALERT},
{"crit", LOG_CRIT},
{"debug", LOG_DEBUG},
{"emerg", LOG_EMERG},
{"err", LOG_ERR},
{"error", LOG_ERR}, /* DEPRECATED */
{"info", LOG_INFO},
{"none", INTERNAL_NOPRI}, /* INTERNAL */
{"notice", LOG_NOTICE},
{"panic", LOG_EMERG}, /* DEPRECATED */
{"warn", LOG_WARNING}, /* DEPRECATED */
{"warning", LOG_WARNING},
{"*", TABLE_ALLPRI},
{NULL, -1}
主要的设备类型(23种)
struct code FacNames[] = {
{"auth", LOG_AUTH},
{"authpriv", LOG_AUTHPRIV},
{"cron", LOG_CRON},
{"daemon", LOG_DAEMON},
{"kern", LOG_KERN},
{"lpr", LOG_LPR},
{"mail", LOG_MAIL},
{"mark", LOG_MARK}, /* INTERNAL */
{"news", LOG_NEWS},
{"security", LOG_AUTH}, /* DEPRECATED */
{"syslog", LOG_SYSLOG},
{"user", LOG_USER},
{"uucp", LOG_UUCP},
#if defined(LOG_FTP)
{"ftp", LOG_FTP},
#endif
{"local0", LOG_LOCAL0},
{"local1", LOG_LOCAL1},
{"local2", LOG_LOCAL2},
{"local3", LOG_LOCAL3},
{"local4", LOG_LOCAL4},
{"local5", LOG_LOCAL5},
{"local6", LOG_LOCAL6},
{"local7", LOG_LOCAL7},
{NULL, -1},
};
日志优先级和设备类型,与配置文件第一列的数据相对应(小数点前是设备类型,小数点后是信息优先级。);
2、主要功能
1> 接收日志信息;然后将依据日志的设备类型(openlog中设置)和信息等级(syslog中设置)将信息存入不同的本地文件中。
2> 将本地日志发送到远程服务器上。
3> 接收远程发送过来的日志。
3、业务数据流
recv收到信息
-> printchopped(确保给printline的是一行信息)
-> printline(提取信息优先级,验证某文件在设备和优先级下是否接收该日志,处理日志中的特殊字符)
-> logmsg(1、检查该条日志是否有时间信息,时间信息是否合法,如果不合法则将时间信息移除。2、检查是否是重复信息等。)
-> fprintlog(存入对应的文件中)
4、重要函数分析