我如何在VCL中print a log
?
我可以在屏幕上打印日志信息吗?
我可以这样做吗?
sub vcl_recv {
....
log.info(req.http.host); // can i write a log here?
....
}
答案 0 :(得分:22)
您可以看到带有请求网址的URL varnishlog实用程序(它能够写入日志文件)
varnishlog -i RxURL
或者使用vmod std和syslog函数向syslog输出一些信息 Varnish 3.x https://www.varnish-cache.org/docs/trunk/reference/vmod_std.html#syslog Varnish 5.1 https://varnish-cache.org/docs/5.1/reference/vmod_std.generated.html#func-syslog
示例:
import std;
sub vcl_recv {
...
std.syslog(180, "RECV: " + req.http.host + req.url);
...
}
或使用C-snippet on Varnish 2.x https://www.varnish-cache.org/trac/wiki/VCLExampleSyslog
答案 1 :(得分:13)
使用vcl config file,导入附加的"标准库",其中包含一堆实用程序函数:
import std;
# To 'varnishlog'
std.log("varnish log info:" + req.host);
# To syslog
std.syslog( LOG_USER|LOG_ALERT, "There is serious troble");
v5.x - https://www.varnish-cache.org/docs/5.0/reference/vmod_std.generated.html?#func-log
v4.x - https://www.varnish-cache.org/docs/4.0/reference/vmod_std.generated.html?#func-log
v3.x - (已弃用)https://www.varnish-cache.org/docs/3.0/reference/vmod_std.html#log
另见man varnishlog