source: tests/src/utils/test-log.c @ 2bf59042

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since 2bf59042 was fead41a, checked in by Paul Brossier <piem@piem.org>, 8 years ago

tests/src/utils/test-log.c: improve messages

  • Property mode set to 100644
File size: 2.2 KB
Line 
1#include <aubio.h>
2#include <stdio.h>
3#include "aubio_priv.h"
4
5const char_t *hdr = "CUSTOM HEADER: ";
6const 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 */
10void 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
24int main (void)
25{
26  fprintf(stdout, "### testing normal logging\n");
27  AUBIO_ERR("testing normal AUBIO_LOG_ERR\n");
28  AUBIO_INF("testing normal AUBIO_LOG_INF\n");
29  AUBIO_WRN("testing normal AUBIO_LOG_WRN\n");
30  AUBIO_MSG("testing normal AUBIO_LOG_MSG\n");
31  AUBIO_DBG("testing normal AUBIO_LOG_DBG\n");
32
33  fprintf(stdout, "### testing with one custom function\n");
34  aubio_log_set_function(logging, (void *)hdr);
35  AUBIO_ERR("testing custom set_function AUBIO_LOG_ERR\n");
36  AUBIO_INF("testing custom set_function AUBIO_LOG_INF\n");
37  AUBIO_WRN("testing custom set_function AUBIO_LOG_WRN\n");
38  AUBIO_MSG("testing custom set_function AUBIO_LOG_MSG\n");
39  AUBIO_DBG("testing custom set_function AUBIO_LOG_DBG\n");
40
41  fprintf(stdout, "### testing resetted logging\n");
42  aubio_log_reset();
43  AUBIO_ERR("testing again normal AUBIO_LOG_ERR\n");
44  AUBIO_INF("testing again normal AUBIO_LOG_INF\n");
45  AUBIO_WRN("testing again normal AUBIO_LOG_WRN\n");
46  AUBIO_MSG("testing again normal AUBIO_LOG_MSG\n");
47  AUBIO_DBG("testing again normal AUBIO_LOG_DBG\n");
48
49  fprintf(stdout, "### testing per level customization\n");
50  aubio_log_set_level_function(AUBIO_LOG_ERR, logging, (void *)hdr2);
51  aubio_log_set_level_function(AUBIO_LOG_WRN, logging, NULL);
52  aubio_log_set_level_function(AUBIO_LOG_MSG, logging, (void *)hdr);
53  AUBIO_ERR("testing custom set_level_function AUBIO_LOG_ERR\n");
54  AUBIO_INF("testing again normal AUBIO_LOG_INF\n");
55  AUBIO_WRN("testing custom set_level_function AUBIO_LOG_WRN with data=NULL\n");
56  AUBIO_MSG("testing custom set_level_function AUBIO_LOG_MSG\n");
57  AUBIO_DBG("testing again normal AUBIO_LOG_DBG\n");
58
59  return 0;
60}
Note: See TracBrowser for help on using the repository browser.