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 Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "JackError.h"
25 #include "JackGlobals.h"
26 #include "JackMessageBuffer.h"
30 static bool change_thread_log_function(jack_log_function_t log_function
)
32 return (jack_tls_get(JackGlobals::fKeyLogFunction
) == NULL
33 && jack_tls_set(JackGlobals::fKeyLogFunction
, (void*)log_function
));
36 SERVER_EXPORT
int set_threaded_log_function()
38 return change_thread_log_function(JackMessageBufferAdd
);
41 void jack_log_function(int level
, const char *message
)
43 void (* log_callback
)(const char *);
48 log_callback
= jack_info_callback
;
51 log_callback
= jack_error_callback
;
57 log_callback(message
);
60 static void jack_format_and_log(int level
, const char *prefix
, const char *fmt
, va_list ap
)
64 jack_log_function_t log_function
;
69 memcpy(buffer
, prefix
, len
);
74 vsnprintf(buffer
+ len
, sizeof(buffer
) - len
, fmt
, ap
);
76 log_function
= (jack_log_function_t
)jack_tls_get(JackGlobals::fKeyLogFunction
);
78 /* if log function is not overridden for thread, use default one */
79 if (log_function
== NULL
)
81 log_function
= jack_log_function
;
82 //log_function(LOG_LEVEL_INFO, "------ Using default log function");
86 //log_function(LOG_LEVEL_INFO, "++++++ Using thread-specific log function");
89 log_function(level
, buffer
);
92 SERVER_EXPORT
void jack_error(const char *fmt
, ...)
96 jack_format_and_log(LOG_LEVEL_ERROR
, NULL
, fmt
, ap
);
100 SERVER_EXPORT
void jack_info(const char *fmt
, ...)
104 jack_format_and_log(LOG_LEVEL_INFO
, NULL
, fmt
, ap
);
108 SERVER_EXPORT
void jack_log(const char *fmt
,...)
110 if (JackGlobals::fVerbose
) {
113 jack_format_and_log(LOG_LEVEL_INFO
, "Jack: ", fmt
, ap
);
118 SERVER_EXPORT
void default_jack_error_callback(const char *desc
)
120 fprintf(stderr
, "%s\n", desc
);
124 SERVER_EXPORT
void default_jack_info_callback(const char *desc
)
126 fprintf(stdout
, "%s\n", desc
);
130 SERVER_EXPORT
void silent_jack_error_callback(const char *desc
)
133 SERVER_EXPORT
void silent_jack_info_callback(const char *desc
)
136 SERVER_EXPORT
void (*jack_error_callback
)(const char *desc
) = &default_jack_error_callback
;
137 SERVER_EXPORT
void (*jack_info_callback
)(const char *desc
) = &default_jack_info_callback
;