-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_log.c
51 lines (38 loc) · 2.01 KB
/
test_log.c
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
#include <assert.h>
#include "vita/util/log.h"
int32_t main(void) {
const char *const logger_filename = "other/test_logger.log";
assert(vt_str_equals_z(vt_log_get_level_str(vt_log_fatal), "FATAL"));
// vt_log_get_level_str(vt_log_count) // fails constraint [ arg < vt_log_count ]
// --- outputs to stderr
VT_LOG_INFO("[s] This is an info test. 12345 qwerty.");
VT_LOG_WARN("[s] Testing %s formatter.", "LOG");
VT_LOG_DEBUG("[s] Testing: debugging = %s, %s", "debug msg", "debug2");
VT_LOG_ERROR("[s] Error: %s", "testing...");
// -- outputs to 'logger' file
// FIXME: fails to log to a file after setting all log_levels to that file
vt_log_redirect_all_output(logger_filename);
VT_LOG_INFO("[f] This is an info test.");
VT_LOG_WARN("[f] Testing %s formatter.", "LOG");
VT_LOG_DEBUG("[f] Testing: debugging = %s, %s", "debug msg", "debug2");
VT_LOG_ERROR("[f] Error: %s", "testing...");
// VT_LOG_FATAL("Must crash after logging this message."); // exits after logging the message
// --- set custom file to each log level
vt_log_redirect_all_output(NULL);
// vt_log_redirect_level_output(ll_info, "src/test_vt_log_info.log");
// vt_log_redirect_level_output(ll_error, "src/test_vt_log_error.log");
// --- logs to files
// int32_t a = 100;
// VT_LOG_INFO("This is an info test.");
// VT_LOG_ERROR("Error: %s", "testing...");
// VT_LOG_INFO("Logging to %s", "file");
// VT_LOG_ERROR("Error %s to file (%d)", "logging", a);
// --- prints to 'logger' file using custom file logger
VT_LOGF_INFO(logger_filename, "This is a test. %s", "Trying out new functionality.");
VT_LOGF_WARN(logger_filename, "This is a test. %s", "Trying out new functionality.");
VT_LOGF_ERROR(logger_filename, "This is a test. %s", "Trying out new functionality.");
// log assert
VT_LOG_ASSERT(1, "%s\n", "Hello, world!"); // does not print to stderr
// VT_LOG_ASSERT(0, "%s\n", "Hello, world!"); // prints to stderr, crashes
return 0;
}