1

I am using syslog() function for logging information in one of my application. I am using c code to call syslog() function in Fedora 14 Linux.

Currently when i call syslog function something like this:

syslog(LOG_INFO,"MYLOG");

I am getting logged msg in /var/log/messages file as follows

Oct  7 04:32:53 syslogname MYLOG

Now i want to have custom Priority value (say 137) logged in the beginning of the syslog() message. for eg: log should look some thing like this.

PRI Oct  7 04:32:53 syslogname MYLOG

I want PRI number to appear in the beginning of the logged message. I did Google search but didn't get proper answer. Request you to kindly suggest as to how to do this using syslog() function?

Prakash K
  • 11,669
  • 6
  • 51
  • 109
sram
  • 69
  • 4

2 Answers2

1

The /var/log/messages file is written by your syslog daemon. Traditionally the PRI value is stripped from it. See this question and my answer there.

You need to set up a special formatter in your syslog deamon to have the severity logged there. Rsyslog has templates for this. With nxlog you can use the $SyslogSeverity field and prepend it to $Message or $raw_message.

Community
  • 1
  • 1
b0ti
  • 2,319
  • 1
  • 18
  • 18
  • Hi, Thanks a lot for your inputs. Infact i had seen your post before posting this query but was not able to implement this! I have some basic questions about syslog and request you to clariffy. – sram Oct 12 '12 at 05:09
  • I have some basic questions about syslog and request you to clariffy. 1. Does syslog-ng support PRIORITY logging ? if yes how to do it? 2. You have mentioned that rsyslog supports this, i'm using FC14 linux and already have rsyslog daemon. Does this support this? else what version of rsyslog i have to try? I tried templates with syslog-ng but could not get the PRI in logged message. i want to use either syslog-ng or rsyslog not nxlog. Please suggest. – sram Oct 12 '12 at 05:39
0

You could use rsyslog to write in the format that you require. The template for your requested format should look something like this: %pri% %timereported% %syslogtag% %msg%

For available parameters you can check http://www.rsyslog.com/doc/property_replacer.html.