[c7844d8] | 1 | /* |
---|
| 2 | Copyright (C) 2016 Paul Brossier <piem@aubio.org> |
---|
| 3 | |
---|
| 4 | This file is part of aubio. |
---|
| 5 | |
---|
| 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. |
---|
| 10 | |
---|
| 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. |
---|
| 15 | |
---|
| 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/>. |
---|
| 18 | |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #ifndef AUBIO_LOG_H |
---|
| 22 | #define AUBIO_LOG_H |
---|
| 23 | |
---|
| 24 | #ifdef __cplusplus |
---|
| 25 | extern "C" { |
---|
| 26 | #endif |
---|
| 27 | |
---|
| 28 | /** \file |
---|
| 29 | |
---|
| 30 | Logging features |
---|
| 31 | |
---|
| 32 | This file specifies ::aubio_log_set_function and |
---|
| 33 | ::aubio_log_set_level_function, which let you define one or several custom |
---|
| 34 | logging functions to redirect warnings and errors from aubio to your |
---|
| 35 | application. The custom function should have the prototype defined in |
---|
| 36 | ::aubio_log_function_t. |
---|
| 37 | |
---|
| 38 | After a call to ::aubio_log_set_level_function, ::aubio_log_reset can be used |
---|
| 39 | to reset each logging functions to the default ones. |
---|
| 40 | |
---|
| 41 | \example utils/test-log.c |
---|
| 42 | |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | /** list of logging levels */ |
---|
| 46 | enum aubio_log_level { |
---|
| 47 | AUBIO_LOG_ERR, /**< critical errors */ |
---|
| 48 | AUBIO_LOG_WRN, /**< warnings */ |
---|
| 49 | AUBIO_LOG_MSG, /**< general messages */ |
---|
| 50 | AUBIO_LOG_DBG, /**< debug messages */ |
---|
| 51 | AUBIO_LOG_LAST_LEVEL, /**< number of valid levels */ |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | /** Logging function prototype, to be passed to ::aubio_log_set_function |
---|
| 55 | |
---|
| 56 | \param level log level |
---|
| 57 | \param message text to log |
---|
| 58 | \param data optional closure used by the callback |
---|
| 59 | |
---|
| 60 | See @ref utils/test-log.c for an example of logging function. |
---|
| 61 | |
---|
| 62 | */ |
---|
| 63 | typedef void (*aubio_log_function_t)(sint_t level, const char_t *message, void |
---|
| 64 | *data); |
---|
| 65 | |
---|
| 66 | /** Set logging function for all levels |
---|
| 67 | |
---|
| 68 | \param fun the function to be used to log, of type ::aubio_log_function_t |
---|
| 69 | \param data optional closure to be passed to the function (can be NULL if |
---|
| 70 | nothing to pass) |
---|
| 71 | |
---|
| 72 | */ |
---|
| 73 | void aubio_log_set_function(aubio_log_function_t fun, void* data); |
---|
| 74 | |
---|
| 75 | /** Set logging function for a given level |
---|
| 76 | |
---|
| 77 | \param level the level for which to set the logging function |
---|
| 78 | \param fun the function to be used to log, of type ::aubio_log_function_t |
---|
| 79 | \param data optional closure to be passed to the function (can be NULL if |
---|
| 80 | nothing to pass) |
---|
| 81 | |
---|
| 82 | */ |
---|
| 83 | aubio_log_function_t aubio_log_set_level_function(sint_t level, |
---|
| 84 | aubio_log_function_t fun, void* data); |
---|
| 85 | |
---|
| 86 | /** Reset all logging functions to the default one |
---|
| 87 | |
---|
| 88 | After calling this function, the default logging function will be used to |
---|
| 89 | print error, warning, normal, and debug messages to `stdout` or `stderr`. |
---|
| 90 | |
---|
| 91 | */ |
---|
| 92 | void aubio_log_reset(void); |
---|
| 93 | |
---|
| 94 | #ifdef __cplusplus |
---|
| 95 | } |
---|
| 96 | #endif |
---|
| 97 | |
---|
| 98 | #endif /* AUBIO_LOG_H */ |
---|