Unused variable.
[jack2.git] / common / JackError.cpp
blob3705c35cbd1c2cd317d0d9d4d2ab117e47cd4769
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
4 Copyright (C) 2008 Nedko Arnaudov
6 This program 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 2 of the License, or
9 (at your option) any later version.
11 This program 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 this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include "JackError.h"
25 #include "JackGlobals.h"
26 #include "JackMessageBuffer.h"
28 using namespace Jack;
30 void change_thread_log_function(jack_log_function_t log_function)
32 if (!jack_tls_set(JackGlobals::fKeyLogFunction, (void*)log_function))
34 jack_error("failed to set thread log function");
38 SERVER_EXPORT void set_threaded_log_function()
40 change_thread_log_function(JackMessageBufferAdd);
43 void jack_log_function(int level, const char *message)
45 void (* log_callback)(const char *);
47 switch (level)
49 case LOG_LEVEL_INFO:
50 log_callback = jack_info_callback;
51 break;
52 case LOG_LEVEL_ERROR:
53 log_callback = jack_error_callback;
54 break;
55 default:
56 return;
59 log_callback(message);
62 static void jack_format_and_log(int level, const char *prefix, const char *fmt, va_list ap)
64 char buffer[300];
65 size_t len;
66 jack_log_function_t log_function;
68 if (prefix != NULL) {
69 len = strlen(prefix);
70 memcpy(buffer, prefix, len);
71 } else {
72 len = 0;
75 vsnprintf(buffer + len, sizeof(buffer) - len, fmt, ap);
77 log_function = (jack_log_function_t)jack_tls_get(JackGlobals::fKeyLogFunction);
79 /* if log function is not overriden for thread, use default one */
80 if (log_function == NULL)
82 log_function = jack_log_function;
83 //log_function(LOG_LEVEL_INFO, "------ Using default log function");
85 else
87 //log_function(LOG_LEVEL_INFO, "++++++ Using thread-specific log function");
90 log_function(level, buffer);
93 SERVER_EXPORT void jack_error(const char *fmt, ...)
95 va_list ap;
96 va_start(ap, fmt);
97 jack_format_and_log(LOG_LEVEL_ERROR, NULL, fmt, ap);
98 va_end(ap);
101 SERVER_EXPORT void jack_info(const char *fmt, ...)
103 va_list ap;
104 va_start(ap, fmt);
105 jack_format_and_log(LOG_LEVEL_INFO, NULL, fmt, ap);
106 va_end(ap);
109 SERVER_EXPORT void jack_log(const char *fmt,...)
111 if (JackGlobals::fVerbose) {
112 va_list ap;
113 va_start(ap, fmt);
114 jack_format_and_log(LOG_LEVEL_INFO, "Jack: ", fmt, ap);
115 va_end(ap);
119 SERVER_EXPORT void default_jack_error_callback(const char *desc)
121 fprintf(stderr, "%s\n", desc);
122 fflush(stderr);
125 SERVER_EXPORT void default_jack_info_callback(const char *desc)
127 fprintf(stdout, "%s\n", desc);
128 fflush(stdout);
131 SERVER_EXPORT void silent_jack_error_callback(const char *desc)
134 SERVER_EXPORT void silent_jack_info_callback(const char *desc)
137 SERVER_EXPORT void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
138 SERVER_EXPORT void (*jack_info_callback)(const char *desc) = &default_jack_info_callback;