2 Copyright (C) 2016 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
6 aubio is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 aubio is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with aubio. If not, see <http://www.gnu.org/licenses/>.
21 #include "aubio_priv.h"
24 /** array of pointers to logging functions, one per level */
25 static aubio_log_function_t aubio_log_function[AUBIO_LOG_LAST_LEVEL];
26 /** array of pointers to closure passed to logging functions, one per level */
27 static void* aubio_log_user_data[AUBIO_LOG_LAST_LEVEL];
28 /** buffer for logging messages */
29 static char aubio_log_buffer[512];
31 /** private function used by default by logging functions */
33 aubio_default_log(sint_t level, const char_t *message, void * data UNUSED)
37 if (level == AUBIO_LOG_DBG || level == AUBIO_LOG_ERR) {
40 fprintf(out, "%s", message);
45 aubio_log(sint_t level, const char_t *fmt, ...)
47 aubio_log_function_t fun = NULL;
51 vsnprintf(aubio_log_buffer, sizeof(aubio_log_buffer), fmt, args);
54 if ((level >= 0) && (level < AUBIO_LOG_LAST_LEVEL)) {
55 fun = aubio_log_function[level];
57 (*fun)(level, aubio_log_buffer, aubio_log_user_data[level]);
59 aubio_default_log(level, aubio_log_buffer, NULL);
69 for (i = 0; i < AUBIO_LOG_LAST_LEVEL; i++) {
70 aubio_log_set_level_function(i, aubio_default_log, NULL);
75 aubio_log_set_level_function(sint_t level, aubio_log_function_t fun, void * data)
77 aubio_log_function_t old = NULL;
78 if ((level >= 0) && (level < AUBIO_LOG_LAST_LEVEL)) {
79 old = aubio_log_function[level];
80 aubio_log_function[level] = fun;
81 aubio_log_user_data[level] = data;
87 aubio_log_set_function(aubio_log_function_t fun, void * data) {
89 for (i = 0; i < AUBIO_LOG_LAST_LEVEL; i++) {
90 aubio_log_set_level_function(i, fun, data);