PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/rt/rust_log.h

http://github.com/jruderman/rust
C Header | 76 lines | 63 code | 12 blank | 1 comment | 5 complexity | 44251e6443cefdb3a63235d4b11864b6 MD5 | raw file
 1// -*- c++ -*-
 2#ifndef RUST_LOG_H
 3#define RUST_LOG_H
 4
 5#include "rust_globals.h"
 6
 7const uint32_t log_err = 0;
 8const uint32_t log_warn = 1;
 9const uint32_t log_info = 2;
10const uint32_t log_debug = 3;
11
12#define LOG(task, field, ...)                                   \
13    DLOG_LVL(log_debug, task, task->sched_loop, field, __VA_ARGS__)
14#define LOG_ERR(task, field, ...)                               \
15    DLOG_LVL(log_err, task, task->sched_loop, field, __VA_ARGS__)
16#define DLOG(sched_loop, field, ...)                                   \
17    DLOG_LVL(log_debug, NULL, sched_loop, field, __VA_ARGS__)
18#define DLOG_ERR(sched_loop, field, ...)                               \
19    DLOG_LVL(log_err, NULL, sched_loop, field, __VA_ARGS__)
20#define LOGPTR(sched_loop, msg, ptrval)                                \
21    DLOG_LVL(log_debug, NULL, sched_loop, mem, "%s 0x%" PRIxPTR, msg, ptrval)
22#define DLOG_LVL(lvl, task, sched_loop, field, ...)                    \
23    do {                                                        \
24        rust_sched_loop* _d_ = sched_loop;                      \
25        if (log_rt_##field >= lvl && _d_->log_lvl >= lvl) {     \
26            _d_->get_log().log(task, lvl, __VA_ARGS__);         \
27        }                                                       \
28    } while (0)
29
30#define KLOG(k, field, ...) \
31    KLOG_LVL(k, field, log_debug, __VA_ARGS__)
32#define KLOG_LVL(k, field, lvl, ...)                          \
33    do {                                                      \
34        if (log_rt_##field >= lvl) {                          \
35            (k)->log(lvl, __VA_ARGS__);                       \
36        }                                                     \
37    } while (0)
38
39struct rust_sched_loop;
40struct rust_task;
41
42class rust_log {
43
44public:
45    rust_log(rust_sched_loop *sched_loop);
46    virtual ~rust_log();
47
48    void log(rust_task* task, uint32_t level, char const *fmt, ...);
49    void trace_ln(rust_task *task, uint32_t level, char *message);
50    void trace_ln(char *prefix, char *message);
51    bool is_tracing(uint32_t type_bits);
52
53private:
54    rust_sched_loop *_sched_loop;
55    bool _use_labels;
56    void trace_ln(rust_task *task, char *message);
57};
58
59void update_log_settings(void* crate_map, char* settings);
60
61extern uint32_t log_rt_mem;
62extern uint32_t log_rt_box;
63extern uint32_t log_rt_comm;
64extern uint32_t log_rt_task;
65extern uint32_t log_rt_dom;
66extern uint32_t log_rt_trace;
67extern uint32_t log_rt_cache;
68extern uint32_t log_rt_upcall;
69extern uint32_t log_rt_timer;
70extern uint32_t log_rt_gc;
71extern uint32_t log_rt_stdlib;
72extern uint32_t log_rt_kern;
73extern uint32_t log_rt_backtrace;
74extern uint32_t log_rt_callback;
75
76#endif /* RUST_LOG_H */