0
0
Nginxdevops~5 mins

Conditional logging in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is conditional logging in nginx?
Conditional logging in nginx means logging requests only when certain conditions are met, like logging errors but not successful requests.
Click to reveal answer
beginner
Which nginx directive is used to control conditional logging?
The access_log directive with a condition parameter controls conditional logging.
Click to reveal answer
intermediate
How do you disable logging for requests with status code 200 in nginx?
Use access_log /path/to/log combined if=$loggable; where $loggable is 0 for status 200, for example: map $status $loggable { 200 0; default 1; } and then access_log /path/to/log combined if=$loggable;
Click to reveal answer
intermediate
What is the purpose of the map directive in conditional logging?
The map directive creates a variable based on conditions, which can be used to decide if logging should happen.
Click to reveal answer
intermediate
Can you log only error responses (status 400 and above) in nginx?
Yes, by using a map to set a variable to 1 for status codes 400 and above, then using access_log with if to log only when that variable is 1.
Click to reveal answer
Which directive controls logging in nginx?
Aaccess_log
Berror_log
Clog_format
Dserver_log
How do you disable logging for certain requests in nginx?
ARemove the log file
BUse <code>access_log off;</code> globally
CUse <code>error_log off;</code>
DUse <code>access_log /path/to/log combined if=$condition;</code>
What does the map directive do in conditional logging?
ASets log format
BDefines log file location
CCreates a variable based on conditions
DStarts the nginx server
To log only error responses (status 400+), what condition should be set?
A$status < 400
B$status >= 400
C$status = 200
D$status = 500
Which of these is a valid way to conditionally log in nginx?
Aaccess_log /var/log/nginx/access.log if=$loggable;
Berror_log /var/log/nginx/error.log if=$loggable;
Clog_format conditional;
Dserver_log conditional;
Explain how to set up conditional logging in nginx to log only requests with status codes 400 and above.
Think about how to create a variable that marks error responses and use it in access_log.
You got /3 concepts.
    Describe the role of the access_log directive and how it can be customized for conditional logging.
    Focus on how access_log controls logging and how conditions affect it.
    You got /3 concepts.