Source: scdebug.h


Annotated List
Files
Globals
Hierarchy
Index
/***************************************************************************
                          scdebug.h  -  description
                             -------------------
    begin                : Sun Aug 25 2002
    copyright            : (C) 2002 by Werner Schulte
    email                : werner@schulte.-ac.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef SCDEBUG_H
#define SCDEBUG_H

#define DBGFULLLINE 0 // print the full line transferd by program
#define DBGBASENAME 1 // strip the leading path from filename

#define DBGSTDOUT   0x01 // print to stdout
#define DBGSYSLOG   0x02 // print to syslog

/**
  This Class provides Debug possibilities.

  @author Werner Schulte (email : werner@schulte-ac.de, homepage : www.uv-ac.de)
  @version 0.2.0 - sc - 19.10.2002
  @version 0.2.1 - sc - 12.12.2002 minor Bugfixes
  @version 0.2.2 - sc - 01.03.2003 dLevel request included

  At the moment the method doDebug writes its data,
  if debuglev (set by method setDebugLevel) is higher
  or equal then the first Argument of doDebug.

  The user may set a combination of SYSLOG or STDOUT debugging.
  For this the setDebugMode method has to be called after creating
  the class.

  Note !!
  The debugmode may be switched into different combinations during
  runtime.
  
  In case of using scdebug (linking -luvdebug), the application has always to create a
  class scdebug (whether it is used or not). You may want to do that in your main file.
  The following piece of example code shows how to implement that straight forward.

  The next paragraph shows, how to initialise Debugging

  
    #include 

    ScDebug *qwdebug;

    void main ( int argc, char *argv[] )
    {
      ScDebug *qwdebug   = new ScDebug();
      // set DebugLevel to 5 and use standard printmode and debugmode
      qwdebug->setDebugLevel( 5 );
      ...
    }
  
Here comes the example of a DebugMessage (in your code)
    #include 
    extern ScDebug *qwdebug;

    qwdebug->doDebug( 4, "%s[%d] : main(%d, %p) : start\n",
                          __FILE__, __LINE__, argc, argv );
  
The result is shown on stdout (fflushed) and looks like
    yourProgramName[203] : main ( 3, 0x80334450 ) : start
  
It is generally a good idea to switch the debuglevel of your program using a config file entry or program arguments. I am using -d level as program arguments normally. **/ class ScDebug { public: /** return the actual DebugLevel @return : the actual debuglevel **/ int dLevel( ); /** sets the actual debuglevel, which defines the limit, where debugging is stopped. All messages above debuglevel are not printed out. @p dlev : the new debuglevel **/ void setDebugLevel( int dlev = 0 ); /** sets the actual printmode actual printmodes are
    #define DBGFULLLINE 0 // print the full line transferd by program
    #define DBGBASENAME 1 // strip the leading path from filename
  
@p mode : the new printmode **/ void setDebugPrintMode( int mode = 0 ); /** sets the actual debugmode actual printmodes are
    #define DBGSTDOUT   0x01 // print to stdout
    #define DBGSYSLOG   0x02 // print to syslog
  
both values ar OR combinable. Note, that if no value is set (0x00) no debugging will take place. Nevertheless, the scdebug instance has to be instantiated. @p mode : the new debugmode **/ void setDebugMode( int mode = 1 ); /** writes a debug message to stdout, if lev is below debuglev. @p lev : the debuglevel of the actual message @p format, ... : the format string (printf-compatible) and parameters
**/ void doDebug( int lev, const char *format, ... ); /** constructor **/ ScDebug(); /** destructor **/ ~ScDebug(); private: /** strpis the leading path from the line and returnes a pointer as new format start. **/ char *getBasenameLine( char *str ); int debuglev, printmode, debugmode; }; #endif
Generated by: sc on schomep4 on Sun Nov 23 16:54:55 2003, using kdoc 2.0a54.