如何在Varnish中调试VCL?

23

如何在 VCL 中打印日志

我可以在屏幕上打印日志信息吗?

我可以这样做吗?

sub vcl_recv {
  ....
  log.info(req.http.host); // can i write a log here?
  ....
}

1
检查您是否正在请求 varnishd -Cf file_name - Tamil
2个回答

28
您可以使用varnishlog工具查看请求的URL(它能够写入日志文件)。
varnishlog -i RxURL

请使用vmod std和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中输出一些信息到syslog。示例:
import std;

sub vcl_recv {
  ...
  std.syslog(180, "RECV: " + req.http.host + req.url);
  ...
}

或者在Varnish 2.x上使用C代码片段 https://www.varnish-cache.org/trac/wiki/VCLExampleSyslog


VCC编译器失败:来自VCC编译器的消息: 预期一个操作,'if','{'或'}' ('input' 第49行第9个位置) std.syslog(180,“RECV:”+req.http.host+ req.url); - lichengwu
好的,是的,我们忘记使用以下代码导入std vmod函数: import std; https://www.varnish-cache.org/docs/3.0/reference/vmod.html - ghloogh
谢谢。我可以看到日志文件 /var/log/syslog。 - lichengwu
添加注释以供以后编辑:varnish vmod_std 3.0 在 https://www.varnish-cache.org/docs/3.0/reference/vmod_std.html#syslog 和 4.0 在 https://www.varnish-cache.org/docs/4.0/reference/vmod_std.generated.html#void-syslog-int-string-list。 - Crowie

17

使用vcl配置文件,导入额外包含的“标准库”,其中包括一堆实用函数:

import std;

# To 'varnishlog'
std.log("varnish log info:" + req.host);

# To syslog
std.syslog( LOG_USER|LOG_ALERT, "There is serious trouble");

v6.x - https://varnish-cache.org/docs/6.0/reference/vmod_generated.html#void-log-string-s

v5.x - https://varnish-cache.org/docs/5.0/reference/vmod_std.generated.html?#func-log

v4.x - https://varnish-cache.org/docs/4.0/reference/vmod_std.generated.html?#func-log

v3.x - https://varnish-cache.org/docs/3.0/reference/vmod_std.html#log

请参见man varnishlog


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接