如何在清漆中调试VCL?

lic*_*gwu 19 varnish varnish-vcl

我怎么能print a log在VCL?

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

我可以这样做吗?

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

ghl*_*ogh 23

您可以看到带有请求URL的URL varnishlog实用程序(它能够写入日志文件)

varnishlog -i RxURL
Run Code Online (Sandbox Code Playgroud)

或者使用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.组织/文档/ 5.1 /参考/ vmod_std.generated.html#FUNC-系统日志

例:

import std;

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

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


her*_*ere 13

使用vcl配置文件,导入附加的"标准库",其中包括一堆实用程序函数:

import std;

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

# To syslog
std.syslog( LOG_USER|LOG_ALERT, "There is serious trouble");
Run Code Online (Sandbox Code Playgroud)

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