CARMA C++
carma::util::Trace Class Reference

The Trace class provides an efficient means for managing debug statements throughout CARMA code. More...

#include <carma/util/Trace.h>

Public Types

enum  TraceDestination { STDOUT, FILE, SYSLOG, SIMPLE }
 Enumeration of possible output destinations. More...
 
enum  TraceLevel {
  TRACE0 = 1, TRACE1 = 1, TRACE2 = 2, TRACE3 = 3,
  TRACE4 = 4, TRACE5 = 5, TRACE6 = 6, TRACE7 = 7,
  TRACEALL = 7
}
 These values are the indices for the private priorities array, which corresponds directly to log4cpp/Priority.hh TRACE0 corresponds to the most critical level trace messages (the least verbose), TRACE7 the least critical (most verbose) messages, usually used for intense debugging. More...
 

Public Member Functions

TraceDestination getDestination () const
 
void setObjectTraceLevel (const TraceLevel traceLevel)
 method allowing traceLevel to be modified More...
 
 Trace (TraceLevel traceLevel, const std::string &traceDestination, bool traceVerbose=true, const std::string &objectName="Trace", carma::util::facilityType facility=DEFAULT_FACILITY)
 Constructor. More...
 
bool willWrite (TraceLevel traceLevel) const
 
void write (TraceLevel traceLevel, const std::string &debugMessage)
 Generic output method, output will go to destination specified in constructor. More...
 
void write (TraceLevel traceLevel, const std::ostringstream &debugMessage)
 Generic output method, output will go to destination specified in constructor. More...
 
void writeFile (const std::string &debugMessage)
 Send trace messages to a file. More...
 
void writeFile (const std::ostringstream &debugMessage)
 Send trace messages to a file. More...
 
void writeStdout (const std::string &debugMessage)
 Send trace messages to standard output. More...
 
void writeStdout (const std::ostringstream &debugMessage)
 Send trace messages to standard output. More...
 
void writeSysLog (const std::string &debugMessage)
 Send trace messages to syslog. More...
 
void writeSysLog (const std::ostringstream &debugMessage)
 Send trace messages to syslog. More...
 

Static Public Member Functions

static carma::util::TracegetProgramTrace ()
 
static carma::util::TracegetProgramTraceIfAvailable ()
 
static carma::util::TracegetProgramTraceIfWillWrite (TraceLevel traceLevel)
 

Detailed Description

The Trace class provides an efficient means for managing debug statements throughout CARMA code.

We want to be able to trace execution of a program through output statements, but be able to modify at compile and/or runtime which statements get printed. The Trace object would be assigned a debug level'' via a command-line parameter. Each debug message would also be assigned adebug level'', so that message generation will depend on the level of the Trace object. Compile-time switches would also be available to reduce the runtime overhead.

Definition at line 97 of file Trace.h.

Member Enumeration Documentation

Enumeration of possible output destinations.

STDOUT -> Standard output
FILE -> A file
SYSLOG -> syslog
SIMPLE -> Simplified output

Definition at line 126 of file Trace.h.

These values are the indices for the private priorities array, which corresponds directly to log4cpp/Priority.hh TRACE0 corresponds to the most critical level trace messages (the least verbose), TRACE7 the least critical (most verbose) messages, usually used for intense debugging.

Definition at line 107 of file Trace.h.

Constructor & Destructor Documentation

carma::util::Trace::Trace ( TraceLevel  traceLevel,
const std::string &  traceDestination,
bool  traceVerbose = true,
const std::string &  objectName = "Trace",
carma::util::facilityType  facility = DEFAULT_FACILITY 
)

Constructor.

Parameters
traceLevel- the trace level
traceDestination- where the output should go.
traceVerbose- print out trace info with full logging info
objectName- descriptive string for [the parent of] this Trace
facility- for syslog traces, the syslog facility to use. This param is ignored for trace messages that do not go to syslog.
See Also
carma::util::Logger::getSyslogger()
carma::util::Logger::getFilelogger()
carma::util::Logger::getOstreamlogger()
syslog(3) manpage

Member Function Documentation

TraceDestination carma::util::Trace::getDestination ( ) const
Returns
the destination of trace messages for this object, as a TraceDestination enumeration value.

Definition at line 229 of file Trace.h.

static carma::util::Trace* carma::util::Trace::getProgramTrace ( )
static
Returns
A pointer to the default carma::util::Program Trace object
void carma::util::Trace::setObjectTraceLevel ( const TraceLevel  traceLevel)

method allowing traceLevel to be modified

Parameters
traceLevel- new level for Trace object
void carma::util::Trace::write ( TraceLevel  traceLevel,
const std::string &  debugMessage 
)

Generic output method, output will go to destination specified in constructor.

Parameters
traceLevel- the trace level
debugMessage- a string containing the trace message

Definition at line 307 of file Trace.h.

void carma::util::Trace::write ( TraceLevel  traceLevel,
const std::ostringstream &  debugMessage 
)

Generic output method, output will go to destination specified in constructor.

Parameters
traceLevel- the trace level
debugMessage- a std::ostringstream containing the trace message

Definition at line 313 of file Trace.h.

void carma::util::Trace::writeFile ( const std::string &  debugMessage)

Send trace messages to a file.

Parameters
debugMessage- a string containing the trace message

Definition at line 287 of file Trace.h.

void carma::util::Trace::writeFile ( const std::ostringstream &  debugMessage)

Send trace messages to a file.

Parameters
debugMessage- a std::ostringstream containing the trace message

Definition at line 292 of file Trace.h.

void carma::util::Trace::writeStdout ( const std::string &  debugMessage)

Send trace messages to standard output.

Parameters
debugMessage- a string containing the trace message

Definition at line 277 of file Trace.h.

void carma::util::Trace::writeStdout ( const std::ostringstream &  debugMessage)

Send trace messages to standard output.

Parameters
debugMessage- a std::ostringstream containing the trace message

Definition at line 282 of file Trace.h.

void carma::util::Trace::writeSysLog ( const std::string &  debugMessage)

Send trace messages to syslog.

Parameters
debugMessage- a string containing the trace message

Definition at line 297 of file Trace.h.

void carma::util::Trace::writeSysLog ( const std::ostringstream &  debugMessage)

Send trace messages to syslog.

Parameters
debugMessage- a std::ostringstream containing the trace message

Definition at line 302 of file Trace.h.


The documentation for this class was generated from the following file: