smtk::spew Class Reference

development printing feedback utility More...

Inheritance diagram for smtk::spew:

Inheritance graph
[legend]
List of all members.

Public Types

enum  LEVEL {
  BLOCK, DEBUG, INFO, NOTICE,
  WARN, ERROR, OFF
}
 spew levels available More...

Public Member Functions

spewadd (const char *format,...) __attribute__((format(printf
 add to the spew message
const char * bld (void) const
 color bold
void block (void)
 pop one off the spew stack at level BLOCK
template<class T>
block (T t)
 pop one off the spew stack at level block
const char * blu (void) const
 color blue
bool check_color (void)
 check is escape colors are set
void clear (LEVEL l=BLOCK)
 pop (clear) all off the spew stack
void debug (void)
 pop one off the spew stack at level DEBUG
template<class T>
debug (T t)
 pop one off the spew stack at level DEBUG
const char * end (void) const
 color end
void error (void)
 pop one off the spew stack at level ERROR
template<class T>
error (T t)
 pop one off the spew stack at level ERROR
void get_env_color (FILE *file, bool over_ride_env=false)
 parse environment variable SMTK_COLOR.
FILE * get_file (void) const
 get the spew file
spew_guiget_gui (void)
 Get the GUI object.
LEVEL get_level (void) const
 get the current spew level
spew const char * get_prefix (void) const
 get the spew prefix string
const char * grn (void) const
 color green
void info (void)
 pop one off the spew stack at level INFO
template<class T>
info (T t)
 pop one off the spew stack at level INFO
void notice (void)
 pop one off the spew stack at level NOTICE
template<class T>
notice (T t)
 pop one off the spew stack at level NOTICE
void pop (LEVEL level)
 pop one off the spew stack
template<class T>
pop (LEVEL level, T t)
 pop one off the spew stack
spew spewpush (void)
 push one on the spew stack
spewpush (const char *func_name,...) __attribute__((format(printf
 push one on the spew stack
const char * rblu (void) const
 color reverse blue
const char * red (void) const
 color red
template<class T>
ret (T t)
 handy return value
const char * rev (void) const
 color reverse
const char * rgrn (void) const
 color reverse green
const char * rred (void) const
 color reverse red
const char * rtur (void) const
 color reverse turquoise
const char * rvil (void) const
 color reverse violet
const char * ryel (void) const
 color reverse yellow
spewset_callback (void(*func)(const char *prefix, const char *message, spew::LEVEL level))
 add a user call-back
spewset_color (bool on=true)
 enable/disable the escape color strings.
int set_file (const char *filename=0)
 set the spew file
spewset_gtk_gui (bool truth=true)
 set/unset for GUI feedback
spewset_gui (spew_gui *my_gui)
 set/unset for GUI feedback with user defined GUI
spewset_level (LEVEL level)
 set the spew level
spewset_prefix (const char *format,...) __attribute__((format(printf
 set the spew prefix string
spew spew spewsys (void)
 add a new spew message with system error
spew spewsys (const char *func_name,...) __attribute__((format(printf
 add a new spew message with system error
const char * tur (void) const
 color turquoise
const char * und (void) const
 color under line
const char * vil (void) const
 color violet
void warn (void)
 pop one off the spew stack at level WARN
template<class T>
warn (T t)
 pop one off the spew stack at level WARN
const char * yel (void) const
 color yellow

Detailed Description

development printing feedback utility

Examples: devel_spew_1.cpp, devel_spew_2.cpp, devel_spew_3.cpp.

The class spew provides a short message spewing utility for the SmTk application programming interface (API). As it's name implies the nature of the messages are usually diagnostic, or coming from within. It's more of a developer tool than a end application user tool. By default it just spews short messages to standard output. Spew may be configured to spew to pop up GUIs (graphical user interfaces), or user defined call-backs may be used to get an ASCII string. It can be used as a debugging tool with varying levels of verbosity or as spew from your application. The application may prepend a string to all the messages using set_prefix(). The intent of spew is to peek at what is happening when using the SmTk API while a program is running. By default the spew message output does not flush until the program execution reaches the API users code or an exceptional condition is generated. The end program user has many controls over spew by using environment variables. The application developer may set some default behaviors, but the end program user can over-ride them.

By default a spew class object uses a standard C library FILE stream. A program user may select a file to use by setting the environment variable SMTK_SPEW_FILE to any one of the following:

In addition to the above spew files the SmTk API user may set up a spew call-back which is called every time the spew flushes. Spew stack's messages from SmTk API calls and, by default, flushes anytime the thread of execution reaches the end of a users call to a SmTk API function (or method) call.

The environment variable SMTK_SPEW or SMTK_SPEW_LEVEL affects when spew will spew. If both SMTK_SPEW and SMTK_SPEW_LEVEL are both set the value of SMTK_SPEW will be ignored. The values of SMTK_SPEW and SMTK_SPEW_LEVEL will be understood in any combination of upper or lower case letters. The following values of SMTK_SPEW and SMTK_SPEW_LEVEL can control a spew object:

Environment variables will only effect spew when the object is constructed. So environment variables set in your code will only effect spew objects that are constructed after the environment variables set.

Todo:
The C++ iostreams and STL strings were not used to make this class because that would requires a lot more coding then what is in this code. We used the right tool for the job as we see it.
Todo:
It seems that all mid to large APIs have and need some kind of spew-like class for helping the API user and API developer with debugging and getting information from exceptional cases when testing. We feel that the default behavior of this spew class is exceptable for most users and it is extensible enough for users who want more.
Todo:
Should this class use internationalization?
Todo:
Spew messages to system logs. This can be added with set_callback() as it is.


Member Enumeration Documentation

enum smtk::spew::LEVEL

spew levels available

This enumeration is used to define the level of spew, from very verbose (DEBUG) too no spew at all (OFF). See spew_level_env in the detailed description of how the environment variable SMTK_SPEW_LEVEL compared to these levels.

Enumerator:
BLOCK  used by API code to turn spew off
DEBUG  for very verbose
INFO  regular verbose
NOTICE  spew when it seems notable
WARN  spew when it is not so good
ERROR  spew when something fails to work
OFF  used to set user spew setting to OFF


Member Function Documentation

spew & spew::add ( const char *  format,
  ... 
)

add to the spew message

Adds to the spew message. Do not use new line characters the arguments of add(), they may be added automatically if they are needed.

Parameters:
format The text added is composed from format interpreting it as a printf(3) like format
Returns:
a reference to the spew object.

const char* smtk::tty_color::bld ( void   )  const [inline, inherited]

color bold

Returns:
color termio escape string bold.

void smtk::spew::block ( void   )  [inline]

pop one off the spew stack at level BLOCK

This will call pop() with level set to BLOCK. This will keep the spew message from being displayed.

template<class T>
T smtk::spew::block ( t  )  [inline]

pop one off the spew stack at level block

This will call pop() with level set to BLOCK. This will keep the spew message from being displayed.

Returns:
t the argument the user passed

const char* smtk::tty_color::blu ( void   )  const [inline, inherited]

color blue

Returns:
color termio escape string blue.

bool smtk::tty_color::check_color ( void   )  [inline, inherited]

check is escape colors are set

Returns:
true if there are color escape strings set, and false if there are all null strings.

void smtk::spew::clear ( LEVEL  l = BLOCK  )  [inline]

pop (clear) all off the spew stack

This pops all spew entries in the stack. This can be used to fix the spew entry stack if there was an exception thrown or some other kind of jump in the code, but otherwise clear() should be avoided.

Parameters:
l set the spew entries that are popped to level l.

void smtk::spew::debug ( void   )  [inline]

pop one off the spew stack at level DEBUG

This will call pop() with level set to DEBUG.

template<class T>
T smtk::spew::debug ( t  )  [inline]

pop one off the spew stack at level DEBUG

This will call pop() with level set to DEBUG.

Returns:
t the argument the user passed

const char* smtk::tty_color::end ( void   )  const [inline, inherited]

color end

Returns:
color termio escape string to end the current color mode.

void smtk::spew::error ( void   )  [inline]

pop one off the spew stack at level ERROR

This will call pop() with level set to ERROR.

template<class T>
T smtk::spew::error ( t  )  [inline]

pop one off the spew stack at level ERROR

This will call pop() with level set to ERROR.

Returns:
t the argument the user passed

void tty_color::get_env_color ( FILE *  file,
bool  over_ride_env = false 
) [inherited]

parse environment variable SMTK_COLOR.

See color_env for how the environment variable SMTK_COLOR effects this class.

Parameters:
file is used to check if the file is a tty terminal that will interpret the escape sequences.
over_ride_env if true the color strings will not depend on the environment variable SMTK_COLOR.

FILE* smtk::spew::get_file ( void   )  const [inline]

get the spew file

Returns:
the file that will be written to when this spews.

spew_gui* smtk::spew::get_gui ( void   )  [inline]

Get the GUI object.

Returns:
a pointer to the GUI object or 0 (NULL) if is is not set.

LEVEL smtk::spew::get_level ( void   )  const [inline]

get the current spew level

Returns:
the current spew level

spew const char* smtk::spew::get_prefix ( void   )  const [inline]

get the spew prefix string

Get a string that will be prepended to all spew messages.

Returns:
a pointer to a string. Don't mess with the string.

const char* smtk::tty_color::grn ( void   )  const [inline, inherited]

color green

Returns:
color termio escape string green.

void smtk::spew::info ( void   )  [inline]

pop one off the spew stack at level INFO

This will call pop() with level set to INFO.

template<class T>
T smtk::spew::info ( t  )  [inline]

pop one off the spew stack at level INFO

This will call pop() with level set to INFO.

Returns:
t the argument the user passed

void smtk::spew::notice ( void   )  [inline]

pop one off the spew stack at level NOTICE

This will call pop() with level set to NOTICE.

template<class T>
T smtk::spew::notice ( t  )  [inline]

pop one off the spew stack at level NOTICE

This will call pop() with level set to NOTICE.

Returns:
t the argument the user passed

void smtk::spew::pop ( LEVEL  level  )  [inline]

pop one off the spew stack

See template<class T> spew::pop(LEVEL level, T t).

template<class T>
T smtk::spew::pop ( LEVEL  level,
t 
) [inline]

pop one off the spew stack

This pops one off the spew entry stack, which this class uses to determine when to flush the message and when this is used properly with accompanying push() can be used to tell what the depth of function call is in the SmTk API. This helps make a list of what called what and what spewed what in the SmTk API. When the spew stack pops the top spew message, all the current the spew messages will be flushed.

pop() is called after push(). Because pop() is called at the end of a spew message call sequence, it decides the importance level of the spew message with the level argument. See also block(), debug(), info(), notice(), warn() and error().

Parameters:
level is the selected spew level. This will be over-ridden if this is not at the bottom of the spew stack. The last message popped off the spew stack will determine the spew level. This is so that the function (or method) closest to the user decides what is the nature of the spew message.
t the returned value. This is convenient to be called in a function that returns a value.
Returns:
t the argument the user passed
example using warn():
     // example code snippet //

     // returns -1
     return smtk::spw.add("failed").warn(-1);
     

spew spew& smtk::spew::push ( void   )  [inline]

push one on the spew stack

Pushes a message entry onto the spew stack. This stack when used properly, push() with accompanying pop() (block(), debug(), info(), notice(), warn() or error()), can be used to tell what the depth of function call is in the SmTk API. This helps make a list of what called what and what spewed what in the SmTk API.

Returns:
a reference to the spew object

spew & spew::push ( const char *  func_name,
  ... 
)

push one on the spew stack

This pushs a spew entry on a stack which this class uses to determine when to flush the message and when this is used properly with accompanying pop() can be used to tell what the depth of function call is in the SmTk API. This helps make a list of what called what and what spewed what in the SmTk API.

Parameters:
func_name the function (or method) name to use in the spew message for this call depth. func_name may be used as a printf(3) like format for the remaining arguments.
Returns:
a reference to the spew object.

const char* smtk::tty_color::rblu ( void   )  const [inline, inherited]

color reverse blue

Returns:
color termio escape string reverse blue.

const char* smtk::tty_color::red ( void   )  const [inline, inherited]

color red

Returns:
color termio escape string red.

template<class T>
T smtk::spew::ret ( t  )  [inline]

handy return value

This does nothing but return the value passed. This is handy for reducing the amount of code that a user must write. For example if you need to return a value after adding to spew you can do:

     // example code snippet //

     if(my_function()) // error
       return spw.add("my_function failed").ret(-1);
     
This is less code then without the ret() method:
     // longer example code snippet //

     if(my_function()) // error
      {
        spw.add("my_function failed");
        return -1;
      }
     

Returns:
t the argument the user passed

const char* smtk::tty_color::rev ( void   )  const [inline, inherited]

color reverse

Returns:
color termio escape string reverse-video.

const char* smtk::tty_color::rgrn ( void   )  const [inline, inherited]

color reverse green

Returns:
color termio escape string reverse green.

const char* smtk::tty_color::rred ( void   )  const [inline, inherited]

color reverse red

Returns:
color termio escape string reverse red.

const char* smtk::tty_color::rtur ( void   )  const [inline, inherited]

color reverse turquoise

Returns:
color termio escape string reverse turquoise.

const char* smtk::tty_color::rvil ( void   )  const [inline, inherited]

color reverse violet

Returns:
color termio escape string reverse violet.

const char* smtk::tty_color::ryel ( void   )  const [inline, inherited]

color reverse yellow

Returns:
color termio escape string reverse yellow.

spew& smtk::spew::set_callback ( void(*)(const char *prefix, const char *message, spew::LEVEL level)  func  )  [inline]

add a user call-back

Add a user call-back function that will be called every time spew is flushed. You may want to remove any color escape sequence strings with set_color() before calling set_callback().

Parameters:
func is called with message that will contain the composed message string.
Returns:
a reference to the spew object.

spew & spew::set_color ( bool  on = true  ) 

enable/disable the escape color strings.

To give the API user the control, this is not called in any part of the SmTk API, other than in this class in the constructor. The setting of escape color strings is also set in the constructor from the value of the environment variable SMTK_COLOR. This will over-ride that. See color_env in the tty_color class detailed description.

Parameters:
on If on is true the escape color strings are set, and if on is false all the escape color strings are set to empty strings.

Reimplemented from smtk::tty_color.

int spew::set_file ( const char *  filename = 0  ) 

set the spew file

Set the spew file. This only over-rides the default spew file. The spew file can be over-written by the end user by setting the SMTK_SPEW_FILE environment variable. See spew_file_env in the spew class detailed description.

Parameters:
filename may be set to "stdout", (for standard error) "stderr" (for standard error), "none" or 0 (for no file spew) or the filename of a regular file. If the file fails to be opened the spew will go back to the way it was before this call.
Returns:
0 if the file was set using filename, 1 if the user over-ride this with the SMTK_SPEW_FILE environment variable, and -1 on error.

spew & spew::set_gtk_gui ( bool  truth = true  ) 

set/unset for GUI feedback

spew_gtk_gui.png

Screen-Shot of this GUI in use.

Set the spew to use the built in GUI (graphical user interface) to display each time there is a spew message flushed.

When setting with GUI feedback on any color escape string sequences will be removed.

Parameters:
truth if truth is true this will set up spew for GUI feedback using a GTK dialog window, and if truth is false this will not use a GUI.
Returns:
a reference to the spew object.

spew & spew::set_gui ( spew_gui my_gui  ) 

set/unset for GUI feedback with user defined GUI

Set the spew to use the GUI (graphical user interface) that the user makes. The spew object will not try to do something stupid like deleting the object that was passed in. See the example in gtk_spew_gui.cpp and gtk_spew_gui.h.

Parameters:
my_gui is a pointer to a spew_gui that the user provided. my_gui may be 0 (NULL) to unset the GUI and make it not display.
Returns:
a reference to the spew object.
See also:
spew::set_gtk_gui().

spew& smtk::spew::set_level ( LEVEL  level  )  [inline]

set the spew level

Set the spew level. The spew level can be over-written by the end user by setting the SMTK_SPEW_LEVEL environment variable. See spew_level_env in the spew class detailed description.

Parameters:
level the level to set to.

spew & spew::set_prefix ( const char *  format,
  ... 
)

set the spew prefix string

Set a string that will be prepended to all spew messages. The typical use would be to set the spew prefix to the name of the program that is built using the SmTk API.

Parameters:
format is a printf(3) format string. See `man 3 printf'.
Returns:
a reference to the spew object.

spew & spew::sys ( void   ) 

add a new spew message with system error

Adds to the spew message using strerror(3) to get the system error string from the current system error number errno(3).

Returns:
a reference to the spew object.

spew & spew::sys ( const char *  func_name,
  ... 
)

add a new spew message with system error

Adds to the spew message using strerror(3) to get the system error string from the current system error number errno(3).

Parameters:
func_name is a printf(3) like format. The string composed is intended to be the name of the system function that produced the system error. This system function name will be used to prefix the system error string.
Returns:
a reference to the spew object.

const char* smtk::tty_color::tur ( void   )  const [inline, inherited]

color turquoise

Returns:
color termio escape string turquoise.

const char* smtk::tty_color::und ( void   )  const [inline, inherited]

color under line

Returns:
color termio escape string under-line.

const char* smtk::tty_color::vil ( void   )  const [inline, inherited]

color violet

Returns:
color termio escape string violet.

void smtk::spew::warn ( void   )  [inline]

pop one off the spew stack at level WARN

This will call pop() with level set to WARN.

template<class T>
T smtk::spew::warn ( t  )  [inline]

pop one off the spew stack at level WARN

This will call pop() with level set to WARN.

Returns:
t the argument the user passed

const char* smtk::tty_color::yel ( void   )  const [inline, inherited]

color yellow

Returns:
color termio escape string yellow.


The documentation for this class was generated from the following files:
Generated on Sat Aug 11 22:25:58 2007 for Simulation Toolkit (SmTk) by  doxygen 1.5.2