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 *******************************************************************/
25 #include <ul_logbase.h>
26 #include <ul_logreg.h>
27 #include <ul_gsacust.h>
30 typedef struct ul_log_domains_t {
31 #ifdef UL_LOG_DOMAINS_STATIC
32 /*gsa_static_array_field_t domains;*/
34 ul_log_domain_t * const* items;
37 #else /*UL_LOG_DOMAINS_STATIC*/
38 gsa_array_field_t domains;
39 #endif /*UL_LOG_DOMAINS_STATIC*/
42 typedef const char *ul_log_domains_key_t;
45 ul_log_domains_cmp_fnc(const ul_log_domains_key_t *a, const ul_log_domains_key_t *b)
50 /* Custom array declarations */
51 #ifdef UL_LOG_DOMAINS_STATIC
53 GSA_STATIC_CUST_DEC(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
54 domains, name, ul_log_domains_cmp_fnc)
56 GSA_STATIC_CUST_IMP(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
57 domains, name, ul_log_domains_cmp_fnc, 0)
59 #else /*UL_LOG_DOMAINS_STATIC*/
61 GSA_CUST_DEC(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
62 domains, name, ul_log_domains_cmp_fnc)
64 GSA_CUST_IMP(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
65 domains, name, ul_log_domains_cmp_fnc, 0)
67 #endif /*UL_LOG_DOMAINS_STATIC*/
69 ul_log_domains_t ul_log_domains;
72 extern int ul_log_cutoff_level;
74 int ul_log_domain_setlevel(const char *name, int setlevel)
78 ul_log_domains_it_t it;
79 ul_log_domain_t *domain=NULL;
81 if((setlevel<0) || (setlevel>UL_LOGL_MAX))
87 all_fl=!strcmp(name,"all");
90 domain=ul_log_domains_find(&ul_log_domains,&name);
94 domain->level=setlevel;
96 ul_for_each_it(ul_log_domains, &ul_log_domains, it){
97 domain=ul_log_domains_it2item(&it);
98 domain->level=setlevel;
105 int ul_log_domain_getlevel(const char *name)
107 ul_log_domain_t *domain=NULL;
112 domain=ul_log_domains_find(&ul_log_domains,&name);
117 return domain->level;
120 int ul_logreg_domain(ul_log_domain_t *domain)
122 ul_log_check_default_output();
124 domain->level=ul_log_cutoff_level;
125 return ul_log_domains_insert(&ul_log_domains,domain);
128 int ul_logreg_domains_static(ul_log_domain_t *const *domains, int count)
130 if(!ul_log_domains.domains.items && !ul_log_domains.domains.alloc_count){
131 ul_log_domains.domains.items=(void**)domains;
132 ul_log_domains.domains.count=count;
133 ul_log_check_default_output();
135 if(!(*domains)->level)
136 (*domains)->level=ul_log_cutoff_level;
142 if(ul_logreg_domain(*(domains++))<0)