-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexample_logging.c
More file actions
88 lines (76 loc) · 1.72 KB
/
example_logging.c
File metadata and controls
88 lines (76 loc) · 1.72 KB
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
/**
* \file example_logging.c
*
* \brief Example usage of logging functions from c_traceback library
*/
#include <stdio.h>
#include <string.h>
#include "c_traceback.h"
#define MESSAGE_BUFFER_SIZE 256
void log_error(int i);
void log_error_level2(int i);
void log_warning(int i);
void log_warning_level2(int i);
void log_message(int i);
void log_message_level2(int i);
int main(void)
{
log_error(1);
log_warning(3);
log_message(5);
return 0;
}
void log_error(int i)
{
LOG_ERROR_FMT(
CTB_MATH_ERROR,
"(Test %d) This should be formatted error level 1 with math error",
i
);
log_error_level2(i + 1);
}
void log_error_level2(int i)
{
char message[MESSAGE_BUFFER_SIZE];
snprintf(
message,
MESSAGE_BUFFER_SIZE,
"(Test %d) This should be error level 2 with buffer error",
i
);
LOG_ERROR(CTB_BUFFER_ERROR, message);
}
void log_warning(int i)
{
LOG_WARNING_FMT(
CTB_DEPRECATION_WARNING,
"(Test %d) This should be formatted warning level 1 with deprecation "
"warning",
i
);
log_warning_level2(i + 1);
}
void log_warning_level2(int i)
{
char message[MESSAGE_BUFFER_SIZE];
snprintf(
message,
MESSAGE_BUFFER_SIZE,
"(Test %d) This should be warning level 2 with user warning",
i
);
LOG_WARNING(CTB_USER_WARNING, message);
}
void log_message(int i)
{
LOG_MESSAGE_FMT("(Test %d) This should be formatted message level 1", i);
log_message_level2(i + 1);
}
void log_message_level2(int i)
{
char message[MESSAGE_BUFFER_SIZE];
snprintf(
message, MESSAGE_BUFFER_SIZE, "(Test %d) This should be message level 2", i
);
LOG_MESSAGE(message);
}