Bug 217 - Sorted out debug. Changed syslogging and allowed debug to be compiled out.

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@1634 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
stan 2005-12-01 16:20:24 +00:00
parent 34c125cc2f
commit f56cf20b5f
3 changed files with 58 additions and 63 deletions

View File

@ -103,6 +103,22 @@ AC_ARG_WITH(webgroup,
) )
AC_SUBST(WEB_GROUP) AC_SUBST(WEB_GROUP)
ENABLE_DEBUG=yes
# Ask group for web group name:.
AC_ARG_ENABLE(debug,
[ --enable-debug=<yes|no> enable or disabled debug, default enabled],
[ENABLE_DEBUG=$enable_debug],
AC_MSG_WARN([You can call configure with the --enable-debug=<yes|no> or --disable-debug option.
This tells configure whether to compile ZoneMinder with debug included. Although debug is included
by default it is not output unless explicitly switched on elsewhere. These checks may induce a
small penalty on performance and if you are after squeezing the maximum possible performance out
of ZoneMinder you may use this switch to prevent debug from being compiled in.
e.g. --enable-debug=yes or --disable-debug])
)
if test "$enable_debug" != yes; then
AC_DEFINE(ZM_DBG_OFF,1,"Whether debug is switched off and compiled out")
fi
AC_PROG_CC AC_PROG_CC
AC_PROG_CXX AC_PROG_CXX
AC_PROG_INSTALL AC_PROG_INSTALL

View File

