我希望能够根据在它们中找到的模式来分割日志文件。
例如,处理所有日志并查找/(\w+)\s与/myresource匹配,但排除/myresource/anythingelse,以便将所有内容重定向到/var/log/extractedlog/myresource/access.log。我可以轻松地使用一些grep来编写脚本,但是,尝试实时地这样做可能会使问题更加困难。例如,我想在不生成重复的情况下调用程序两次。
下面是一个完整的代码,用于使用syslog-ng /etc/syslog-ng/syslog-ng.conf (学分到达公认的答案):
# no-parse let syslog load any source
source s_unparsed_source {
file("/var/log/myservice/access.log"
flags(no-parse));
};
# Just protect the input and avoid syslog-ng header to be added in the final log
template t_preserve_message {
template("$MSG\n");
template_escape(no);
};
# This will filter the message only matching the given expression
filter f_match_pattern1 {
match("\/pattern1");
};
destination d_target1 {
file("/var/log/target/pattern1/access.log" template(t_preserve_message));
};
# The actual logging instruction which wraps everything
log {
source(s_unparsed_source);
filter(f_math_pattern1);
destination(d_target1);
};发布于 2014-07-15 08:54:10
rsyslog和syslog-ng ( GNU/Linux中用于管理日志的两个常用程序)都有这样做的方法。
使用syslog-ng,您可以定义匹配正则表达式的筛选器:
filter myfilter {
not match("regex" value("\/usr\/sbin\/run-crons"))
and not match("regex" value("vmware-checker"));
}您还可以使用模式数据库,它允许事件和动作触发之间的关联。
还有原木存放物,它有高级过滤能力。具体来说,它有一个grep过滤器:
filter {
grep {
match => { "message" => "hello world" }
}
}发布于 2014-07-21 09:06:25
看看罗格人。
我使用syslog-ng来“正常”地登录到文件中,此外,我还将所有信息通过管道输送到日志管理员中,以便按程序进行分类,并发现新的/不寻常的消息。
我的配置中有一个片段,所以我看到了所有openvpn警告:
'^.{29} .+ openvpn\[[0-9]+\]: (ERROR|WARN)' - - - 0 echo >>lines.openvpn $0
'^.{29} .+ openvpn\[[0-9]+\]: ' - - - 0 ignorehttps://serverfault.com/questions/612589
复制相似问题