]> rtime.felk.cvut.cz Git - ulut.git/commitdiff
Provided generic code to maintain and register log domains.
authorppisa <ppisa>
Fri, 28 Jul 2006 12:51:27 +0000 (12:51 +0000)
committerppisa <ppisa>
Fri, 28 Jul 2006 12:51:27 +0000 (12:51 +0000)
ulut/Makefile.omk
ulut/ul_logbase.c
ulut/ul_logbase.h
ulut/ul_logreg.c [new file with mode: 0644]
ulut/ul_logreg.h [new file with mode: 0644]

index 5d65978371ae3fff44e1f5eac4190ff40ada3cbd..ddcf5fafed87037004cd1fad55a4e53b7809bc2b 100644 (file)
@@ -8,7 +8,8 @@ include_HEADERS  = ul_dbuff.h ul_evcbase.h ul_gavl.h ul_gavlcust.h \
                ul_gavlflesint.h ul_gavlrepcust.h ul_gsa.h ul_gsacust.h \
               ul_hptree.h ul_htimdefs.h ul_htimer.h ul_itbase.h \
               ul_list.h ul_listbase.h ul_utdefs.h ul_utmalloc.h \
-              ul_uniqid.h ul_dbufflog.h ul_log.h ul_logbase.h
+              ul_uniqid.h ul_dbufflog.h ul_log.h ul_logbase.h \
+              ul_logreg.h
 
 lib_LIBRARIES = ulut
 
@@ -19,9 +20,8 @@ endif
 ulut_SOURCES = ul_dbufbase.c ul_dbufmore.c ul_gsa.c ul_gsacust.c \
                ul_gavlprim.c ul_gavl.c ul_hptree.c \
                ul_htimer.c ul_htimbase.c ul_htimmstime.c \
-               ul_evcbase.c ul_uniqid.c ul_dbufflog.c ul_logbase.c
-
-#ulut_SOURCES += ul_dbufflog.c
+               ul_evcbase.c ul_uniqid.c ul_dbufflog.c ul_logbase.c \
+              ul_logreg.c
 
 lib_LOADLIBES = ulut
 
@@ -74,4 +74,4 @@ kernel_HEADERS = ul_gavl.h ul_gavlcust.h \
 
 ulutkern_SOURCES = ul_gavlprim.c ul_htimer.c ul_htimbase.c
 
-endif
\ No newline at end of file
+endif
index 9fe87bdd4a189bd3e13312a0bb3b5d04af50ca6d..69b1d34a817230ba3b80a4d871b412cb4f32a015 100644 (file)
@@ -115,30 +115,14 @@ void
 ul_vlog1(ul_log_domain_t *domain, int level,
        const char *format, va_list ap)
 {
- #ifndef __RTL__
-  char *s;
-  char *log_fname;
- #endif /*__RTL__*/
   if(ul_log_cutoff_level) {
       if((level & UL_LOGL_MASK) > ul_log_cutoff_level) return;
   }
   if(ul_log_output==NULL) {
-    ul_log_output=ul_log_fnc_default;
-   #ifndef __RTL__
-    if((log_fname=getenv("UL_LOG_FILENAME"))!=NULL){
-      ul_log_default_file=fopen(log_fname,"a");
-    }
-    if(ul_log_default_file==NULL)
-      ul_log_default_file=stderr;
-    if(!ul_debug_flg&&((s=getenv("UL_DEBUG_FLG"))!=NULL)){
-      ul_debug_flg=atoi(s);
-    }
-    if((s = getenv("UL_LOG_CUTTOFF")) != NULL) {
-        ul_log_cutoff_level = atoi(s);
-    }
-   #endif /*__RTL__*/
+    ul_log_check_default_output();
   }
-  (*ul_log_output)(domain,level,format,ap);
+  if(ul_log_output)
+    (*ul_log_output)(domain,level,format,ap);
 }
 
 /**
@@ -189,3 +173,31 @@ ul_log_fnc_default(ul_log_domain_t *domain, int level,
 
 #endif /*__RTL__*/
 
