我是该系统ng概念的新手
ie。( log_alert 日志应生成 alert.log 文件和 log_info 日志应生成 info.log 文件
我试图根据级别修改syslog-ng.conf文件以进行分离文件,我不确定我所做的修改是否正确。
我看了这个问题,我无法理解答案在单独的日志文件中写作
以下是syslog-ng.conf,我已经修改了
@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);
};
修改后,我观察到日志完全生成在唯一的消息中。
以下是我使用的示例C代码
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.
任何线索都会非常有帮助。
您需要对不同日志级别的单独日志语句,然后使用过滤器将适当的消息路由到文件中。另外,您需要将标志(最终(添加到日志语句中,因此消息仅出现在一个文件中。这样:
log {
source(s_local);
filter { level("alert") };
destination(d_LOG_ALERT);
flags(final);
};
如果要简化上述配置,则可以使用模板文件目标名称。
@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);
};
当消息写出时,评估了$ {level}宏,因此不需要过滤或多个日志路径。
您可以在目标文件名中使用多个宏,例如与日期相关的宏(月,年,...(,甚至程序,主机。