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.
24 #include "JackError.h"
25 #include "JackGlobals.h"
26 #include "JackMessageBuffer.h"
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 *);
50 log_callback
= jack_info_callback
;
53 log_callback
= jack_error_callback
;
59 log_callback(message
);
62 static void jack_format_and_log(int level
, const char *prefix
, const char *fmt
, va_list ap
)
66 jack_log_function_t log_function
;
70 memcpy(buffer
, prefix
, len
);
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");
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
, ...)
97 jack_format_and_log(LOG_LEVEL_ERROR
, NULL
, fmt
, ap
);
101 SERVER_EXPORT
void jack_info(const char *fmt
, ...)
105 jack_format_and_log(LOG_LEVEL_INFO
, NULL
, fmt
, ap
);
109 SERVER_EXPORT
void jack_log(const char *fmt
,...)
111 if (JackGlobals::fVerbose
) {
114 jack_format_and_log(LOG_LEVEL_INFO
, "Jack: ", fmt
, ap
);
119 SERVER_EXPORT
void default_jack_error_callback(const char *desc
)
121 fprintf(stderr
, "%s\n", desc
);
125 SERVER_EXPORT
void default_jack_info_callback(const char *desc
)
127 fprintf(stdout
, "%s\n", desc
);
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
;