@version:3.0

options {
	chain_hostnames(no);
	create_dirs(yes);
	flush_lines(0);
	keep_hostname(no);
	log_fifo_size(10240);
	log_msg_size(81920);
	log_iw_size(10240);
	log_fetch_limit(10240);
	stats_freq(0);
	use_dns(no);
	use_fqdn(no);
	dns_cache(no);
	ts_format(iso);
	keep_timestamp(no);
};

source src {
	internal();
	unix-stream("/dev/log");
};

source kernel {
	file("/proc/kmsg" program_override("kernel") flags(kernel));
};

destination d_messages {
	file("/tmp/messages");
};

destination proc_messages {
	file("/proc/xiaoqiang/xq_syslog");
};

template t_stat { template("$MSG\n"); };

destination d_stat_points_rom {
	file("/tmp/stat_points_rom.log" template(t_stat));
};

destination d_stat_points_web {
	file("/tmp/stat_points_web.log" template(t_stat));
};

destination d_stat_points_privacy {
	file("/tmp/stat_points_privacy.log" template(t_stat));
};

destination d_wifi_log {
	file("/tmp/wifi_analysis.log");
};

destination d_dns_log {
    pipe("/tmp/web_filter_list",template(t_stat));
};

filter f_luci {
	level(alert .. info)
	and program(luci)
	and not match("stat_points_" value("MESSAGE"));
};

filter f_messages {
	level(alert .. warning)
	and not program(luci)
        and not match("wifi_log" value("MESSAGE"))
	and not match("stat_points_" value("MESSAGE"));
};

filter f_messages_d {
	not program(luci)
        and not match("wifi_log" value("MESSAGE"))
	and not match("stat_points_" value("MESSAGE"));
};

filter f_stat_points_rom {
	(match("stat_points_none" value("MESSAGE"))
	or match("stat_points_instant" value("MESSAGE")))
	and not program(web);
};

filter f_stat_points_web {
	(match("stat_points_none" value("MESSAGE"))
	or match("stat_points_instant" value("MESSAGE")))
	and program(web);
};

filter f_stat_points_privacy {
	match("stat_points_privacy" value("MESSAGE"));
};

filter f_wifi_log {
        match("wifi_log" value("MESSAGE"))
        and not program(web);
};

filter f_dns_log {
        match("stat_points_dns" value("MESSAGE"))
        and not program(web);
};

# user this rewrite to replace kernel timestamp
rewrite f_stat_points_kernel {
       subst("^\[ *[0-9]+\.[0-9]+\] ", "", value("MESSAGE"));
};

rewrite f_stat_points_dns {
    subst("stat_points_dns dns_resolve=", "", value("MESSAGE"));
};

log {
	source(src);
	source(kernel);
	filter(f_luci);
	destination(d_messages);
	destination(proc_messages);
};
log {
	source(src);
	source(kernel);
	filter(f_messages);
	destination(d_messages);
	destination(proc_messages);
};
log {
	source(src);
	filter(f_stat_points_rom);
	destination(d_stat_points_rom);
};
log {
	source(kernel);
	rewrite(f_stat_points_kernel);
	filter(f_stat_points_rom);
	destination(d_stat_points_rom);
};
log {
	source(src);
	filter(f_stat_points_web);
	destination(d_stat_points_web);
};
log {
	source(src);
	filter(f_stat_points_privacy);
	destination(d_stat_points_privacy);
};
log {
	source(kernel);
	rewrite(f_stat_points_kernel);
	filter(f_stat_points_privacy);
	destination(d_stat_points_privacy);
};
log {
	source(kernel);
	rewrite(f_stat_points_kernel);
	filter(f_wifi_log);
	destination(d_wifi_log);
};
log {
	source(src);
	filter(f_wifi_log);
	destination(d_wifi_log);
};
log {
    source(src);
    filter(f_dns_log);
    rewrite(f_stat_points_dns);
    destination(d_dns_log);
};
