0
0
Nginxdevops~20 mins

Log format customization in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Log Format Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2: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;
A192.168.1.10 GET /home
B192.168.1.10 - GET /home
C192.168.1.10 - GET "/home"
D192.168.1.10 - "GET" "/home"
Attempts:
2 left
💡 Hint
Look carefully at the quotes and dashes in the log_format string.
Configuration
intermediate
2: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?
Alog_format timed '$remote_addr - $request_time';
Blog_format timed '$remote_addr - $request_time ms';
Clog_format timed '$remote_addr - $request_time seconds';
Dlog_format timed '$remote_addr - $request_time'; # $request_time is in seconds with milliseconds
Attempts:
2 left
💡 Hint
Remember that $request_time already includes seconds with milliseconds as a decimal number.
Troubleshoot
advanced
2: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;
AThe variable $request_uri is invalid in log_format and causes failure.
BMissing closing single quote in the log_format directive causes a syntax error.
CThe access_log path is incorrect and prevents nginx from starting.
DThe log_format name 'broken' is a reserved keyword and cannot be used.
Attempts:
2 left
💡 Hint
Check the quotes carefully in the log_format directive.
🔀 Workflow
advanced
2: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?
A3,1,2,4
B1,3,2,4
C3,2,1,4
D1,2,3,4
Attempts:
2 left
💡 Hint
You must edit config before testing syntax.
Best Practice
expert
2: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?
Alog_format balanced '$remote_addr - $request_method "$request_uri" $status $request_time';
Blog_format balanced '$remote_addr - $request_method "$request_uri" $status $request_time "$http_user_agent" "$http_cookie"';
Clog_format balanced '$remote_addr - $request_method "$request_uri" $status $request_time $request_length';
Dlog_format balanced '$remote_addr - $request_method "$request_uri" $status $request_time "$http_referer"';
Attempts:
2 left
💡 Hint
Avoid logging headers or cookies to reduce log size.