comparison src/core/ngx_log.h @ 9299:2706b60dc225 default tip

Core: error logging rate limiting. With this change, error logging to files can be rate-limited with the "rate=" parameter. The parameter specifies allowed log messages rate to a particular file (per worker), in messages per second (m/s). By default, "rate=1000m/s" is used. Rate limiting is implemented using the "leaky bucket" method, similarly to the limit_req module. Maximum burst size is set to the number of log messages per second for each severity level, so "error" messages are logged even if the rate limit is hit by "info" messages (but not vice versa). When the limit is reached for a particular level, the "too many log messages, limiting" message is logged at this level. If debug logging is enabled, either for the particular log file or for the particular connection, rate limiting is not used.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 25 Jun 2024 22:58:56 +0300
parents af5b47569cb2
children
comparison
equal deleted inserted replaced
9298:14770557be17 9299:2706b60dc225
45 typedef u_char *(*ngx_log_handler_pt) (ngx_log_t *log, u_char *buf, size_t len); 45 typedef u_char *(*ngx_log_handler_pt) (ngx_log_t *log, u_char *buf, size_t len);
46 typedef void (*ngx_log_writer_pt) (ngx_log_t *log, ngx_uint_t level, 46 typedef void (*ngx_log_writer_pt) (ngx_log_t *log, ngx_uint_t level,
47 u_char *buf, size_t len); 47 u_char *buf, size_t len);
48 48
49 49
50 typedef struct {
51 ngx_uint_t rate;
52 ngx_atomic_t excess;
53 ngx_atomic_t last;
54 } ngx_log_limit_t;
55
56
50 struct ngx_log_s { 57 struct ngx_log_s {
51 ngx_uint_t log_level; 58 ngx_uint_t log_level;
52 ngx_open_file_t *file; 59 ngx_open_file_t *file;
53 60
54 ngx_atomic_uint_t connection; 61 ngx_atomic_uint_t connection;
64 * the static strings and in the "u_char *" case we have to override 71 * the static strings and in the "u_char *" case we have to override
65 * their types all the time 72 * their types all the time
66 */ 73 */
67 74
68 char *action; 75 char *action;
76
77 ngx_log_limit_t *limit;
69 78
70 ngx_log_t *next; 79 ngx_log_t *next;
71 }; 80 };
72 81
73 82