@ -172,7 +172,7 @@ int zmDebugPrepareLog()
if ( fclose(zm_dbg_log_fd) == -1 ) if ( fclose(zm_dbg_log_fd) == -1 )
{ {
Error(( "fclose(), error = %s",strerror(errno)) ); Error(( "fclose(), error = %s",strerror(errno)) );
return( ZM_DBG_ERROR ); return( -1 );
} }
zm_dbg_log_fd = (FILE *)NULL; zm_dbg_log_fd = (FILE *)NULL;
} }
@ -194,7 +194,7 @@ int zmDebugPrepareLog()
if( zm_dbg_log[0] && (zm_dbg_log_fd = fopen(zm_dbg_log,"w")) == (FILE *)NULL ) if( zm_dbg_log[0] && (zm_dbg_log_fd = fopen(zm_dbg_log,"w")) == (FILE *)NULL )
{ {
Error(("fopen() for %s, error = %s",zm_dbg_log,strerror(errno))); Error(("fopen() for %s, error = %s",zm_dbg_log,strerror(errno)));
return(ZM_DBG_ERROR); return( -1 );
} }
} }
@ -230,7 +230,7 @@ int zmDebugInitialise( const char *name, const char *id, int level )
if( (status = zmGetDebugEnv() ) < 0) if( (status = zmGetDebugEnv() ) < 0)
{ {
Error(( "Debug Environment Error, status = %d", status )); Error(( "Debug Environment Error, status = %d", status ));
return(ZM_DBG_ERROR); return( -1 );
} }
zmDebugPrepareLog(); zmDebugPrepareLog();
@ -245,21 +245,21 @@ int zmDebugInitialise( const char *name, const char *id, int level )
if ( sigaction( SIGUSR1, &action, &old_action ) < 0 ) if ( sigaction( SIGUSR1, &action, &old_action ) < 0 )
{ {
Error(("sigaction(), error = %s",strerror(errno))); Error(("sigaction(), error = %s",strerror(errno)));
return(ZM_DBG_ERROR); return( -1 );
} }
if ( sigaction( SIGUSR2, &action, &old_action ) < 0) if ( sigaction( SIGUSR2, &action, &old_action ) < 0)
{ {
Error(("sigaction(), error = %s",strerror(errno))); Error(("sigaction(), error = %s",strerror(errno)));
return(ZM_DBG_ERROR); return( -1 );
} }
} }
zm_dbg_running = TRUE; zm_dbg_running = TRUE;
return(ZM_DBG_OK); return( 0 );
} }
int zmDbgInit( const char *name, const char *id, int level ) int zmDbgInit( const char *name, const char *id, int level )
{ {
return((zmDebugInitialise( name, id, level ) == ZM_DBG_OK ? 0 : 1)); return( zmDebugInitialise( name, id, level ) );
} }
int zmDebugReinitialise( const char *target ) int zmDebugReinitialise( const char *target )
@ -297,7 +297,7 @@ int zmDebugReinitialise( const char *target )
if ( (status = zmGetDebugEnv() ) < 0 ) if ( (status = zmGetDebugEnv() ) < 0 )
{ {
Error(( "Debug Environment Error, status = %d", status )); Error(( "Debug Environment Error, status = %d", status ));
return(ZM_DBG_ERROR); return( -1 );
} }
zmDebugPrepareLog(); zmDebugPrepareLog();
@ -305,12 +305,12 @@ int zmDebugReinitialise( const char *target )
Info(( "New Debug Level = %d, New Debug Log = %s", zm_dbg_level, zm_dbg_log[0]?zm_dbg_log:"<none>" )); Info(( "New Debug Level = %d, New Debug Log = %s", zm_dbg_level, zm_dbg_log[0]?zm_dbg_log:"<none>" ));
} }
return(ZM_DBG_OK); return( 0 );
} }
int zmDbgReinit( const char *target ) int zmDbgReinit( const char *target )
{ {
return( (zmDebugReinitialise( target )==ZM_DBG_OK?0:1) ); return( zmDebugReinitialise( target ) );
} }
int zmDebugTerminate() int zmDebugTerminate()
@ -320,18 +320,18 @@ int zmDebugTerminate()
if ( fclose(zm_dbg_log_fd) == -1 ) if ( fclose(zm_dbg_log_fd) == -1 )
{ {
Error(( "fclose(), error = %s",strerror(errno)) ); Error(( "fclose(), error = %s",strerror(errno)) );
return( ZM_DBG_ERROR ); return( -1 );
} }
zm_dbg_log_fd = (FILE *)NULL; zm_dbg_log_fd = (FILE *)NULL;
(void) closelog(); (void) closelog();
zm_dbg_running = FALSE; zm_dbg_running = FALSE;
return( ZM_DBG_OK ); return( 0 );
} }
int zmDbgTerm() int zmDbgTerm()
{ {
return((zmDebugTerminate() == ZM_DBG_OK ? 0 : 1)); return( zmDebugTerminate() );
} }
void zmDbgSubtractTime( struct timeval * const tp1, struct timeval * const tp2 ) void zmDbgSubtractTime( struct timeval * const tp1, struct timeval * const tp2 )
@ -348,37 +348,37 @@ void zmDbgSubtractTime( struct timeval * const tp1, struct timeval * const tp2 )
} }
} }
int zmDbgPrepare( const char * const file, const int line, const int code ) int zmDbgPrepare( const char * const file, const int line, const int level )
{ {
zm_dbg_file = file; zm_dbg_file = file;
zm_dbg_line = line; zm_dbg_line = line;
zm_dbg_code = code; zm_dbg_code = level;
switch(code) switch(level)
{ {
case ZM_DBG_INF: case ZM_DBG_INF:
strcpy(zm_dbg_class,"INF"); strcpy( zm_dbg_class,"INF" );
break; break;
case ZM_DBG_WAR: case ZM_DBG_WAR:
strcpy(zm_dbg_class,"WAR"); strcpy( zm_dbg_class,"WAR" );
break; break;
case ZM_DBG_ERR: case ZM_DBG_ERR:
strcpy(zm_dbg_class,"ERR"); strcpy( zm_dbg_class,"ERR" );
break; break;
case ZM_DBG_FAT: case ZM_DBG_FAT:
strcpy(zm_dbg_class,"FAT"); strcpy( zm_dbg_class,"FAT" );
break; break;
default: default:
if(code > 0 && code <= 9) if ( level > 0 && level <= 9 )
{ {
sprintf(zm_dbg_class,"DB%d",code); sprintf( zm_dbg_class, "DB%d", level );
} }
else else
{ {
Error(("Unknown Error Code %d",code)); Error(( "Unknown Error Level %d", level ));
} }
break; break;
} }
return(code); return( level );
} }
int zmDbgOutput( const char *fstring, ... ) int zmDbgOutput( const char *fstring, ... )
@ -435,7 +435,7 @@ int zmDbgOutput( const char *fstring, ... )
} }
} }
/* For Info, Warning, Errors etc we want to log them */ /* For Info, Warning, Errors etc we want to log them */
if ( 1 || zm_dbg_code <= ZM_DBG_INF ) if ( zm_dbg_code >= ZM_DBG_SYSLOG )
{ {
switch(zm_dbg_code) switch(zm_dbg_code)
{ {
@ -449,19 +449,19 @@ int zmDbgOutput( const char *fstring, ... )
log_code = LOG_ERR; log_code = LOG_ERR;
break; break;
case ZM_DBG_FAT: case ZM_DBG_FAT:
log_code = LOG_CRIT; log_code = LOG_ERR;
break; break;
default: default:
log_code = LOG_DEBUG; log_code = LOG_DEBUG;
break; break;
} }
log_code |= LOG_LOCAL1; log_code |= LOG_DAEMON;
syslog( log_code, "%s [%s]", zm_dbg_class, zm_temp_dbg_string ); syslog( log_code, "%s [%s]", zm_dbg_class, zm_temp_dbg_string );
} }
va_end(arg_ptr); va_end(arg_ptr);
if ( zm_dbg_code == ZM_DBG_FAT ) if ( zm_dbg_code == ZM_DBG_FAT )
{ {
exit(-1); exit( -1 );
} }
return( strlen( zm_temp_dbg_string ) ); return( strlen( zm_temp_dbg_string ) );
} }

