日期:2014-05-16  浏览次数:20679 次

syslog消息格式
在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的格式,是更改源代码还是在哪个配置文件中操作?

------解决方案--------------------
看看/etc/syslog*.conf文件
没实际用过
------解决方案--------------------
反正在程序里用syslog输出的日志 
都是要修改/etc/syslog.conf 来捕获的 修改之后要重启syslog
但是好像新一代的日志管理是syslog-ng 对应的设定文件是 /etc/syslog-ng.conf

不过关于开发方面就不会了