MsgUtil Class Reference

#include <MsgUtil.h>

Collaboration diagram for MsgUtil:

Collaboration graph
[legend]
List of all members.

Public Types

enum  MsgType {
  TRACEMEM = 0, TRACE, VERBOSE, DEBUG,
  INFO, WARN
}

Static Public Member Functions

static void init (int argc, char **argv, const char *outFilename="runlog.txt")
static void init (const char *filename, const char *outFilename="runlog.txt")
static void setOutputMode (const bool printToFile=true, const bool printToScreen=true)
static void printMsg (const char *classname, const char *funcname, const int linenum, const MsgType type, const char *msg)
static void printfMsg (const char *classname, const char *funcname, const int linenum, const MsgType type, const char *fmt,...)
static void printAssert (const char *condition, const char *funcname, int lineNum, const char *filename)

Static Public Attributes

static const int ourNumTypes = 6
static const char * ourTypeNames [ourNumTypes]

Static Protected Member Functions

static int typeBits (const MsgType type)
static void enableClass (const char *classname, const int types)
static void setType (const char *type, const bool flag)

Static Protected Attributes

static ofstream outputFile
static bool shouldPrintToFile = true
static bool shouldPrintToScreen = true
static map< string, int > classOverrides
static int enabledTypes = 0

Detailed Description

This header defines a message logging capability. Features:

Disadvantages:

Message Levels:

Requirements to use:

Convinience macros:

File Format: If you provided a file with message level settings you can have any number of the following line types. If you have conflicting settings, the last setting will be used. You can start a line with '#' for a comment that will be ignored

Command line arguments: If you want to set message settings through the command line, you can use the -EnableType or -DisableType argument with any of the types. You can also use the argument -DebugClass with a classname.

In this mode the message system starts with WARN and INFO types turned on for all classes. The EnableType and DisableType arguments will turn on or off that message type for all classes. If a class is specified with the -DebugClass argument, that class will have all types turned on.

Debug vs Release build: To turn on the DEBUG VERBOSE TRACE and TRACEMEM message types, you have to compile with the _DEBUG_ flag set. Without this flag, the message macros will compile out.

This message system can either print to a wxMessageLog if you are using the wxWindows log (wxUSE_LOG defined; the default), or it can print to cout. If you are doing a windows application, you can setup a console to receive messages with the following code: FreeConsole(); AllocConsole(); freopen("CONIN$","rt",stdin); freopen("CONOUT$","wt",stdout); freopen("CONOUT$","wt",stderr); BringWindowToTop (GetConsoleHwnd()); SetConsoleTitle ("DrawStuff Messages");

Definition at line 114 of file MsgUtil.h.


Member Enumeration Documentation

enum MsgUtil::MsgType
 

Enumerator:
TRACEMEM 
TRACE 
VERBOSE 
DEBUG 
INFO 
WARN 

Definition at line 117 of file MsgUtil.h.


Member Function Documentation

void MsgUtil::enableClass const char *  classname,
const int  types
[static, protected]
 

turn on a class by name. This turns on the given bitwise or of types

Definition at line 88 of file MsgUtil.cpp.

References classOverrides.

Referenced by init().

void MsgUtil::init const char *  filename,
const char *  outFilename = "runlog.txt"
[static]
 

Initialized the message system with the given configuration file File Format: If you provide a file with message level settings you can have any number of the following line types. If you have conflicting settings, the last setting will be used. You can start a line with '#' for a comment that will be ignored:

  • Default message level setting. This line determine whether a message defaults to on or off. If a class isn't listed in this file, the default will be used for it. Note that in a relase build, turning on DEBUG, VERBOSE, TRACE, or TRACEMEM won't work since they are compiled out [WARN|INFO|DEBUG|VERBOSE|TRACE|TRACEMEM] [1|0]
  • Per class level setting. This line determine what messages are printed a single class <Class name>="">: [List of message types seperated with spaces]

If there is no file provided the following file is assumed as the default WARN 1 INFO 1 DEBUG 1 VERBOSE 0 TRACE 0 TRACEMEM 0

Definition at line 40 of file MsgUtil.cpp.

References enableClass(), enabledTypes, INFO, ourNumTypes, ourTypeNames, outputFile, setType(), typeBits(), and WARN.

Here is the call graph for this function:

void MsgUtil::init int  argc,
char **  argv,
const char *  outFilename = "runlog.txt"
[static]
 

Initialize the message system with the command line Command line arguments: If you want to set message settings through the command line, you can use the -EnableType or -DisableType argument with any of the types. You can also use the argument -DebugClass with a classname.

In this mode the message system starts with WARN and INFO types turned on for all classes. The EnableType and DisableType arguments will turn on or off that message type for all classes. If a class is specified with the -DebugClass argument, that class will have all types turned on.