View File

@ -28,31 +28,30 @@
#define FALSE 0 #define FALSE 0
#endif #endif
/* Leve 0 and below */ /* Leave 0 and below for debug */
#define ZM_DBG_OK 0
#define ZM_DBG_SUCCESS 0
#define ZM_DBG_INFO 1
#define ZM_DBG_WARNING -1
#define ZM_DBG_ERROR -2
#define ZM_DBG_FATAL -3
#define ZM_DBG_INF 0 #define ZM_DBG_INF 0
#define ZM_DBG_WAR -1 #define ZM_DBG_WAR -1
#define ZM_DBG_ERR -2 #define ZM_DBG_ERR -2
#define ZM_DBG_FAT -3 #define ZM_DBG_FAT -3
#ifndef ZM_DBG_OFF /* Define the level at which messages go through syslog */
#define ZM_DBG_SYSLOG 0
#define zmDbgPrintf(code,params) {\ #define zmDbgPrintf(level,params) {\
if (code <= zm_dbg_level)\ if (level <= zm_dbg_level)\
{\ {\
(void) zmDbgPrepare(__FILE__,__LINE__,code);\ (void) zmDbgPrepare(__FILE__,__LINE__,level);\
(void) zmDbgOutput params;\ (void) zmDbgOutput params;\
}\ }\
} }
#define Null(params) /* Turn off debug here */
#ifndef ZM_DBG_OFF
#define Debug(level,params) zmDbgPrintf(level,params) #define Debug(level,params) zmDbgPrintf(level,params)
#else
#define Debug(level,params)
#endif
#define Info(params) zmDbgPrintf(0, params) #define Info(params) zmDbgPrintf(0, params)
#define Warning(params) zmDbgPrintf(ZM_DBG_WAR,params) #define Warning(params) zmDbgPrintf(ZM_DBG_WAR,params)
#define Error(params) zmDbgPrintf(ZM_DBG_ERR,params) #define Error(params) zmDbgPrintf(ZM_DBG_ERR,params)
@ -73,7 +72,7 @@
#define Exit(level) #define Exit(level)
#endif #endif
#define HexDump(t,n) {if(zm_dbg_level == 9) \ #define HexDump(level,t,n) {if(level<=zm_dbg_level) \
{ \ { \
int _i; \ int _i; \
int _len; \ int _len; \
@ -108,7 +107,7 @@ void zmDbgSubtractTime( struct timeval * const tp1, struct timeval * const tp2 )
int zmDbgInit( const char *name, const char *id, int level ); int zmDbgInit( const char *name, const char *id, int level );
int zmDbgReinit( const char *target ); int zmDbgReinit( const char *target );
int zmDbgTerm(void); int zmDbgTerm(void);
int zmDbgPrepare( const char * const file, const int line, const int code ); int zmDbgPrepare( const char * const file, const int line, const int level );
int zmDbgOutput( const char *fstring, ... ) __attribute__ ((format(printf, 1, 2))); int zmDbgOutput( const char *fstring, ... ) __attribute__ ((format(printf, 1, 2)));
#else #else
int zmDbgInit(); int zmDbgInit();
@ -134,23 +133,3 @@ extern int zm_dbg_add_log_id;
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif
#else
#define zmDebugInitialise(params) ZM_DBG_OK
#define zmDebugTerminate(params) ZM_DBG_OK
#define Debug(lvl,params)
#define Info(params)
#define Warning(params)
#define Error(params)
#define Fatal(params)
#define Mark()
#define Log()
#define Enter()
#define Exit()
#define zmDbgInit(name,id,level)
#define zmDbgTerm()
#endif /* !ZM_DBG_OFF */