From 26f8a3fdc6886229c24f6202974459fd266f363b Mon Sep 17 00:00:00 2001 From: smolik Date: Fri, 7 Apr 2006 07:21:39 +0000 Subject: [PATCH] added support for logging, conditional compilation of ulcintf --- ulut/Makefile.omk | 26 +++++-- ulut/ul_log.h | 100 ++++++++++++++++++++++++ ulut/ul_logbase.c | 191 ++++++++++++++++++++++++++++++++++++++++++++++ ulut/ul_logbase.h | 115 ++++++++++++++++++++++++++++ ulut/ul_logbuf.c | 51 +++++++++++++ 5 files changed, 475 insertions(+), 8 deletions(-) create mode 100644 ulut/ul_log.h create mode 100644 ulut/ul_logbase.c create mode 100644 ulut/ul_logbase.h create mode 100644 ulut/ul_logbuf.c diff --git a/ulut/Makefile.omk b/ulut/Makefile.omk index cbe3820..5d65978 100644 --- a/ulut/Makefile.omk +++ b/ulut/Makefile.omk @@ -1,21 +1,25 @@ -default_CONFIG = CONFIG_OC_SOLIBS=x +default_CONFIG = CONFIG_OC_ULUT=y +default_CONFIG += CONFIG_OC_ULUTRTL=n +default_CONFIG += CONFIG_OC_SOLIBS=x -lib_LIBRARIES = ulut - -ifeq ($(CONFIG_OC_SOLIBS),y) -shared_LIBRARIES = ulut -endif +ifeq ($(CONFIG_OC_ULUT),y) 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_uniqid.h ul_dbufflog.h ul_log.h ul_logbase.h + +lib_LIBRARIES = ulut + +ifeq ($(CONFIG_OC_SOLIBS),y) +shared_LIBRARIES = ulut +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_evcbase.c ul_uniqid.c ul_dbufflog.c ul_logbase.c #ulut_SOURCES += ul_dbufflog.c @@ -27,8 +31,12 @@ ul_gavlchk_SOURCES = ul_gavlchk.c ul_gsachk_SOURCES = ul_gsachk.c ul_htimchk_SOURCES = ul_htimchk.c +endif + # RT-Linux version of build +ifeq ($(CONFIG_OC_ULUTRLT),y) + rtlinux_INCLUDES = -DUL_WITH_RTL_MALLOC rtlinux_LIBRARIES = ulutrtl @@ -65,3 +73,5 @@ kernel_HEADERS = ul_gavl.h ul_gavlcust.h \ $(rtlinux_with_malloc_HEADERS) ulutkern_SOURCES = ul_gavlprim.c ul_htimer.c ul_htimbase.c + +endif \ No newline at end of file diff --git a/ulut/ul_log.h b/ulut/ul_log.h new file mode 100644 index 0000000..5aa5fba --- /dev/null +++ b/ulut/ul_log.h @@ -0,0 +1,100 @@ +/******************************************************************* + uLan Utilities Library - C library of basic reusable constructions + + ul_log.h - standard logging facility + + (C) Copyright 2005 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 + +#define UL_LOG_CUST(log_domain) \ +\ +ul_log_domain_t log_domain; \ +\ +static inline \ +void ul_loglev(int level, const char *format, ...) UL_ATTR_PRINTF (2, 3);\ +static inline \ +void ul_vloglev(int level, const char *format, va_list ap) \ +{ \ + ul_vlog(&log_domain, level, format, ap); \ +} \ +\ +static inline \ +void ul_loglev(int level, const char *format, ...) \ +{ \ + va_list ap; \ + va_start(ap, format); \ + ul_vloglev(level, format, ap); \ + va_end(ap); \ +} \ +\ +static inline \ +void ul_logfatal(const char *format, ...) UL_ATTR_PRINTF (1, 2);\ +static inline \ +void ul_logfatal(const char *format, ...) \ +{ \ + va_list ap; \ + va_start(ap, format); \ + ul_vloglev(UL_LOGL_FATAL, format, ap); \ + va_end(ap); \ +}\ +\ +static inline \ +void ul_logerr(const char *format, ...) UL_ATTR_PRINTF (1, 2);\ +static inline \ +void ul_logerr(const char *format, ...) \ +{ \ + va_list ap; \ + va_start(ap, format); \ + ul_vloglev(UL_LOGL_ERR, format, ap); \ + va_end(ap); \ +} \ +\ +static inline \ +void ul_logmsg(const char *format, ...) UL_ATTR_PRINTF (1, 2);\ +static inline \ +void ul_logmsg(const char *format, ...) \ +{ \ + va_list ap; \ + va_start(ap, format); \ + ul_vloglev(UL_LOGL_MSG, format, ap); \ + va_end(ap); \ +} \ +\ +static inline \ +void ul_loginf(const char *format, ...) UL_ATTR_PRINTF (1, 2);\ +static inline \ +void ul_loginf(const char *format, ...) \ +{ \ + va_list ap; \ + va_start(ap, format); \ + ul_vloglev(UL_LOGL_INF, format, ap); \ + va_end(ap); \ +} \ +\ +static inline \ +void ul_logdeb(const char *format, ...) UL_ATTR_PRINTF (1, 2);\ +static inline \ +void ul_logdeb(const char *format, ...) \ +{ \ + va_list ap; \ + va_start(ap, format); \ + ul_vloglev(UL_LOGL_DEB, format, ap); \ + va_end(ap); \ +} diff --git a/ulut/ul_logbase.c b/ulut/ul_logbase.c new file mode 100644 index 0000000..9fe87bd --- /dev/null +++ b/ulut/ul_logbase.c @@ -0,0 +1,191 @@ +/******************************************************************* + uLan Utilities Library - C library of basic reusable constructions + + ul_logbase.c - base of standard logging facility + + (C) Copyright 2003 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. + + *******************************************************************/ + +#ifndef __RTL__ + +#include +#include +#include +#include + +#else /*__RTL__*/ + +#include +#include +#include +#include + +#endif /*__RTL__*/ + +#include "ul_utdefs.h" +#include "ul_logbase.h" + + +int ul_debug_flg; +int ul_log_cutoff_level; + +#ifdef UL_LOG_NOINLINE + +int ul_log_cond(ul_log_domain_t *domain, int level) +{ + if(!domain || (level > UL_LOGL_MAX)) + return 0; + return level <= domain->level; +} + +void ul_vlog(ul_log_domain_t *domain, int level, + const char *format, va_list ap) +{ + if(!ul_log_cond(domain,level)) + return; + ul_vlog1(domain, level, format, ap); +} + +void ul_log(ul_log_domain_t *domain, int level, + const char *format, ...) +{ + va_list ap; + + if(!ul_log_cond(domain,level)) + return; + va_start (ap, format); + ul_vlog1(domain, level, format, ap); + va_end (ap); +} + +#endif /*UL_LOG_NOINLINE*/ + + +void +ul_log_fnc_default(ul_log_domain_t *domain, int level, + const char *format, va_list ap); + +ul_log_fnc_t *ul_log_output; +#ifndef __RTL__ +FILE *ul_log_default_file; +#endif /*__RTL__*/ + +/** + * ul_log - generic logging facility for ULUT library + * @domain: pointer to domain of debugging messages + * @level: severity level + * @format: printf style format followed by arguments + * + * This functions is used for logging of various events. + * If not overridden by application, logged messages goes to the stderr. + * Environment variable %UL_LOG_FILENAME can be used to redirect + * output to file. Environment variable %UL_DEBUG_FLG can be used + * to select different set of logged events through ul_debug_flg. + * + * Note: There is a global variable %ul_log_cutoff_level. + * Only the messages with %level <= %ul_log_cutoff_level will be logged. + */ + +void +ul_log1(ul_log_domain_t *domain, int level, + const char *format, ...) +{ + va_list ap; + va_start(ap, format); + ul_vlog1(domain,level,format,ap); + va_end(ap); +} + +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_output)(domain,level,format,ap); +} + +/** + * ul_log_redir - redirects default log output function + * @log_fnc: new log output function. Value NULL resets + * to default function + * @add_flags: some more flags + */ + +void +ul_log_redir(ul_log_fnc_t *log_fnc, int add_flags) +{ + if(log_fnc==NULL) log_fnc=ul_log_fnc_default; + ul_log_output=log_fnc; +} + +#ifndef __RTL__ +void +ul_log_fnc_default(ul_log_domain_t *domain, int level, + const char *format, va_list ap) +{ + if(!(level&UL_LOGL_CONT)) { + level&=UL_LOGL_MASK; + if(level) + fprintf(ul_log_default_file,"<%d>",level); + if(domain && domain->name) + fprintf(ul_log_default_file,"%s: ",domain->name); + } + vfprintf(ul_log_default_file, format, ap); + fflush(ul_log_default_file); +} + + +#else /*__RTL__*/ +void +ul_log_fnc_default(ul_log_domain_t *domain, int level, + const char *format, va_list ap) +{ + if(!(level&UL_LOGL_CONT)) { + level&=UL_LOGL_MASK; + if(level) + rtl_printf("<%d>",level); + if(domain && domain->name) + rtl_printf("%s: ",domain->name); + } + rtl_vprintf(format, ap); +} + +#endif /*__RTL__*/ + diff --git a/ulut/ul_logbase.h b/ulut/ul_logbase.h new file mode 100644 index 0000000..bdb94d1 --- /dev/null +++ b/ulut/ul_logbase.h @@ -0,0 +1,115 @@ +/******************************************************************* + uLan Utilities Library - C library of basic reusable constructions + + ul_logbase.h - base of standard logging facility + + (C) Copyright 2005 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. + + *******************************************************************/ + +#ifndef _UL_LOGBASE_H +#define _UL_LOGBASE_H + +#include +#include "ul_utdefs.h" + +#define UL_LOGL_MASK (0xff) +#define UL_LOGL_CONT (0x1000) + +#define UL_LOGL_FATAL 1 +#define UL_LOGL_ERR 2 +#define UL_LOGL_MSG 3 +#define UL_LOGL_INF 4 +#define UL_LOGL_DEB 5 +#define UL_LOGL_TRASH 6 + +#ifndef UL_LOGL_MAX +#define UL_LOGL_MAX 6 +#endif + +/** + * struct ul_log_domain - Loggomg domain structure + * @level: maximal enabled logging level for domain + * @name: logging domain name + * @flags: logging domain flags + */ +typedef struct ul_log_domain { + int level; + const char *name; + int flags; +} ul_log_domain_t; + +typedef void (ul_log_fnc_t)(ul_log_domain_t *domain, int level, + const char *format, va_list ap); + +void ul_log_redir(ul_log_fnc_t *log_fnc, int add_flags); + +void ul_vlog1(ul_log_domain_t *domain, int level, + const char *format, va_list ap); + +void ul_log1(ul_log_domain_t *domain, int level, + const char *format, ...) UL_ATTR_PRINTF (3, 4); + +#ifdef UL_LOG_NOINLINE + +int ul_log_cond(ul_log_domain_t *domain, int level); + +void ul_vlog(ul_log_domain_t *domain, int level, + const char *format, va_list ap); + +void ul_log(ul_log_domain_t *domain, int level, + const char *format, ...) UL_ATTR_PRINTF (3, 4); + +#else /*UL_LOG_NOINLINE*/ + +static inline +int ul_log_cond(ul_log_domain_t *domain, int level) +{ + if(!domain || (level > UL_LOGL_MAX)) + return 0; + return level <= domain->level; +} + +static inline +void ul_vlog(ul_log_domain_t *domain, int level, + const char *format, va_list ap) +{ + if(!ul_log_cond(domain,level)) + return; + ul_vlog1(domain, level, format, ap); +} + +static inline +void ul_log(ul_log_domain_t *domain, int level, + const char *format, ...) UL_ATTR_PRINTF (3, 4); + +static inline +void ul_log(ul_log_domain_t *domain, int level, + const char *format, ...) +{ + va_list ap; + + if(!ul_log_cond(domain,level)) + return; + va_start (ap, format); + ul_vlog1(domain, level, format, ap); + va_end (ap); +} + +#endif /*UL_LOG_NOINLINE*/ + +#endif /*_UL_LOGBASE_H*/ diff --git a/ulut/ul_logbuf.c b/ulut/ul_logbuf.c new file mode 100644 index 0000000..97e4b36 --- /dev/null +++ b/ulut/ul_logbuf.c @@ -0,0 +1,51 @@ +/******************************************************************* + uLan Utilities Library - C library of basic reusable constructions + + ul_logbuf.c - circular log buffer + + (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. + + *******************************************************************/ + +#ifndef __RTL__ + +#include +#include +#include +#include + +#else /*__RTL__*/ + +#include +#include +#include +#include + +#endif /*__RTL__*/ + +#include "ul_utdefs.h" +#include "ul_logbase.h" + +typedef struct ul_log_buff { + unsigned char *buf_beg; + unsigned char *buf_end; + unsigned char *ip; + unsigned char *op; +} ul_log_buff_t; + + +ul_log_domain_t *domain -- 2.39.2