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

Parameters for log_format #678

Closed
goldsap25 opened this issue Sep 9, 2015 · 5 comments
Closed

Parameters for log_format #678

goldsap25 opened this issue Sep 9, 2015 · 5 comments

Comments

@goldsap25
Copy link

I need to set the log_format values but not sure how to do this. I was not able to find documentation regarding this.

By default, it's setting $log_format: {}
I need it to be set such that it looks like below. (skipping other values within http)

http{
log_format main 'some string with some var like $remote_addr'
'another string'
'one more string'
}

If this is the wrong place to post question, please let me know where I may post this question.

Thanks!

@Griphon
Copy link

Griphon commented Sep 15, 2015

Just add

class { '::nginx::config':
  ...
  log_format => {
    main      => 'some string with some var like $remote_addr',
    alternate => 'another string',
    combined  => '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"',
  }
  ...
}

@goldsap25
Copy link
Author

When I used the format provided, it created following on the conf file.

log_format alternate '$status $body_bytes_sent "$http_referer" ';
log_format combined '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"';
log_format main '$remote_addr - $remote_user [$time_local] "$request" ';

And it fails the config check. log_format should not be repeated, it seems. :(
I have it working for now by adding a module that pastes in the exact content that I want but wanted to check if it was possible to generate the multiline for log_format without repeating log_format.

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

@Griphon
Copy link

Griphon commented Sep 18, 2015

@goldsap25, I use 2 formats and it seems to be ok. Try to remove format combined as it's predefined

@wyardley
Copy link
Collaborator

wyardley commented Oct 8, 2016

I'm going to close this one; @goldsap25, please reopen or file a new issue if you're still experiencing problems.

@soudaburger
Copy link

I know this is closed, but I just wanted to add that I solved this with crazy inline escaping in hiera. Wondering if there's a better way to handle this?

nginx::log_format main: "$remote_addr - $remote_user [$time_local] \"$request\"'\n\t\t '$status $body_bytes_sent \"$http_referer\" Via:\"$http_via\" '\n\t\t '\"$http_user_agent\" \"$http_x_forwarded_for\""

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

4 participants