forked from facebook/watchman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchman_log.h
49 lines (40 loc) · 1.4 KB
/
watchman_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
/* Copyright 2012-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
#ifndef WATCHMAN_LOG_H
#define WATCHMAN_LOG_H
// Helpers for pasting __LINE__ for symbol generation
#define w_paste2(pre, post) pre ## post
#define w_paste1(pre, post) w_paste2(pre, post)
#define w_gen_symbol(pre) w_paste1(pre, __LINE__)
#define W_LOG_OFF 0
#define W_LOG_ERR 1
#define W_LOG_DBG 2
#define W_LOG_FATAL -1
#ifndef WATCHMAN_FMT_STRING
# define WATCHMAN_FMT_STRING(x) x
#endif
extern int log_level;
extern char *log_name;
const char *w_set_thread_name(const char *fmt, ...);
const char *w_get_thread_name(void);
void w_setup_signal_handlers(void);
void w_log(int level, WATCHMAN_FMT_STRING(const char *fmt), ...)
#ifdef __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
;
#define w_check(e, ...) \
if (!(e)) { \
w_log(W_LOG_ERR, "%s:%u failed assertion `%s'\n", __FILE__, __LINE__, #e); \
w_log(W_LOG_FATAL, __VA_ARGS__); \
}
// Similar to assert(), but uses W_LOG_FATAL to log the stack trace
// before giving up the ghost
#ifdef NDEBUG
# define w_assert(e, ...) ((void)0)
#else
#define w_assert(e, ...) w_check(e, __VA_ARGS__)
#endif
bool w_should_log_to_clients(int level);
void w_log_to_clients(int level, const char *buf);
#endif