aboutsummaryrefslogtreecommitdiffstats
path: root/build/4coder_byp/custom/4coder_log.cpp
blob: d7175cf9e65e97aba9d7e5d95da99118839af738 (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
/*
 * Mr. 4th Dimention - Allen Webster
 *
 * 14.08.2019
 *
 * Logging helpers.
 *
 */

// TOP

#if !defined(FCODER_LOG_CPP)
#define FCODER_LOG_CPP

internal String_Const_u8
log_event(Arena *arena, String_Const_u8 event_name, String_Const_u8 src_name, i32 line_number, i32 buffer, i32 view, i32 thread_id){
  List_String_Const_u8 list = {};
  string_list_pushf(arena, &list, "%S:%d: %S", src_name, line_number, event_name);
  if (thread_id != 0){
    string_list_pushf(arena, &list, " [thread=%d]", thread_id);
  }
  if (buffer != 0){
    string_list_pushf(arena, &list, " [buffer=%d]", buffer);
  }
  if (view != 0){
    string_list_pushf(arena, &list, " [view=%d]", view);
  }
  string_list_push(arena, &list, string_u8_litexpr("\n"));
  return(string_list_flatten(arena, list));
}

#define LogEventStr(log_call, arena, B, V, T, E) \
  Stmnt(Temp_Memory temp_LOG = begin_temp(arena); \
        String_Const_u8 M = log_event(arena, E, \
                                      string_u8_litexpr(__FILE__), \
                                      __LINE__, (B), (V), (T));    \
        log_call; \
        end_temp(temp_LOG); )

#define LogEventLit(log_call, arena, B, V, T, Elit) \
  LogEventStr(log_call, arena, (B), (V), (T), string_u8_litexpr(Elit))

#define LogEventF(log_call, arena, B, V, T, Ef, ...) \
  Stmnt(Temp_Memory temp_LOG_F = begin_temp(arena); \
        String_Const_u8 E = push_u8_stringf(arena, Ef, __VA_ARGS__); \
        LogEventStr(log_call, arena, B, V, T, E); \
        end_temp(temp_LOG_F); )

#endif

// BOTTOM