+int
+ul_log_check_default_output(void)
+{
+ #ifndef __RTL__
+  char *s;
+  char *log_fname;
+ #endif /*__RTL__*/
+
+  if(ul_log_output!=NULL)
+    return 0;
+
+  ul_log_output=ul_log_fnc_default;
+ #ifndef __RTL__
+  if((log_fname=getenv("UL_LOG_FILENAME"))!=NULL){
+    ul_log_default_file=fopen(log_fname,"a");
+  }
+  if(ul_log_default_file==NULL)
+    ul_log_default_file=stderr;
+  if(!ul_debug_flg&&((s=getenv("UL_DEBUG_FLG"))!=NULL)){
+    ul_debug_flg=atoi(s);
+  }
+  if((s = getenv("UL_LOG_CUTTOFF")) != NULL) {
+      ul_log_cutoff_level = atoi(s);
+  }
+ #endif /*__RTL__*/
+  return 0;
+}
+
index bdb94d162a0184117f975fda909ad9b1f2db082a..3afbba75aa5f83b0865544a41eac6eda8d636bdb 100644 (file)
 #include <stdarg.h>
 #include "ul_utdefs.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define UL_LOGL_MASK (0xff)
 #define UL_LOGL_CONT (0x1000)
 
@@ -58,6 +62,8 @@ typedef void (ul_log_fnc_t)(ul_log_domain_t *domain, int level,
 
 void ul_log_redir(ul_log_fnc_t *log_fnc, int add_flags);
 
+int ul_log_check_default_output(void);
+
 void ul_vlog1(ul_log_domain_t *domain, int level,
        const char *format, va_list ap);
 
@@ -112,4 +118,8 @@ void ul_log(ul_log_domain_t *domain, int level,
 
 #endif /*UL_LOG_NOINLINE*/
 
+#ifdef __cplusplus
+} /* extern "C"*/
+#endif
+
 #endif /*_UL_LOGBASE_H*/
diff --git a/ulut/ul_logreg.c b/ulut/ul_logreg.c
new file mode 100644 (file)
index 0000000..4ab8999
--- /dev/null
@@ -0,0 +1,146 @@
+/*******************************************************************
+  uLan Utilities Library - C library of basic reusable constructions
+
+  ul_logreg.c  - registration of logging domains
+
+  (C) Copyright 2006 by Pavel Pisa - Originator
+
+  The uLan utilities library can be used, copied and modified under
+  next licenses
+    - GPL - GNU General Public License
+    - LGPL - GNU Lesser General Public License
+    - MPL - Mozilla Public License
+    - and other licenses added by project originators
+  Code can be modified and re-distributed under any combination
+  of the above listed licenses. If contributor does not agree with
+  some of the licenses, he/she can delete appropriate line.
+  Warning, if you delete all lines, you are not allowed to
+  distribute source code and/or binaries utilizing code.
+  
+  See files COPYING and README for details.
+
+ *******************************************************************/
+
+#include <string.h>
+#include <ul_logbase.h>
+#include <ul_logreg.h>
+#include <ul_gsacust.h>
+
+
+typedef struct ul_log_domains_t {
+ #ifdef UL_LOG_DOMAINS_STATIC
+  /*gsa_static_array_field_t domains;*/
+  struct {
+    ul_log_domain_t * const* items;
+    int count;
+  } domains;
+ #else /*UL_LOG_DOMAINS_STATIC*/
+  gsa_array_field_t domains;
+ #endif /*UL_LOG_DOMAINS_STATIC*/
+} ul_log_domains_t;
+
+typedef const char *ul_log_domains_key_t;
+
+inline int
+ul_log_domains_cmp_fnc(const ul_log_domains_key_t *a, const ul_log_domains_key_t *b)
+{
+  return strcmp(*a,*b);
+}
+
+/* Custom array declarations */
+#ifdef UL_LOG_DOMAINS_STATIC
+
+GSA_STATIC_CUST_DEC(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
+       domains, name, ul_log_domains_cmp_fnc)
+
+GSA_STATIC_CUST_IMP(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
+       domains, name, ul_log_domains_cmp_fnc, 0)
+
+#else /*UL_LOG_DOMAINS_STATIC*/
+
+GSA_CUST_DEC(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
+       domains, name, ul_log_domains_cmp_fnc)
+
+GSA_CUST_IMP(ul_log_domains, ul_log_domains_t, ul_log_domain_t, ul_log_domains_key_t,
+       domains, name, ul_log_domains_cmp_fnc, 0)
+
+#endif /*UL_LOG_DOMAINS_STATIC*/
+
+ul_log_domains_t ul_log_domains;
+
+/*This is not ideal*/
+extern int ul_log_cutoff_level;
+
+int ul_log_domain_setlevel(const char *name, int setlevel)
+{
+  int all_fl=0;
+
+  ul_log_domains_it_t it;
+  ul_log_domain_t *domain=NULL;
+
+  if((setlevel<0) || (setlevel>UL_LOGL_MAX))
+    return -1;
+
+  if(!name)
+    all_fl=1;
+  else
+    all_fl=!strcmp(name,"all");
+
+  if(!all_fl){
+    domain=ul_log_domains_find(&ul_log_domains,&name);
+    if(!domain){
+      return 1;
+    }
+    domain->level=setlevel;
+  }else{
+    ul_for_each_it(ul_log_domains, &ul_log_domains, it){
+      domain=ul_log_domains_it2item(&it);
+      domain->level=setlevel;
+    }
+  }
+
+  return 0;
+}
+
+int ul_log_domain_getlevel(const char *name)
+{
+  ul_log_domain_t *domain=NULL;
+
+  if(!name)
+    return -1;
+
+  domain=ul_log_domains_find(&ul_log_domains,&name);
+  if(!domain){
+    return -1;
+  }
+  
+  return domain->level;
+}
+
+int ul_logreg_domain(ul_log_domain_t *domain)
+{
+  ul_log_check_default_output();
+  if(!domain->level)
+    domain->level=ul_log_cutoff_level;
+  return ul_log_domains_insert(&ul_log_domains,domain);
+}
+
+int ul_logreg_domains_static(ul_log_domain_t *const *domains, int count)
+{
+  if(!ul_log_domains.domains.items && !ul_log_domains.domains.alloc_count){
+    ul_log_domains.domains.items=(void**)domains;
+    ul_log_domains.domains.count=count;
+    ul_log_check_default_output();
+    while(count-->0){
+      if(!(*domains)->level)
+         (*domains)->level=ul_log_cutoff_level;
+      domains++;
+    }
+    return 0;
+  }
+  while(count-->0){
+    if(ul_logreg_domain(*(domains++))<0)
+      return -1;
+  }
+  return 0;
+}
diff --git a/ulut/ul_logreg.h b/ulut/ul_logreg.h
new file mode 100644 (file)
index 0000000..aa0ca6b
--- /dev/null
@@ -0,0 +1,43 @@
+/*******************************************************************
+  uLan Utilities Library - C library of basic reusable constructions
+
+  ul_logreg.h  - registration of logging domains
+
+  (C) Copyright 2006 by Pavel Pisa - Originator
+
+  The uLan utilities library can be used, copied and modified under
+  next licenses
+    - GPL - GNU General Public License
+    - LGPL - GNU Lesser General Public License
+    - MPL - Mozilla Public License
+    - and other licenses added by project originators
+  Code can be modified and re-distributed under any combination
+  of the above listed licenses. If contributor does not agree with
+  some of the licenses, he/she can delete appropriate line.
+  Warning, if you delete all lines, you are not allowed to
+  distribute source code and/or binaries utilizing code.
+  
+  See files COPYING and README for details.
+
+ *******************************************************************/
+
+#include <ul_logbase.h>
+
+#ifndef _UL_LOGREG_H
+#define _UL_LOGREG_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int ul_log_domain_setlevel(const char *name, int setlevel);
+int ul_log_domain_getlevel(const char *name);
+
+int ul_logreg_domain(ul_log_domain_t *domain);
+int ul_logreg_domains_static(ul_log_domain_t *const *domains, int count);
+
+#ifdef __cplusplus
+} /* extern "C"*/
+#endif
+
+#endif /*_UL_LOGREG_H*/