caddyserver / transform-encoder

Log encoder module for custom log formats
Apache License 2.0
79 stars 17 forks source link

How to output only one User-Agent? #5

Closed riku22 closed 4 years ago

riku22 commented 4 years ago

Hello.

I'm trying to log only one from the User-Agent header. I wrote the following template.

format formatted "{{index request>headers>User-Agent 0}}"

However, this does not work well, and the character string specified in the format as shown below is output as it is.

{{index request>headers>User-Agent 0}}

Is it difficult to do this?

The environment is as follows.

Best regards.

mohammed90 commented 4 years ago

The template isn't a Go template, so the usage of double braces and the function index isn't correct. The syntax of the template is defined by the backing library github.com/buger/jsonparser. For your use-case, you need: format formatted "{request>headers>User-Agent>[0]}".

This is a shortcoming in the documentation of this module. I'll address it in the README shortly.