aboutsummaryrefslogtreecommitdiff
path: root/src/rt/rust_log.h
blob: 3b40869b71c721697202e48b410fcca7f2d9d172 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef RUST_LOG_H
#define RUST_LOG_H

#define DLOG(dom, mask, ...)                         \
  do {                                               \
    rust_dom *_dom = dom;                            \
    uint32_t _mask = mask;                           \
    if ((_dom)->get_log().is_tracing(_mask)) {       \
        (_dom)->log(_mask, __VA_ARGS__);             \
    }                                                \
  } while(0)
#define LOG(task, mask, ...)                         \
  DLOG((task)->dom, mask, __VA_ARGS__)
#define LOG_I(task, mask, ...)                       \
  do {                                               \
    rust_task *_task = task;                         \
    uint32_t _mask = mask;                           \
    if ((_task)->dom->get_log().is_tracing(_mask)) { \
      (_task)->dom->get_log().reset_indent(0);       \
      (_task)->dom->log(_mask, __VA_ARGS__);         \
      (_task)->dom->get_log().indent();              \
    }                                                \
  } while(0)
#define LOGPTR(dom, msg, ptrval)                     \
  DLOG(dom, rust_log::MEM, "%s 0x%" PRIxPTR, msg, ptrval)

class rust_dom;
class rust_task;

class rust_log {

public:
    rust_log(rust_srv *srv, rust_dom *dom);
    virtual ~rust_log();

    enum ansi_color {
        WHITE,
        RED,
        LIGHTRED,
        GREEN,
        LIGHTGREEN,
        YELLOW,
        LIGHTYELLOW,
        BLUE,
        LIGHTBLUE,
        MAGENTA,
        LIGHTMAGENTA,
        TEAL,
        LIGHTTEAL
    };

    enum log_type {
        ERR = 0x1,
        MEM = 0x2,
        COMM = 0x4,
        TASK = 0x8,
        DOM = 0x10,
        ULOG = 0x20,
        TRACE = 0x40,
        DWARF = 0x80,
        CACHE = 0x100,
        UPCALL = 0x200,
        TIMER = 0x400,
        GC = 0x800,
        STDLIB = 0x1000,
        SPECIAL = 0x2000,
        KERN = 0x4000,
        BT = 0x8000,
        ALL = 0xffffffff
    };

    void indent();
    void outdent();
    void reset_indent(uint32_t indent);
    void trace_ln(uint32_t thread_id, char *prefix, char *message);
    void trace_ln(rust_task *task, uint32_t type_bits, char *message);
    void trace_ln(rust_task *task, ansi_color color,
                  uint32_t type_bits, char *message);
    bool is_tracing(uint32_t type_bits);

private:
    rust_srv *_srv;
    rust_dom *_dom;
    uint32_t _type_bit_mask;
    bool _use_labels;
    bool _use_colors;
    uint32_t _indent;
    void trace_ln(rust_task *task, char *message);
};

inline bool
rust_log::is_tracing(uint32_t type_bits) {
    return type_bits & _type_bit_mask;
}

#endif /* RUST_LOG_H */