Implement setting log mask string on a destination.
Improve logging docs
This commit is contained in:
+80
-8
@@ -67,12 +67,12 @@ static const struct uc_log_module g_unknown_module = {
|
||||
static SLIST_HEAD(, uc_log_destination) g_destinations;
|
||||
static int uc_log_reopen_file(struct uc_log_destination *dest);
|
||||
//Uses enum UC_LOG_LEVEL as index
|
||||
static const char *const g_debug_levels[] = {
|
||||
static const char *const g_log_levels[] = {
|
||||
"NONE",
|
||||
"DEBUG",
|
||||
"UNKNOWN_2",
|
||||
"INFO",
|
||||
"UNKNOWN_4"
|
||||
"UNKNOWN_4",
|
||||
"WARNING",
|
||||
"UNKNOWN_6",
|
||||
"ERROR"
|
||||
@@ -80,20 +80,20 @@ static const char *const g_debug_levels[] = {
|
||||
|
||||
inline const char *uc_ll_2_str(enum UC_LOG_LEVEL l)
|
||||
{
|
||||
if (l < ARRAY_SIZE(g_debug_levels)) {
|
||||
return g_debug_levels[l];
|
||||
if (l < ARRAY_SIZE(g_log_levels)) {
|
||||
return g_log_levels[l];
|
||||
} else {
|
||||
return "???";
|
||||
}
|
||||
}
|
||||
|
||||
//returns if the string is not a known log level
|
||||
static int uc_str_2_ll(const char *str)
|
||||
static int uc_str_2_ll(const char *str, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(g_debug_levels); i++) {
|
||||
if (strcmp(str, g_debug_levels[i]) == 0) {
|
||||
for (i = 0; i < ARRAY_SIZE(g_log_levels); i++) {
|
||||
if (strncasecmp(str, g_log_levels[i], len) == 0) {
|
||||
return (int)i;
|
||||
}
|
||||
}
|
||||
@@ -411,7 +411,6 @@ static inline void uc_vlog_file(const struct uc_log_args *args, const char *fmt,
|
||||
|
||||
time_buf[sizeof time_buf -1] = 0;
|
||||
|
||||
|
||||
if (dest->log_location) {
|
||||
fprintf(dest->type.file.file, "[%-7s] %s %s:%d [%s] : ",
|
||||
uc_ll_2_str(args->log_level), time_buf, args->file,
|
||||
@@ -467,6 +466,79 @@ log:
|
||||
}
|
||||
}
|
||||
|
||||
void uc_log_destination_set_module_loglevel(
|
||||
struct uc_log_destination *dest,
|
||||
int module,
|
||||
enum UC_LOG_LEVEL log_level
|
||||
)
|
||||
{
|
||||
if (dest == NULL)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&g_log_lock);
|
||||
|
||||
if (module >= 0 && module < g_modules.cnt)
|
||||
dest->module_settings[module].log_level = log_level;
|
||||
|
||||
pthread_mutex_unlock(&g_log_lock);
|
||||
}
|
||||
|
||||
|
||||
void uc_log_destination_set_mask(
|
||||
struct uc_log_destination *dest,
|
||||
const char *log_mask
|
||||
)
|
||||
{
|
||||
size_t module_len;
|
||||
|
||||
if (dest == NULL || log_mask == NULL)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&g_log_lock);
|
||||
|
||||
while ((module_len = strcspn(log_mask, "=")) != 0) {
|
||||
int i;
|
||||
int level_len;
|
||||
const char *level_str;
|
||||
int log_level;
|
||||
const char *module_str = log_mask;
|
||||
|
||||
log_mask += module_len;
|
||||
if (log_mask[0] == '=')
|
||||
log_mask++;
|
||||
|
||||
level_len = strcspn(log_mask, ":");
|
||||
if (level_len == 0)
|
||||
continue;
|
||||
|
||||
level_str = log_mask;
|
||||
log_mask += level_len;
|
||||
if (log_mask[0] == ':')
|
||||
log_mask++;
|
||||
|
||||
log_level = uc_str_2_ll(level_str, level_len);
|
||||
if (log_level == -1)
|
||||
continue;
|
||||
|
||||
for (i = 0; i < g_modules.cnt; i++) {
|
||||
size_t short_name_len;;
|
||||
|
||||
if (g_modules.mods[i].short_name == NULL)
|
||||
continue;
|
||||
|
||||
short_name_len = strlen(g_modules.mods[i].short_name);
|
||||
module_len = UC_MAX(module_len, short_name_len);
|
||||
|
||||
if (strncasecmp(g_modules.mods[i].short_name,
|
||||
module_str, module_len) == 0) {
|
||||
dest->module_settings[i].log_level = log_level;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_log_lock);
|
||||
}
|
||||
|
||||
void uc_logf(int log_level, int module, int raw,
|
||||
const char *file, int line, const char *fmt, ...)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user