Challenge - 5 Problems
Log Format Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this custom log format directive?
Given the following nginx log_format directive, what will be the logged output for a request with remote_addr 192.168.1.10, request_method GET, and request_uri /home?
Nginx
log_format custom '$remote_addr - $request_method "$request_uri"';
access_log /var/log/nginx/access.log custom;Attempts:
2 left
💡 Hint
Look carefully at the quotes and dashes in the log_format string.
✗ Incorrect
The log_format directive uses single quotes around the whole format and double quotes around $request_uri. The dash and spaces are literal. So the output includes the dash and quotes exactly as specified.
❓ Configuration
intermediate2:00remaining
Which log_format directive correctly logs the request time in seconds with millisecond precision?
You want to log the request processing time in seconds with millisecond precision using the variable $request_time. Which of the following log_format directives achieves this?
Attempts:
2 left
💡 Hint
Remember that $request_time already includes seconds with milliseconds as a decimal number.
✗ Incorrect
The variable $request_time in nginx logs the request processing time in seconds with millisecond precision as a decimal number. Adding units like 'ms' or 'seconds' as text is optional but must be consistent with the value meaning.
❓ Troubleshoot
advanced2:00remaining
Why does this custom log format cause nginx to fail to start?
Consider this nginx configuration snippet:
log_format broken '$remote_addr - $request_method $request_uri;
access_log /var/log/nginx/access.log broken;
Why does nginx fail to start with this configuration?
Nginx
log_format broken '$remote_addr - $request_method $request_uri;
access_log /var/log/nginx/access.log broken;Attempts:
2 left
💡 Hint
Check the quotes carefully in the log_format directive.
✗ Incorrect
The log_format directive string is missing the closing single quote at the end, causing nginx to fail parsing the configuration.
🔀 Workflow
advanced2:00remaining
What is the correct sequence to apply a new custom log format without downtime?
You created a new log_format named 'detailed' in nginx.conf. What is the correct workflow to apply this change without dropping active connections?
Attempts:
2 left
💡 Hint
You must edit config before testing syntax.
✗ Incorrect
First edit the config to add the new log_format and update access_log. Then test syntax with 'nginx -t'. If syntax is OK, reload nginx with 'nginx -s reload' to apply changes without downtime. Finally, verify logs.
✅ Best Practice
expert2:00remaining
Which custom log format best balances detailed info and log file size?
You want a custom nginx log format that logs client IP, request method, URI, status code, and request time, but avoids logging headers or cookies to keep log size manageable. Which option is best?
Attempts:
2 left
💡 Hint
Avoid logging headers or cookies to reduce log size.
✗ Incorrect
Option A logs essential info without extra headers or cookies, keeping logs concise. Options B and C add headers/cookies increasing size. Option A adds request_length which may not be necessary.