1 | #include <aubio.h> |
---|
2 | #include <stdio.h> |
---|
3 | #include "aubio_priv.h" |
---|
4 | |
---|
5 | const char_t *hdr = "CUSTOM HEADER: "; |
---|
6 | const char_t *hdr2 = "OTHER HEADER: "; |
---|
7 | |
---|
8 | /* an example of logging function that adds a custom header and prints |
---|
9 | * aubio debug messages on stdout instead of stderr */ |
---|
10 | void logging(int level, const char_t *message, void *data) { |
---|
11 | FILE *out; |
---|
12 | fprintf(stdout, "using custom logging function\n"); |
---|
13 | if (level == AUBIO_LOG_ERR) { |
---|
14 | out = stderr; |
---|
15 | } else { |
---|
16 | out = stdout; |
---|
17 | } |
---|
18 | if ((level >= 0) && (data != NULL)) { |
---|
19 | fprintf(out, "%s", (const char_t *)data); |
---|
20 | } |
---|
21 | fprintf(out, "%s", message); |
---|
22 | } |
---|
23 | |
---|
24 | int main (void) |
---|
25 | { |
---|
26 | fprintf(stdout, "### testing normal logging\n"); |
---|
27 | AUBIO_ERR("testing normal AUBIO_LOG_ERR\n"); |
---|
28 | AUBIO_WRN("testing normal AUBIO_LOG_WRN\n"); |
---|
29 | AUBIO_MSG("testing normal AUBIO_LOG_MSG\n"); |
---|
30 | AUBIO_DBG("testing normal AUBIO_LOG_DBG\n"); |
---|
31 | |
---|
32 | fprintf(stdout, "### testing with one custom function\n"); |
---|
33 | aubio_log_set_function(logging, (void *)hdr); |
---|
34 | AUBIO_ERR("testing recustom AUBIO_LOG_ERR\n"); |
---|
35 | AUBIO_WRN("testing recustom AUBIO_LOG_WRN\n"); |
---|
36 | AUBIO_MSG("testing recustom AUBIO_LOG_MSG\n"); |
---|
37 | AUBIO_DBG("testing recustom AUBIO_LOG_DBG\n"); |
---|
38 | |
---|
39 | fprintf(stdout, "### testing resetted logging\n"); |
---|
40 | aubio_log_reset(); |
---|
41 | AUBIO_ERR("testing uncustom AUBIO_LOG_ERR\n"); |
---|
42 | AUBIO_WRN("testing uncustom AUBIO_LOG_WRN\n"); |
---|
43 | AUBIO_MSG("testing uncustom AUBIO_LOG_MSG\n"); |
---|
44 | AUBIO_DBG("testing uncustom AUBIO_LOG_DBG\n"); |
---|
45 | |
---|
46 | fprintf(stdout, "### testing per level customization\n"); |
---|
47 | aubio_log_set_level_function(AUBIO_LOG_ERR, logging, (void *)hdr2); |
---|
48 | aubio_log_set_level_function(AUBIO_LOG_WRN, logging, NULL); |
---|
49 | aubio_log_set_level_function(AUBIO_LOG_MSG, logging, (void *)hdr); |
---|
50 | AUBIO_ERR("testing custom AUBIO_LOG_ERR\n"); |
---|
51 | AUBIO_WRN("testing custom AUBIO_LOG_WRN with data=NULL\n"); |
---|
52 | AUBIO_MSG("testing custom AUBIO_LOG_MSG\n"); |
---|
53 | AUBIO_DBG("testing uncustomized AUBIO_LOG_DBG\n"); |
---|
54 | |
---|
55 | return 0; |
---|
56 | } |
---|