1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-11-03 04:17:20 -05:00

Feature: Implemented igloo_logmsg_get_context(), igloo_logmsg_get_message(), and igloo_logmsg_get_extra()

This commit is contained in:
Philipp Schafft 2019-07-10 10:37:39 +00:00
parent c8b7f85f76
commit e4520abf4c
2 changed files with 98 additions and 5 deletions

View File

@ -107,10 +107,52 @@ typedef unsigned long int igloo_logmsg_opt_t;
*/
igloo_logmsg_t * igloo_logmsg_new(const char *name, igloo_ro_t associated, const char *msgid, const char *cat, const char *func, const char *codefile, const ssize_t codeline, const struct timespec * ts, igloo_loglevel_t level, igloo_logmsg_opt_t options, igloo_list_t *referenced, const char *format, ...);
/* Get the context from a log message object.
*
* Any parameter but the msg parameter can be NULL if the caller is not interested in the specific value.
* In that case the value is not returned.
*
* Note: Strings are returned as pointers to internal memory. Those pointers become invalide
* once the caller releases it's reference to the message.
*
* Parameters:
* msg
* The log message to operate on.
* msgid, cat, func, codefile, codeline, ts
* Pointers to where the context should be stored.
*/
int igloo_logmsg_get_context(igloo_logmsg_t *msg, const char **msgid, const char **cat, const char **func, const char **codefile, ssize_t *codeline, struct timespec *ts);
int igloo_logmsg_get_context(igloo_logmsg_t *msg, const char **msgid, const char **cat, const char **func, const char **codefile, const ssize_t *codeline, struct timespec **ts);
/* Get the message from a log message object.
*
* Any parameter but the msg parameter can be NULL if the caller is not interested in the specific value.
* In that case the value is not returned.
*
* Note: Strings are returned as pointers to internal memory. Those pointers become invalide
* once the caller releases it's reference to the message.
*
* Parameters:
* msg
* The log message to operate on.
* level, string
* Pointers to where the message should be stored.
*/
int igloo_logmsg_get_message(igloo_logmsg_t *msg, igloo_loglevel_t *level, const char **string);
int igloo_logmsg_get_extra(igloo_logmsg_t *msg, igloo_logmsg_opt_t *options, igloo_list_t **list);
/* Get extra information from a log message object.
*
* Any parameter but the msg parameter can be NULL if the caller is not interested in the specific value.
* In that case the value is not returned.
*
* Parameters:
* msg
* The log message to operate on.
* options
* Options set on the message.
* referenced
* A list of referenced objects. A new reference to that list is returned.
*/
int igloo_logmsg_get_extra(igloo_logmsg_t *msg, igloo_logmsg_opt_t *options, igloo_list_t **referenced);
/* This creates a formater that allows writing of log messages to a logfile.
* Parameters:

View File

@ -117,9 +117,60 @@ igloo_logmsg_t * igloo_logmsg_new(const char *name, igloo_ro_t associated,
}
int igloo_logmsg_get_context(igloo_logmsg_t *msg, const char **msgid, const char **cat, const char **func, const char **codefile, const ssize_t *codeline, struct timespec **ts);
int igloo_logmsg_get_message(igloo_logmsg_t *msg, igloo_loglevel_t *level, const char **string);
int igloo_logmsg_get_extra(igloo_logmsg_t *msg, igloo_logmsg_opt_t *options, igloo_list_t **list);
#define __SETSTRING(x) \
if ((x)) { \
*(x) = msg->x; \
}
int igloo_logmsg_get_context(igloo_logmsg_t *msg, const char **msgid, const char **cat, const char **func, const char **codefile, ssize_t *codeline, struct timespec *ts)
{
if (!msg)
return -1;
__SETSTRING(msgid);
__SETSTRING(cat);
__SETSTRING(func);
__SETSTRING(codefile);
__SETSTRING(codeline);
__SETSTRING(ts);
return 0;
}
int igloo_logmsg_get_message(igloo_logmsg_t *msg, igloo_loglevel_t *level, const char **string)
{
if (!msg)
return -1;
if (level)
*level = msg->level;
__SETSTRING(string);
return 0;
}
int igloo_logmsg_get_extra(igloo_logmsg_t *msg, igloo_logmsg_opt_t *options, igloo_list_t **referenced)
{
if (!msg)
return -1;
if (options)
*options = msg->options;
if (referenced) {
if (msg->referenced) {
if (igloo_ro_ref(msg->referenced) != 0)
return -1;
*referenced = msg->referenced;
} else {
*referenced = NULL;
}
}
return 0;
}
static const char * __level2str(igloo_loglevel_t level)
{