syslog消息格式

qudaxiao2 2010-11-12 10:41:16
在RFC3164中定义的格式为:<34>Oct 11 22:14:15 mymachine su: 'su root' failed for lonvick
其中“<34>”为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 %s\n", timestamp, msg);
else {
char res[20];
parse_fac_prio_20(pri, res);
sprintf(G.printbuf, "%s %.64s %s %s\n", timestamp, G.hostname, res, msg);
}其中parse_fac_prio_20(pri, res);是对pri做snprintf(res,20,"<%d>",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), "<%d>%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) < logLevel) {
if (option_mask32 & OPT_small)
message("%s %s\n", timestamp, msg);
else
message("%s %s %s %s\n", timestamp, LocalHostName, res, msg);
}
}
}

貌似都有一个if(option_mask32 & OPT_xxxx)的判断来确定是否要加入优先级<%d>不知道我理解的对不对

我的问题就是怎么处理才能将最前面的优先级显示出来,符合RFC3164的格式,是更改源代码还是在哪个配置文件中操作?
...全文
472 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveztwray 2012-05-09
  • 打赏
  • 举报
回复
为啥看不到回复
steptodream 2010-11-12
  • 打赏
  • 举报
回复
反正在程序里用syslog输出的日志
都是要修改/etc/syslog.conf 来捕获的 修改之后要重启syslog
但是好像新一代的日志管理是syslog-ng 对应的设定文件是 /etc/syslog-ng.conf

不过关于开发方面就不会了
qudaxiao2 2010-11-12
  • 打赏
  • 举报
回复
看过了 貌似只是过滤器的配置,即配置那种级别和类型的syslog消息发送到哪个文件
justkk 2010-11-12
  • 打赏
  • 举报
回复
看看/etc/syslog*.conf文件
没实际用过

23,223

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