summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_log_moderation.h
blob: ebef7fd57461c3abcda2363c3664cdb677fc490e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) NGINX, Inc.
 */

#ifndef _NXT_LOG_MODERATION_H_INCLUDED_
#define _NXT_LOG_MODERATION_H_INCLUDED_


typedef struct {
    uint32_t               level;
    uint32_t               limit;
    const char             *msg;
    nxt_thread_spinlock_t  lock;
    nxt_pid_t              pid;
    nxt_uint_t             count;
    nxt_time_t             last;
    nxt_timer_t            timer;
} nxt_log_moderation_t;


#define NXT_LOG_MODERATION  0, -1, 0, 0, NXT_TIMER


#define                                                                       \
nxt_log_moderate(_mod, _level, _log, ...)                                     \
    do {                                                                      \
        nxt_log_t  *_log_ = _log;                                             \
                                                                              \
        if (_log_->level >= (_level) && nxt_log_moderate_allow(_mod)) {       \
            _log_->handler(_level, _log_, __VA_ARGS__);                       \
        }                                                                     \
    } while (0)


nxt_bool_t nxt_log_moderate_allow(nxt_log_moderation_t *mod);


#endif /* _NXT_LOG_MODERATION_H_INCLUDED_ */