Definition at line 19 of file MsgUtil.cpp.

References classOverrides, DEBUG, enabledTypes, INFO, outputFile, setType(), TRACE, TRACEMEM, typeBits(), VERBOSE, and WARN.

Referenced by ViewerApp::OnInit().

Here is the call graph for this function:

void MsgUtil::printAssert const char *  condition,
const char *  funcname,
int  lineNum,
const char *  filename
[static]
 

Definition at line 167 of file MsgUtil.cpp.

void MsgUtil::printfMsg const char *  classname,
const char *  funcname,
const int  linenum,
const MsgType  type,
const char *  fmt,
  ...
[static]
 

Send a message to the log. This function is normally called through the macros defined in this class. However, you can call this function directly if you want

Parameters:
classname The name of the class that is generating the message
funcname The name of the function generating the message
linenum The line number where the message is generated
type The message type see MsgType enum
fmt fprintf format string

Definition at line 107 of file MsgUtil.cpp.

References classOverrides, enabledTypes, ourTypeNames, outputFile, shouldPrintToFile, shouldPrintToScreen, and typeBits().

Referenced by printMsg().

Here is the call graph for this function:

void MsgUtil::printMsg const char *  classname,
const char *  funcname,
const int  linenum,
const MsgType  type,
const char *  msg
[static]
 

Send a message to the log. This function is normally called through the macros defined in this class. However, you can call this function directly if you want

Parameters:
classname The name of the class that is generating the message
funcname The name of the function generating the message
linenum The line number where the message is generated
type The message type see MsgType enum
msg The message to print

Definition at line 161 of file MsgUtil.cpp.

References printfMsg().

Here is the call graph for this function:

static void MsgUtil::setOutputMode const bool  printToFile = true,
const bool  printToScreen = true
[inline, static]
 

Set the output modes

Parameters:
printToFile set to true to make the message output go to a file. Defaults to on.
printToScreen set to true to make the message output go to the screen. This message system can either print to a wxMessageLog if you are using the wxWindows log (wxUSE_LOG defined; the default), or it can print to cout. If you are doing a windows application, you can setup a console to receive messages with the following code: FreeConsole(); AllocConsole(); freopen("CONIN$","rt",stdin); freopen("CONOUT$","wt",stdout); freopen("CONOUT$","wt",stderr); BringWindowToTop (GetConsoleHwnd()); SetConsoleTitle ("DrawStuff Messages");

Definition at line 184 of file MsgUtil.h.

References shouldPrintToFile, and shouldPrintToScreen.

void MsgUtil::setType const char *  type,
const bool  flag
[static, protected]
 

turn on or off a particular type. This sets the default for all classes for that type. A class can overrride this default with the enable class function call.

Definition at line 93 of file MsgUtil.cpp.

References enabledTypes, ourNumTypes, and ourTypeNames.

Referenced by init().

static int MsgUtil::typeBits const MsgType  type  )  [inline, static, protected]
 

get the bitwise representation of the given message type

Definition at line 221 of file MsgUtil.h.

Referenced by init(), and printfMsg().


Member Data Documentation

map< string, int > MsgUtil::classOverrides [static, protected]
 

Map of string class name to a bitwise or of the types that are turned on for that class

Definition at line 236 of file MsgUtil.h.

Referenced by enableClass(), init(), and printfMsg().

int MsgUtil::enabledTypes = 0 [static, protected]
 

bitwise or of all the types that are enabled for all classes

Definition at line 240 of file MsgUtil.h.

Referenced by init(), printfMsg(), and setType().

const int MsgUtil::ourNumTypes = 6 [static]
 

Definition at line 118 of file MsgUtil.h.

Referenced by init(), and setType().

const char * MsgUtil::ourTypeNames [static]
 

Initial value:

 
                {"TRACEMEM", "TRACE","VERBOSE","DEBUG","INFO","WARN"}

Definition at line 119 of file MsgUtil.h.

Referenced by init(), printfMsg(), and setType().

ofstream MsgUtil::outputFile [static, protected]
 

Definition at line 121 of file MsgUtil.h.

Referenced by init(), and printfMsg().

bool MsgUtil::shouldPrintToFile = true [static, protected]
 

Definition at line 122 of file MsgUtil.h.

Referenced by printfMsg(), and setOutputMode().

bool MsgUtil::shouldPrintToScreen = true [static, protected]
 

Definition at line 123 of file MsgUtil.h.

Referenced by printfMsg(), and setOutputMode().


The documentation for this class was generated from the following files:
Generated on Sat Dec 3 10:48:14 2005 for Robotics by  doxygen 1.4.5