+/** cleans a loglevel name from leading paths and suffixes */
+static char *clean_name(const char *name, int len, char *namebuf, int buflen)
+{
+ char *p = namebuf;
+ char *start = namebuf;
+ if (buflen <len)
+ len = buflen;
+ strncpy(namebuf, name, len);
+ namebuf[len] = '\0';
+ while ((p = strchr(start,'/')))
+ start = p+1;
+ if ((p = strrchr(start,'.')))
+ *p = '\0';
+ return start;
+
+}
+
+static int define_module_bit(const char *name)
+{
+ int i;
+ for (i = 0; mask_names[i].name; i++)
+ ;
+ if ( (i>=MAX_MASK_NAMES) || (next_log_bit >= 1<<31 ))
+ {
+ yaz_log(LOG_WARN,"No more log bits left, not logging '%s'", name);
+ return 0;
+ }
+ mask_names[i].mask = next_log_bit;
+ next_log_bit = next_log_bit<<1;
+ mask_names[i].name = xstrdup(name);
+ mask_names[i+1].name = NULL;
+ mask_names[i+1].mask = 0;
+ return mask_names[i].mask;
+}
+
+int yaz_log_module_level(const char *name)
+{
+ int i;
+ char clean[255];
+ char *n = clean_name(name, strlen(name), clean, sizeof(clean));
+ for (i = 0; mask_names[i].name; i++)
+ if (0==strcmp(n,mask_names[i].name))
+ return mask_names[i].mask;
+ return 0;
+}
+