2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
4 Copyright (C) 2008 Nedko Arnaudov
5 Copyright (C) 2013 Samsung Electronics
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #include "JackError.h"
26 #include "JackGlobals.h"
27 #include "JackMessageBuffer.h"
29 #define LOG_BUF_SIZE 1024
32 #define LOG_TAG "JackAudioServer"
34 #define LOG_TAG "JackAudioClient"
36 #include <utils/Log.h>
40 static bool change_thread_log_function(jack_log_function_t log_function
)
42 return (jack_tls_get(JackGlobals::fKeyLogFunction
) == NULL
43 && jack_tls_set(JackGlobals::fKeyLogFunction
, (void*)log_function
));
46 SERVER_EXPORT
int set_threaded_log_function()
48 return change_thread_log_function(JackMessageBufferAdd
);
51 void jack_log_function(int level
, const char *message
)
53 void (* log_callback
)(const char *);
58 log_callback
= jack_info_callback
;
61 log_callback
= jack_error_callback
;
67 log_callback(message
);
70 static void jack_format_and_log(int level
, const char *prefix
, const char *fmt
, va_list ap
)
74 jack_log_function_t log_function
;
79 memcpy(buffer
, prefix
, len
);
84 vsnprintf(buffer
+ len
, sizeof(buffer
) - len
, fmt
, ap
);
86 log_function
= (jack_log_function_t
)jack_tls_get(JackGlobals::fKeyLogFunction
);
88 /* if log function is not overridden for thread, use default one */
89 if (log_function
== NULL
)
91 log_function
= jack_log_function
;
92 //log_function(LOG_LEVEL_INFO, "------ Using default log function");
96 //log_function(LOG_LEVEL_INFO, "++++++ Using thread-specific log function");
99 log_function(level
, buffer
);
102 SERVER_EXPORT
void jack_error(const char *fmt
, ...)
105 char buf
[LOG_BUF_SIZE
];
107 vsnprintf(buf
, LOG_BUF_SIZE
, fmt
, ap
);
109 __android_log_write(ANDROID_LOG_ERROR
, LOG_TAG
, buf
);
112 SERVER_EXPORT
void jack_info(const char *fmt
, ...)
115 char buf
[LOG_BUF_SIZE
];
117 vsnprintf(buf
, LOG_BUF_SIZE
, fmt
, ap
);
119 __android_log_write(ANDROID_LOG_INFO
, LOG_TAG
, buf
);
122 SERVER_EXPORT
void jack_log(const char *fmt
,...)
125 char buf
[LOG_BUF_SIZE
];
126 if (JackGlobals::fVerbose
) {
128 vsnprintf(buf
, LOG_BUF_SIZE
, fmt
, ap
);
130 __android_log_write(ANDROID_LOG_VERBOSE
, LOG_TAG
, buf
);
134 SERVER_EXPORT
void default_jack_error_callback(const char *desc
)
136 fprintf(stderr
, "%s\n", desc
);
140 SERVER_EXPORT
void default_jack_info_callback(const char *desc
)
142 fprintf(stdout
, "%s\n", desc
);
146 SERVER_EXPORT
void silent_jack_error_callback(const char *desc
)
149 SERVER_EXPORT
void silent_jack_info_callback(const char *desc
)
152 SERVER_EXPORT
void (*jack_error_callback
)(const char *desc
) = &default_jack_error_callback
;
153 SERVER_EXPORT
void (*jack_info_callback
)(const char *desc
) = &default_jack_info_callback
;