summaryrefslogtreecommitdiff
path: root/tnslc/logging.tnsl
blob: 2de326a3193ca962ea53dbca3a6bf6f2b625fc27 (plain)
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
##
## LOG UTILITIES
##

# Log levels:
# 0 - Visual queues and errors only
# 1 - Info (default)
# 2 - Debugging information (useful for me, probably less for you)
# 3 - Also logs the state changes of the log itself
int log_level = 2
int log_mode = 1

{}uint8 _log_print_one = "\0\0"
{}uint8 _log_nl = "\n\0"
{}uint8 _log_prefix = "[TNSLC] [%d] \0"

/; log_state(int new_state)
    /; if (new_state !== log_mode)
        _printf(~_log_nl{0})
    ;/
    
    log_mode = new_state
;/

/; log_err (~uint8 msg)
    log_state(0)
    _print_num(~_log_prefix{0}, log_mode)
    _printf(msg)
    _printf(~_log_nl{0})
;/

/; log_info (~uint8 msg)
    /; if (log_level > 0)
        log_state(1)
        _print_num(~_log_prefix{0}, log_mode)
        _printf(msg)
        _printf(~_log_nl{0})
    ;/
;/

/; log_vis (~uint8 msg)
    log_state(0)
    _printf(msg)
;/

/; log_debug (~uint8 msg)
    /; if (log_level > 1)
        log_state(2)
        _print_num(~_log_prefix{0}, log_mode)
        _printf(msg)
        _printf(~_log_nl{0})
    ;/
;/

# bypass logging framework (mostly for in-place debugging)

/; log_one (uint8 c)
    _log_print_one{0} = c
    _printf(~_log_print_one{0})
;/

/; log_one_nl (uint8 c)
    log_one(c)
    _printf(~_log_nl{0})
;/

/; log_num (int i)
    _print_num(~_dec{0}, i)
;/

/; log_num_nl (int i)
    _print_num(~_dec{0}, i)
    _printf(~_log_nl{0})
;/