[insert project logo here (125x200px max)] Navigator Mailinglists Please report any errors or ommissions you find to our `Help' mailinglist, or post a message in the Forums. Copyright and Licensing Information Snap is (c) Jonathan T. Moore, 1999-2002 and licensed under the GNU General Public License (GPL). All other parts of Splash are (c) Willem de Bruijn, 2002-2003 and licensed under the BSD Open Source License. All sourcecode is made publicly available. Acknowledgement Splash and the Splash website are hosted by SourceForge.net |
Splash - DocumentationSNMP Plus a Lightweight API for SNAP Handlingsnap_svc/d_printf.cGo to the documentation of this file.00001 /* snap-1.0. Copyright (C) 2000 by Jonathan T. Moore and Michael Hicks. 00002 * 00003 * d_printf.c: debugging messages. Can be easily compiled out by 00004 * setting the -DNDEBUG flag. Verbosity level controlled by setting 00005 * the environment variable DEBUG_LEVEL. If DEBUG_LEVEL = -1, then 00006 * _all_ debugging messages will be printed. Otherwise, only those 00007 * messages with a debug level less than DEBUG_LEVEL will be printed 00008 * (so DEBUG_LEVEL = 0 produces no messages). 00009 * 00010 * $Id: d_printf.c,v 1.1 2003/03/06 13:08:40 wdebruij Exp $ 00011 */ 00012 00013 00014 #ifdef __KERNEL__ 00015 #include <linux/kernel.h> 00016 #else 00017 #include <stdarg.h> 00018 #include <stdio.h> 00019 #include <stdlib.h> 00020 #include <string.h> 00021 #include <time.h> 00022 #include <sys/time.h> 00023 #include "d_printf.h" 00024 #endif /* __KERNEL__ */ 00025 00026 00027 int debug_level = 0; 00028 int debug_level_setp = 0; 00029 00030 void set_debug_level_int(int newdebuglvl){ 00031 #ifdef __KERNEL__ 00032 debug_level = -1; 00033 #else 00034 char *env_val; 00035 00036 sysctl_snap_debug_level = newdebuglvl; 00037 env_val = getenv("DEBUG_LEVEL"); 00038 if (env_val != NULL) { 00039 sysctl_snap_debug_level = atoi(env_val); 00040 } 00041 #endif /* __KERNEL__ */ 00042 debug_level_setp = 1; 00043 } 00044 00045 void set_debug_level(void) { 00046 set_debug_level_int(100); 00047 } 00048 00049 void d_printf(int lvl, char* fmt, ...){ 00050 va_list ap; 00051 00052 if (!debug_level_setp) { 00053 set_debug_level(); 00054 } 00055 if (sysctl_snap_debug_level == -1 || lvl <= sysctl_snap_debug_level) { 00056 va_start(ap,fmt); 00057 #ifdef __KERNEL__ 00058 /* TODO : add kernel version of gettimeofday */ 00059 printk(fmt,ap); 00060 #else 00061 #ifdef DEBUG_TIMED_ALL 00062 { 00063 struct timeval tNow; 00064 /* get the time */ 00065 gettimeofday(&tNow,NULL); 00066 fprintf(stderr,"%lu | ",(unsigned long) ((tNow.tv_sec * 1000000) + tNow.tv_usec)); 00067 } 00068 #endif 00069 vfprintf(stderr,fmt,ap); 00070 #endif /* __KERNEL__ */ 00071 va_end(ap); 00072 } 00073 } 00074 00075 void d_printf_timed(int lvl, char* fmt, ...){ 00076 va_list ap; 00077 00078 if (!debug_level_setp) { 00079 set_debug_level(); 00080 } 00081 if (sysctl_snap_debug_level == -1 || lvl <= sysctl_snap_debug_level) { 00082 va_start(ap,fmt); 00083 #ifdef __KERNEL__ 00084 /* TODO : add kernel version of gettimeofday */ 00085 printk(fmt,ap); 00086 #else 00087 { 00088 struct timeval tNow; 00089 /* get the time */ 00090 gettimeofday(&tNow,NULL); 00091 fprintf(stderr,"%lu | ",(unsigned long) ((tNow.tv_sec * 1000000) + tNow.tv_usec)); 00092 vfprintf(stderr,fmt,ap); 00093 } 00094 #endif /* __KERNEL__ */ 00095 va_end(ap); 00096 } 00097 } |