Reputation: 35
I am entirely new to this syslog-ng concept and trying to do some logging of my application using syslog-ng levels into different files.
ie.) LOG_ALERT log should be generated into alert.log file and Log_INFO log should be generated into info.log file
I have tried to modify the syslog-ng.conf file for separation files based on levels, where I am not sure about the modification I had done is correct.
I had a look on to this question, where I am not able to understand the answer Writing in separate log files
Following is the syslog-ng.conf I have modified
@version: 3.2
@include "scl.conf"
source s_local {
system();
internal();
};
source s_LOG_ALERT {
system();
internal();
};
source s_network {
udp();
};
destination d_local {
file("/var/log/messages.txt");
};
destination d_LOG_ALERT {
file("/var/log/alert.txt");
};
log {
source(s_LOG_ALERT);
destination(d_LOG_ALERT);
};
log {
source(s_local);
# uncomment this line to open port 514 to receive messages
#source(s_network);
destination(d_local);
};
After this modification, I had observed that the log is entirely generating in the only messages.txt file, but not in alert.tx.
Following is the sample C code I have used
openlog("myapp",LOG_CONS|LOG_PID|LOG_NDELAY,LOG_LOCAL0);
syslog(LOG_ALERT|LOG_LOCAL0,"Alert",getuid());
syslog (LOG_ALERT, "Program started by User %d \n", getuid ());
syslog (LOG_ALERT , "Its the Beginning ");
syslog (LOG_ALERT , "Hello ALL ");
syslog (LOG_ALERT , "Its the alert ");
syslog (LOG_INFO , " Information for all ");
syslog (LOG_INFO, " Simulation has begin ");
followed by my application code.
Any leads would be very helpful.
Upvotes: 0
Views: 877
Reputation: 64
If you would like to simplify the above configuration, it is possible with template file destination name.
@version: 3.2
@include "scl.conf"
source s_in {
system();
internal();
udp();
};
destination d_log {
file("/var/log/${LEVEL}.txt");
};
log {
source(s_in);
destination(d_log);
};
When the message is written out, the ${LEVEL} macro is evaluated, so no filtering or multiple log paths is required.
You could use multiple macros in the destination file name such as date related ones (MONTH, YEAR, ...), or even PROGRAM, HOST.
Upvotes: 0
Reputation: 557
You need separate log statements for the different log levels, and use filters to route only the appropriate messages into the files. Also, you need to add the flags(final) to the log statements so the messages appear only in one file. Like this:
log {
source(s_local);
filter { level("alert") };
destination(d_LOG_ALERT);
flags(final);
};
Upvotes: 1