1 /*******************************************************************
2 uLan Utilities Library - C library of basic reusable constructions
4 ul_logreg.c - registration of logging domains
6 (C) Copyright 2006 by Pavel Pisa - Originator
8 The uLan utilities library can be used, copied and modified under
10 - GPL - GNU General Public License
11 - LGPL - GNU Lesser General Public License
12 - MPL - Mozilla Public License
13 - and other licenses added by project originators
14 Code can be modified and re-distributed under any combination
15 of the above listed licenses. If contributor does not agree with
16 some of the licenses, he/she can delete appropriate line.
17 Warning, if you delete all lines, you are not allowed to
18 distribute source code and/or binaries utilizing code.
20 See files COPYING and README for details.
22 *******************************************************************/
27 #include <ul_logbase.h>
28 #include <ul_logreg.h>
29 #include <ul_gsacust.h>
32 typedef struct ul_log_domains_t {
33 #ifdef UL_LOG_DOMAINS_STATIC
34 /*gsa_static_array_field_t domains;*/
36 ul_log_domain_t * const* items;
39 #else /*UL_LOG_DOMAINS_STATIC*/
40 gsa_array_field_t domains;
41 #endif /*UL_LOG_DOMAINS_STATIC*/
44 typedef const char *ul_log_domains_key_t;
47 ul_log_domains_cmp_fnc(const ul_log_domains_key_t *a, const ul_log_domains_key_t *b)
52 /* Custom array declarations */
53 #ifdef UL_LOG_DOMAINS_STATIC
55 GSA_STATIC_CUST_DEC(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
56 domains, name, ul_log_domains_cmp_fnc)
58 GSA_STATIC_CUST_IMP(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
59 domains, name, ul_log_domains_cmp_fnc, 0)
61 #else /*UL_LOG_DOMAINS_STATIC*/
63 GSA_CUST_DEC(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
64 domains, name, ul_log_domains_cmp_fnc)
66 GSA_CUST_IMP(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
67 domains, name, ul_log_domains_cmp_fnc, 0)
69 #endif /*UL_LOG_DOMAINS_STATIC*/
71 ul_log_domains_t ul_log_domains;
74 extern int ul_log_cutoff_level;
76 int ul_log_domain_setlevel(const char *name, int setlevel)
80 ul_log_domains_it_t it;
81 ul_log_domain_t *domain=NULL;
86 if(setlevel>UL_LOGL_MAX)
92 all_fl=!strcmp(name,"all") || !strcmp(name,"ALL");
95 domain=ul_log_domains_find(&ul_log_domains,&name);
99 domain->level=setlevel;
101 ul_for_each_it(ul_log_domains, &ul_log_domains, it){
102 domain=ul_log_domains_it2item(&it);
103 domain->level=setlevel;
110 int ul_log_domain_getlevel(const char *name)
112 ul_log_domain_t *domain=NULL;
117 domain=ul_log_domains_find(&ul_log_domains,&name);
122 return domain->level;
125 #ifndef UL_MAX_DOMAIN_NAME
126 #define UL_MAX_DOMAIN_NAME 20
127 #endif /*UL_MAX_DOMAIN_NAME*/
129 int ul_log_domain_arg2levels(const char *arg)
134 char name[UL_MAX_DOMAIN_NAME+1];
144 while(isalnum(*p)) p++;
146 if(l>UL_MAX_DOMAIN_NAME)
147 l=UL_MAX_DOMAIN_NAME;
150 if(*p&&(*p!='.')&&(*p!='='))
155 l=strtol(r,(char**)&p,0);
156 if(!p||(p==r)||(*p&&(*p!=':')&&(*p!=',')))
158 if(ul_log_domain_setlevel(name, l)<0)
167 int ul_logreg_domain(ul_log_domain_t *domain)
169 ul_log_check_default_output();
171 domain->level=ul_log_cutoff_level;
172 return ul_log_domains_insert(&ul_log_domains,domain);
175 int ul_logreg_domains_static(ul_log_domain_t *const *domains, int count)
177 if(!ul_log_domains.domains.items && !ul_log_domains.domains.alloc_count){
178 ul_log_domains.domains.items=(void**)domains;
179 ul_log_domains.domains.count=count;
180 ul_log_check_default_output();
182 if(!(*domains)->level)
183 (*domains)->level=ul_log_cutoff_level;
189 if(ul_logreg_domain(*(domains++))<0)