Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http_format_log for nginx servers #1139

Closed
hostingnuggets opened this issue Oct 28, 2017 · 9 comments
Closed

http_format_log for nginx servers #1139

hostingnuggets opened this issue Oct 28, 2017 · 9 comments

Comments

@hostingnuggets
Copy link

The nginx::http_format_log config parameter only applies to the main nginx.conf file. It would be nice to have the possibility to customize the log format per nginx server. For example by using the following hiera config parameter:

nginx::nginx_servers:
  'www.mywebsite.com':
    http_format_log: 'special'
...
@wyardley
Copy link
Collaborator

The log_format directive is only valid in http context:
http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
That said, you can create as many log_formats as you want, and reference them from a specific server block.

@hostingnuggets
Copy link
Author

I might have not been quite clear: what I would like to do is from my nginx server blocks to use a specific log_format which of course I would have defined in the http context as you correctly mention. This is currently not possible as the access_log parameter in the server block does not allow you to pass a custom log_format, it always and automatically defaults to combined. Or did I miss something?

@alexjfisher
Copy link
Member

I'm pretty sure this is already possible. I use this module with json formatted logs.
As well as the access_log parameter, there is also format_log.

@alexjfisher
Copy link
Member

Ah right, that's the problem. In the main class it's called http_format_log but in server.pp it's just format_log.

@hostingnuggets
Copy link
Author

Ahh thank you that was exactly what I was looking for, namely format_log. Didn't see anything about it in the docs.

@alexjfisher
Copy link
Member

BTW, in newer versions of nginx, log_format has an escape parameter you can set to json. There's no explicit support for this in the puppet module, but that doesn't really matter.
eg just ram it in a bit like (and I haven't got access to my actual code just now)...

class { 'nginx':
  log_format =>
    {
      'logstash_json' => 'escape=json \'{ "@timestamp": "$time_iso8601", ...',
    }
}

@alexjfisher
Copy link
Member

@hostingnuggets I'm glad we were able to help. PRs to improve the docs are always welcome! :)

@wyardley
Copy link
Collaborator

wyardley commented Nov 2, 2017

Ahh thank you that was exactly what I was looking for, namely format_log. Didn't see anything about it in the docs.

btw, while the main class does need an improvement in parameter docs, location and server resources do actually have mostly-complete docs -- for this case:

https://github.com/voxpupuli/puppet-nginx/blob/master/manifests/resource/server.pp#L101-L106
https://github.com/voxpupuli/puppet-nginx/blob/master/manifests/resource/server.pp#L234

@hostingnuggets
Copy link
Author

@wyardley cheers for the precisions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants