当前位置: 技术问答>linux和unix
syslog消息格式
来源: 互联网 发布时间:2017-02-20
本文导语: 在RFC3164中定义的格式为:Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick 其中“”为syslog的设备号*8+优先级 但是我的syslog消息格式是:Jan 1 05:30:42 aicpd: internal forward start running! 我的busybox版本是1.15.3,然后...
在RFC3164中定义的格式为:Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick
其中“”为syslog的设备号*8+优先级
但是我的syslog消息格式是:Jan 1 05:30:42 aicpd: internal forward start running!
我的busybox版本是1.15.3,然后我看了1.3.0的源代码发现虽然有区别但是都大同小异
1.15.3:
if (option_mask32 & OPT_small)
sprintf(G.printbuf, "%s %sn", timestamp, msg);
else {
char res[20];
parse_fac_prio_20(pri, res);
sprintf(G.printbuf, "%s %.64s %s %sn", timestamp, G.hostname, res, msg);
}其中parse_fac_prio_20(pri, res);是对pri做snprintf(res,20,"",pri)的操作
1.3.0:
#ifdef CONFIG_FEATURE_REMOTE_LOG
if (option_mask32 & OPT_remotelog) {
char line[MAXLINE + 1];
/* trying connect the socket */
if (-1 == remotefd) {
remotefd = socket(AF_INET, SOCK_DGRAM, 0);
}
/* if we have a valid socket, send the message */
if (-1 != remotefd) {
snprintf(line, sizeof(line), "%s", pri, msg);
/* send message to remote logger, ignore possible error */
sendto(remotefd, line, strlen(line), 0,
(struct sockaddr *) &remoteaddr, sizeof(remoteaddr));
}
}
if (option_mask32 & OPT_locallog)
#endif
{
/* now spew out the message to wherever it is supposed to go */
if (pri == 0 || LOG_PRI(pri)
其中“”为syslog的设备号*8+优先级
但是我的syslog消息格式是:Jan 1 05:30:42 aicpd: internal forward start running!
我的busybox版本是1.15.3,然后我看了1.3.0的源代码发现虽然有区别但是都大同小异
1.15.3:
if (option_mask32 & OPT_small)
sprintf(G.printbuf, "%s %sn", timestamp, msg);
else {
char res[20];
parse_fac_prio_20(pri, res);
sprintf(G.printbuf, "%s %.64s %s %sn", timestamp, G.hostname, res, msg);
}其中parse_fac_prio_20(pri, res);是对pri做snprintf(res,20,"",pri)的操作
1.3.0:
#ifdef CONFIG_FEATURE_REMOTE_LOG
if (option_mask32 & OPT_remotelog) {
char line[MAXLINE + 1];
/* trying connect the socket */
if (-1 == remotefd) {
remotefd = socket(AF_INET, SOCK_DGRAM, 0);
}
/* if we have a valid socket, send the message */
if (-1 != remotefd) {
snprintf(line, sizeof(line), "%s", pri, msg);
/* send message to remote logger, ignore possible error */
sendto(remotefd, line, strlen(line), 0,
(struct sockaddr *) &remoteaddr, sizeof(remoteaddr));
}
}
if (option_mask32 & OPT_locallog)
#endif
{
/* now spew out the message to wherever it is supposed to go */
if (pri == 0 || LOG_PRI(pri)