yahelpers
Enhanced debugging functionality for the ya ecosystem
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
12#ifndef HELPERS_H
13#define HELPERS_H
14
15#define GENERAL_DEBUG 1
16
17#ifdef NDEBUG
18
19#undef GENERAL_DEBUG
20#define GENERAL_DEBUG 0
21
22#endif
23
24#if GENERAL_DEBUG == 1
25
26// NOTE: Requires C99
27#include <stdarg.h>
28#include <stdio.h>
29
30#include "logconstants.h"
31
34#define STRINGIFY(x) #x
35
36#define TOSTRING(x) STRINGIFY(x)
37
46#define LOG_DEBUG(formatted_string, ...) \
47 do { \
48 printf("\e[0;32m" DEBUG "( " __FILE__ ": " TOSTRING(__LINE__) " )" \
49 "\e[0m" \
50 " " formatted_string, \
51 ##__VA_ARGS__); \
52 } while (0)
53
57#define LOG_FUNCTION_CALL(fn_name) LOG_DEBUG(#fn_name " was called.\n");
58
62#define LOG_FUNCTION_BACK(fn_name) LOG_DEBUG("Back in " #fn_name "\n");
63
67#define TYPE_CALL_ADDRESS 0
68
72#define TYPE_CALL_VALUE 1
73
76#define TCA TYPE_CALL_ADDRESS
77
80#define TCV TYPE_CALL_VALUE
81
92#define LOG_PARAMETER(ordinal_number, type, type_call, fmt, ...) \
93 LOG_DEBUG(#ordinal_number " parameter (type: " #type ") with %s " fmt, \
94 (type_call == TYPE_CALL_ADDRESS ? "address" : "value"), ##__VA_ARGS__)
95
105#define LOG_RETURN(type, type_call, fmt, ...) \
106 LOG_DEBUG("Returning (type: " #type ") %s " fmt, (type_call == TYPE_CALL_ADDRESS ? "address" : "value"), \
107 ##__VA_ARGS__)
108
112#else
113
114#define LOG_DEBUG(formated_string, ...) /* Empty stub macro*/
115#define LOG_FUNCTION_CALL(fn_name) /* Empty stub macro*/
116#define LOG_FUNCTION_BACK(fn_name) /* Empty stub macro*/
117#define LOG_PARAMETER(ordinal_number, type_str, type_call, fmt, ...) /* Empty stub macro*/
118#define LOG_RETURN(type_str, type_call, fmt, ...) /* Empty stub macro*/
119
120#define TCA 0
121#define TCV 0
122
123#define TYPE_CALL_ADDRESS 0
124#define TYPE_CALL_VALUE 0
125
126#endif
127
128#endif
Various constants for the log header file.