22

我如何print a log在 VCL 中?

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

我可以这样做吗?

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

2 回答 2

26

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

varnishlog -i RxURL

或者使用Varnish 3.x https://www.varnish-cache.org/docs/trunk/reference/vmod_std.html#syslog Varnish 5.1 https://varnish-cache的 vmod std 和 syslog 函数向 syslog 输出一些信息。 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);
  ...
}

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

于 2012-09-25T11:05:45.947 回答
16

使用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

于 2015-01-27T08:07:16.313 回答