Challenge - 5 Problems
Conditional Logging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the effect of this nginx config snippet?
Given this nginx configuration snippet, what will be the effect on logging?
map $status $loggable {
~^[23] 0;
default 1;
}
access_log /var/log/nginx/access.log combined if=$loggable;Attempts:
2 left
💡 Hint
Look at the map directive and the if condition in access_log.
✗ Incorrect
The map directive sets $loggable to 0 for status codes starting with 2 or 3, meaning logging is disabled for those. The access_log directive logs only if $loggable is 1, so only other status codes are logged.
❓ Configuration
intermediate2:00remaining
Choose the correct nginx config to log only client errors (4xx)
Which nginx configuration snippet will log only requests with client error status codes (4xx)?
Attempts:
2 left
💡 Hint
Client errors have status codes starting with 4.
✗ Incorrect
The map sets $log_client_error to 1 only when status code starts with 4, enabling logging only for client errors.
❓ Troubleshoot
advanced2:00remaining
Why does conditional logging not work as expected?
An nginx config uses:
But logs still include 2xx responses. What is the likely cause?
map $status $loggable {
~^2 0;
default 1;
}
access_log /var/log/nginx/access.log combined if=$loggable;But logs still include 2xx responses. What is the likely cause?
Attempts:
2 left
💡 Hint
Consider when $status variable is set during request processing.
✗ Incorrect
The $status variable is set after the log phase, so using it in 'if' for access_log does not work as expected. This causes logging to ignore the condition and log all requests.
🔀 Workflow
advanced2:30remaining
Order the steps to enable conditional logging for error responses only
Put these steps in the correct order to configure nginx to log only error responses (status 4xx and 5xx):
Attempts:
2 left
💡 Hint
Start by defining the variable, then specify patterns, then use it, then reload.
✗ Incorrect
First define the variable with map, then specify regex patterns inside it, then use the variable in access_log, finally reload nginx to apply.
✅ Best Practice
expert3:00remaining
Which approach is best for conditional logging of slow requests in nginx?
You want to log only requests that take longer than 2 seconds to process. Which nginx configuration approach is best?
Attempts:
2 left
💡 Hint
Nginx map works with string matching, not numeric comparisons.
✗ Incorrect
Nginx map cannot do numeric comparisons directly. Using regex to match $request_time strings representing values greater than 2 seconds is the practical approach.