mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-10 13:30:01 -05:00
error: add priority and interface strings to the log messages
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
7248b0c660
commit
492df4bb94
2 changed files with 68 additions and 0 deletions
|
|
@ -54,6 +54,7 @@ const char *snd_strerror(int errnum);
|
|||
#define SND_LOG_INFO 3 /**< info priority level */
|
||||
#define SND_LOG_DEBUG 4 /**< debug priority level */
|
||||
#define SND_LOG_TRACE 5 /**< trace priority level */
|
||||
#define SND_LOG_LAST SND_LOG_TRACE
|
||||
|
||||
#define SND_ILOG_CORE 1 /**< core library code */
|
||||
#define SND_ILOG_CONFIG 2 /**< configuration parsing and operations */
|
||||
|
|
@ -67,6 +68,7 @@ const char *snd_strerror(int errnum);
|
|||
#define SND_ILOG_UCM 10 /**< UCM API */
|
||||
#define SND_ILOG_TOPOLOGY 11 /**< topology API */
|
||||
#define SND_ILOG_ASERVER 12 /**< aserver */
|
||||
#define SND_ILOG_LAST SND_ILOG_ASERVER
|
||||
|
||||
/**
|
||||
* \brief Log handler callback.
|
||||
|
|
|
|||
66
src/error.c
66
src/error.c
|
|
@ -83,6 +83,61 @@ snd_lib_log_handler_t snd_lib_log_set_local(snd_lib_log_handler_t func)
|
|||
return old;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of log priority level names.
|
||||
*/
|
||||
static const char *snd_log_prio_names[SND_LOG_LAST + 1] = {
|
||||
[0] = NULL,
|
||||
[SND_LOG_ERROR] = "error",
|
||||
[SND_LOG_WARN] = "warning",
|
||||
[SND_LOG_INFO] = "info",
|
||||
[SND_LOG_DEBUG] = "debug",
|
||||
[SND_LOG_TRACE] = "trace",
|
||||
};
|
||||
|
||||
/**
|
||||
* Array of interface names.
|
||||
*/
|
||||
static const char *snd_ilog_interface_names[SND_ILOG_LAST + 1] = {
|
||||
[0] = NULL,
|
||||
[SND_ILOG_CORE] = "core",
|
||||
[SND_ILOG_CONFIG] = "config",
|
||||
[SND_ILOG_CONTROL] = "control",
|
||||
[SND_ILOG_HWDEP] = "hwdep",
|
||||
[SND_ILOG_TIMER] = "timer",
|
||||
[SND_ILOG_RAWMIDI] = "rawmidi",
|
||||
[SND_ILOG_PCM] = "pcm",
|
||||
[SND_ILOG_MIXER] = "mixer",
|
||||
[SND_ILOG_SEQUENCER] = "sequencer",
|
||||
[SND_ILOG_UCM] = "ucm",
|
||||
[SND_ILOG_TOPOLOGY] = "topology",
|
||||
[SND_ILOG_ASERVER] = "aserver",
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Function to convert log priority level to text.
|
||||
* \param prio Priority value (SND_LOG_*).
|
||||
* \return The textual representation of the priority level, or NULL if invalid.
|
||||
*/
|
||||
const char *snd_lib_log_priority(int prio)
|
||||
{
|
||||
if (prio >= 0 && prio <= SND_LOG_TRACE)
|
||||
return snd_log_prio_names[prio];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Function to convert interface code to text.
|
||||
* \param interface Interface (SND_ILOG_*).
|
||||
* \return The textual representation of the interface code, or NULL if invalid.
|
||||
*/
|
||||
const char *snd_lib_log_interface(int interface)
|
||||
{
|
||||
if (interface >= 0 && interface <= SND_ILOG_TOPOLOGY)
|
||||
return snd_ilog_interface_names[interface];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief The default log handler function.
|
||||
* \param prio Priority value (SND_LOG_*).
|
||||
|
|
@ -100,6 +155,8 @@ snd_lib_log_handler_t snd_lib_log_set_local(snd_lib_log_handler_t func)
|
|||
*/
|
||||
static void snd_lib_vlog_default(int prio, int interface, const char *file, int line, const char *function, int errcode, const char *fmt, va_list arg)
|
||||
{
|
||||
const char *text;
|
||||
|
||||
if (local_log) {
|
||||
local_log(prio, interface, file, line, function, errcode, fmt, arg);
|
||||
return;
|
||||
|
|
@ -109,6 +166,15 @@ static void snd_lib_vlog_default(int prio, int interface, const char *file, int
|
|||
return;
|
||||
}
|
||||
fprintf(stderr, "ALSA lib %s:%i:(%s) ", file, line, function);
|
||||
|
||||
text = snd_lib_log_priority(prio);
|
||||
if (text)
|
||||
fprintf(stderr, "[%s] ", text);
|
||||
|
||||
text = snd_lib_log_interface(interface);
|
||||
if (text)
|
||||
fprintf(stderr, "[%s] ", text);
|
||||
|
||||
vfprintf(stderr, fmt, arg);
|
||||
if (errcode)
|
||||
fprintf(stderr, ": %s", snd_strerror(errcode));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue