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)
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_CXX
AC_PROG_INSTALL

View File

@ -172,7 +172,7 @@ int zmDebugPrepareLog()
if ( fclose(zm_dbg_log_fd) == -1 )
{
Error(( "fclose(), error = %s",strerror(errno)) );
return( ZM_DBG_ERROR );
return( -1 );
}
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 )
{
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)
{
Error(( "Debug Environment Error, status = %d", status ));
return(ZM_DBG_ERROR);
return( -1 );
}
zmDebugPrepareLog();
@ -245,21 +245,21 @@ int zmDebugInitialise( const char *name, const char *id, int level )
if ( sigaction( SIGUSR1, &action, &old_action ) < 0 )
{
Error(("sigaction(), error = %s",strerror(errno)));
return(ZM_DBG_ERROR);
return( -1 );
}
if ( sigaction( SIGUSR2, &action, &old_action ) < 0)
{
Error(("sigaction(), error = %s",strerror(errno)));
return(ZM_DBG_ERROR);
return( -1 );
}
}
zm_dbg_running = TRUE;
return(ZM_DBG_OK);
return( 0 );
}
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 )
@ -297,7 +297,7 @@ int zmDebugReinitialise( const char *target )
if ( (status = zmGetDebugEnv() ) < 0 )
{
Error(( "Debug Environment Error, status = %d", status ));
return(ZM_DBG_ERROR);
return( -1 );
}
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>" ));
}
return(ZM_DBG_OK);
return( 0 );
}
int zmDbgReinit( const char *target )
{
return( (zmDebugReinitialise( target )==ZM_DBG_OK?0:1) );
return( zmDebugReinitialise( target ) );
}
int zmDebugTerminate()
@ -320,18 +320,18 @@ int zmDebugTerminate()
if ( fclose(zm_dbg_log_fd) == -1 )
{
Error(( "fclose(), error = %s",strerror(errno)) );
return( ZM_DBG_ERROR );
return( -1 );
}
zm_dbg_log_fd = (FILE *)NULL;
(void) closelog();
zm_dbg_running = FALSE;
return( ZM_DBG_OK );
return( 0 );
}
int zmDbgTerm()
{
return((zmDebugTerminate() == ZM_DBG_OK ? 0 : 1));
return( zmDebugTerminate() );
}
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_line = line;
zm_dbg_code = code;
switch(code)
zm_dbg_code = level;
switch(level)
{
case ZM_DBG_INF:
strcpy(zm_dbg_class,"INF");
strcpy( zm_dbg_class,"INF" );
break;
case ZM_DBG_WAR:
strcpy(zm_dbg_class,"WAR");
strcpy( zm_dbg_class,"WAR" );
break;
case ZM_DBG_ERR:
strcpy(zm_dbg_class,"ERR");
strcpy( zm_dbg_class,"ERR" );
break;
case ZM_DBG_FAT:
strcpy(zm_dbg_class,"FAT");
strcpy( zm_dbg_class,"FAT" );
break;
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
{
Error(("Unknown Error Code %d",code));
Error(( "Unknown Error Level %d", level ));
}
break;
}
return(code);
return( level );
}
int zmDbgOutput( const char *fstring, ... )
@ -435,7 +435,7 @@ int zmDbgOutput( const char *fstring, ... )
}
}
/* 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)
{
@ -449,19 +449,19 @@ int zmDbgOutput( const char *fstring, ... )
log_code = LOG_ERR;
break;
case ZM_DBG_FAT:
log_code = LOG_CRIT;
log_code = LOG_ERR;
break;
default:
log_code = LOG_DEBUG;
break;
}
log_code |= LOG_LOCAL1;
log_code |= LOG_DAEMON;
syslog( log_code, "%s [%s]", zm_dbg_class, zm_temp_dbg_string );
}
va_end(arg_ptr);
if ( zm_dbg_code == ZM_DBG_FAT )
{
exit(-1);
exit( -1 );
}
return( strlen( zm_temp_dbg_string ) );
}

View File

@ -28,31 +28,30 @@
#define FALSE 0
#endif
/* Leve 0 and below */
#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
/* Leave 0 and below for debug */
#define ZM_DBG_INF 0
#define ZM_DBG_WAR -1
#define ZM_DBG_ERR -2
#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) {\
if (code <= zm_dbg_level)\
#define zmDbgPrintf(level,params) {\
if (level <= zm_dbg_level)\
{\
(void) zmDbgPrepare(__FILE__,__LINE__,code);\
(void) zmDbgPrepare(__FILE__,__LINE__,level);\
(void) zmDbgOutput params;\
}\
}
#define Null(params)
/* Turn off debug here */
#ifndef ZM_DBG_OFF
#define Debug(level,params) zmDbgPrintf(level,params)
#else
#define Debug(level,params)
#endif
#define Info(params) zmDbgPrintf(0, params)
#define Warning(params) zmDbgPrintf(ZM_DBG_WAR,params)
#define Error(params) zmDbgPrintf(ZM_DBG_ERR,params)
@ -73,7 +72,7 @@
#define Exit(level)
#endif
#define HexDump(t,n) {if(zm_dbg_level == 9) \
#define HexDump(level,t,n) {if(level<=zm_dbg_level) \
{ \
int _i; \
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 zmDbgReinit( const char *target );
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)));
#else
int zmDbgInit();
@ -134,23 +133,3 @@ extern int zm_dbg_add_log_id;
#ifdef __cplusplus
} /* extern "C" */
#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 */