-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlog.h
62 lines (53 loc) · 1.72 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// (C) 2018-2024 by Folkert van Heusden
// Released under MIT license
#pragma once
#include <string>
#include "gen.h"
#if defined(ESP32)
#include "FvHNTP/FvHNTP.h"
#endif
class console;
typedef enum { ll_emerg = 0, ll_alert, ll_critical, ll_error, warning, notice, info, debug, none } log_level_t; // TODO ll_ prefix
log_level_t parse_ll(const std::string & str);
void setlogfile(const char *const lf, const log_level_t ll_file, const log_level_t ll_screen, const bool l_timestamp);
bool setloghost(const char *const host, const log_level_t ll);
void setll(const log_level_t ll_screen, const log_level_t ll_file);
void setloguid(const int uid, const int gid);
void send_syslog(const int ll, const std::string & what);
void closelog();
void dolog(const log_level_t ll, const char *fmt, ...);
void settrace(const bool on);
bool gettrace();
#if defined(ESP32)
void set_clock_reference(ntp *const ntp_);
#endif
void set_terminal(console *const cnsl);
#ifdef TURBO
#define DOLOG(ll, always, fmt, ...) do { } while(0)
#else
#if defined(ESP32)
#define DOLOG(ll, always, fmt, ...) do { \
extern log_level_t log_level_file, log_level_screen; \
\
if (always || ll <= log_level_file || ll <= log_level_screen) \
dolog(ll, fmt, ##__VA_ARGS__); \
} while(0)
#else
#define DOLOG(ll, always, fmt, ...) do { \
extern log_level_t log_level_file, log_level_screen; \
\
if (always || ll <= log_level_file || ll <= log_level_screen) [[unlikely]] \
dolog(ll, fmt, ##__VA_ARGS__); \
} while(0)
#endif
#endif
#ifdef TURBO
#define TRACE(fmt, ...) do { } while(0)
#else
#define TRACE(fmt, ...) do { \
extern bool log_trace_enabled; \
if (log_trace_enabled) { \
dolog(debug, fmt, ##__VA_ARGS__); \
} \
} while(0)
#endif