Reputation: 69
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?
Upvotes: 1
Views: 2170
Reputation: 116
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.
Upvotes: 0
Reputation: 2329
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.
Upvotes: 1