-
Notifications
You must be signed in to change notification settings - Fork 30
/
la-log.h
48 lines (40 loc) · 1.09 KB
/
la-log.h
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
41
42
43
44
45
46
47
48
#ifndef _LA_LOG_H
#define _LA_LOG_H
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#ifndef _WIN32
#include <syslog.h>
#else
#define LOG_DEBUG 0
#define LOG_INFO 1
#define LOG_ERR 2
#define LOG_CRIT 3
#endif
#include <time.h>
void la_log_syslog_open();
void la_log(int priority, const char *format, ...);
void la_log_unsuppress();
class LALog {
public:
LALog() :
_time_period_start(time(NULL))
{ }
void syslog_open();
void log(int priority, const char *format, ...);
void log_ap(int priority, const char *format, va_list ap);
void unsupress();
bool should_suppress();
bool suppressing() {return _suppressing; }
private:
// really rough rate limiting for log messages. We could keep a
// hash here of formats and selectively supress based on format.
bool _suppressing = false;
const uint8_t _time_period = 5; // seconds
const uint8_t _max_messages_per_time_period = 10;
uint32_t _suppressed_message_count = 0;
uint8_t _message_count_this_time_period = 0;
time_t _time_period_start;
bool use_syslog = false;
};
#endif