SST/macro
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
sstmac::logger Class Reference

Base class of things which track events in the simulation, and output in different ways. More...

#include <logger.h>

Collaboration diagram for sstmac::logger:
Collaboration graph

Public Member Functions

 logger (const std::string &namesig, std::ostream *os, bool flush=false, const char *color=black)
 Real constructor. More...
 
 logger ()
 Fake constructor for instantiating static loggers before they're sure that the static logger variable has been instantiated. More...
 
virtual ~logger ()
 
bool is_active (int lev=1) const
 Indicates if this logger is turned on, which is useful for bypassing std::stringifying everything. More...
 
virtual loggeroperator<< (int i)
 
virtual loggeroperator<< (long i)
 
virtual loggeroperator<< (long long int i)
 
virtual loggeroperator<< (unsigned int i)
 
virtual loggeroperator<< (unsigned long int i)
 
virtual loggeroperator<< (unsigned long long int i)
 
virtual loggeroperator<< (bool i)
 
virtual loggeroperator<< (const char *i)
 
virtual loggeroperator<< (double i)
 
virtual loggeroperator<< (long double i)
 
virtual loggeroperator<< (const std::string &i)
 
virtual loggeroperator<< (timestamp i)
 
virtual loggeroperator<< (const std::pair< int, int > &p)
 
template<class T >
loggeroperator<< (const T &t)
 
bool is_real ()
 Indicates if this instance was constructed correctly. More...
 
virtual std::string to_string () const
 
std::string time () const
 

Static Public Member Functions

static void register_logger (logger *log)
 Unfortunately, everyone who wants loggers to get turned on/off has to call this. More...
 
static void delete_statics ()
 
static void set_user_param (const std::string &s)
 Static function which should be called to change which loggers are currently turned on. More...
 
static void check_user_params ()
 
static void clear ()
 Clears all saved loggers that are updated on set_user_param. More...
 
static void set_debug_coloring (bool c)
 Sets whether we should turn text coloring on (useful for debugging in a console) More...
 

Static Public Attributes

static bool user_params_checked_
 
static const char * black
 
static const char * red
 
static const char * green
 
static const char * yellow
 
static const char * blue
 
static const char * magenta
 
static const char * cyan
 
static const char * white
 
static event_managertimer_
 

Protected Member Functions

void update_active ()
 updates the active status of this logger based on the current user parameter More...
 

Static Protected Member Functions

static void update_all_active ()
 updates all saved loggers based on the current user parameter More...
 

Protected Attributes

int active_
 
std::string signature_
 
std::string category_
 
std::ostream * outstream_
 
std::string my_color_
 
bool always_flush_
 
bool is_real_
 

Static Protected Attributes

static std::deque< std::string > user_params
 
static spkt_unordered_map< std::string, bool > user_params_matched_
 
static std::list< logger * > loggers_
 
static bool debug_coloring_
 
static bool timer_on_
 

Detailed Description

Base class of things which track events in the simulation, and output in different ways.

Upon construction, loggers are registered in a global variable, and provide a name signature which has the form "<category> name | name2 | ...". Then loggers can be selectively turned on and off by calling set_user_param(). Loggers will be turned on using any of their supplied names, and all loggers of a given category will be turned on by specifying "all" (e.g. "<debug> all")

Currently supported categories are <debug>, <stats>, and <trace>

Objects which are created and destroyed often should definitely use a static variable, because a lot of std::string operations have to happen to check name signatures to see if the logger is active.

Also, because the logger constructed adds this to a static collection, static logger variables should first use the fake constructor as initialization, then check is_real() after the executable has started to see if they should reinstantiate themselves.

Definition at line 50 of file logger.h.

Constructor & Destructor Documentation

sstmac::logger::logger ( const std::string &  namesig,
std::ostream *  os,
bool  flush = false,
const char *  color = black 
)

Real constructor.

Adds this to the static logger collection that is updated on set_user_param(), and calls update_active() in case set_user_param has already been called.

Parameters
namesigMy name signature (e.g. "<debug> mpi | library | mpiserver"). It's usually a good idea to provide multiple names so you don't have to remember the exact name, and also so you can turn on whole groups of objects (like all of mpi, for instance).
osthe output stream to use.
flushIf true, the logger will always call flush() on the output stream after it writes something to it.
colorSet color with escape characters, most useful for debugging in a console.
sstmac::logger::logger ( )
inline

Fake constructor for instantiating static loggers before they're sure that the static logger variable has been instantiated.

Definition at line 71 of file logger.h.

References ~logger().

Here is the call graph for this function:

virtual sstmac::logger::~logger ( )
virtual

Referenced by logger().

Member Function Documentation

static void sstmac::logger::check_user_params ( )
static
static void sstmac::logger::clear ( )
static

Clears all saved loggers that are updated on set_user_param.

It's usually a good idea to call this in between simulations if running multiple in one executable.

static void sstmac::logger::delete_statics ( )
static

Referenced by register_logger().

bool sstmac::logger::is_active ( int  lev = 1) const
inline

Indicates if this logger is turned on, which is useful for bypassing std::stringifying everything.

Returns

Definition at line 97 of file logger.h.

References active_, and set_user_param().

Here is the call graph for this function:

bool sstmac::logger::is_real ( )
inline

Indicates if this instance was constructed correctly.

This is useful for instantiating static logger variables, and only making the real ones until the simulation has already started, when the logger static variables have been set up first (which is required for the whole logger active mechanism to work).

Returns
true if this instance was constructed properly

Definition at line 199 of file logger.h.

References is_real_, and to_string().

Here is the call graph for this function:

virtual logger& sstmac::logger::operator<< ( int  i)
virtual
virtual logger& sstmac::logger::operator<< ( long  i)
virtual
virtual logger& sstmac::logger::operator<< ( long long int  i)
virtual
virtual logger& sstmac::logger::operator<< ( unsigned int  i)
virtual
virtual logger& sstmac::logger::operator<< ( unsigned long int  i)
virtual
virtual logger& sstmac::logger::operator<< ( unsigned long long int  i)
virtual
virtual logger& sstmac::logger::operator<< ( bool  i)
virtual
virtual logger& sstmac::logger::operator<< ( const char *  i)
virtual
virtual logger& sstmac::logger::operator<< ( double  i)
virtual
virtual logger& sstmac::logger::operator<< ( long double  i)
virtual
virtual logger& sstmac::logger::operator<< ( const std::string &  i)
virtual
virtual logger& sstmac::logger::operator<< ( timestamp  i)
virtual
virtual logger& sstmac::logger::operator<< ( const std::pair< int, int > &  p)
virtual
template<class T >
logger& sstmac::logger::operator<< ( const T &  t)
inline

Definition at line 165 of file logger.h.

static void sstmac::logger::register_logger ( logger log)
inlinestatic

Unfortunately, everyone who wants loggers to get turned on/off has to call this.

Parameters
log

Definition at line 84 of file logger.h.

References delete_statics(), and loggers_.

Here is the call graph for this function:

static void sstmac::logger::set_debug_coloring ( bool  c)
inlinestatic

Sets whether we should turn text coloring on (useful for debugging in a console)

Parameters
c

Definition at line 186 of file logger.h.

References debug_coloring_.

static void sstmac::logger::set_user_param ( const std::string &  s)
static

Static function which should be called to change which loggers are currently turned on.

Calls update_all_active().

Parameters
sSignature which indicates which loggers should be turned on. For example "<debug> mpi | <stats> all | <debug> app | <trace> mpi"

Referenced by is_active().

std::string sstmac::logger::time ( ) const
virtual std::string sstmac::logger::to_string ( ) const
virtual

Referenced by is_real().

void sstmac::logger::update_active ( )
protected

updates the active status of this logger based on the current user parameter

static void sstmac::logger::update_all_active ( )
staticprotected

updates all saved loggers based on the current user parameter

Member Data Documentation

int sstmac::logger::active_
protected

Definition at line 215 of file logger.h.

Referenced by is_active().

bool sstmac::logger::always_flush_
protected

Definition at line 238 of file logger.h.

const char* sstmac::logger::black
static

Definition at line 171 of file logger.h.

const char* sstmac::logger::blue
static

Definition at line 175 of file logger.h.

std::string sstmac::logger::category_
protected

Definition at line 218 of file logger.h.

const char* sstmac::logger::cyan
static

Definition at line 177 of file logger.h.

bool sstmac::logger::debug_coloring_
staticprotected

Definition at line 236 of file logger.h.

Referenced by set_debug_coloring().

const char* sstmac::logger::green
static

Definition at line 173 of file logger.h.

bool sstmac::logger::is_real_
protected

Definition at line 240 of file logger.h.

Referenced by is_real().

std::list<logger*> sstmac::logger::loggers_
staticprotected

Definition at line 213 of file logger.h.

Referenced by register_logger().

const char* sstmac::logger::magenta
static

Definition at line 176 of file logger.h.

std::string sstmac::logger::my_color_
protected

Definition at line 222 of file logger.h.

std::ostream* sstmac::logger::outstream_
protected

Definition at line 220 of file logger.h.

const char* sstmac::logger::red
static

Definition at line 172 of file logger.h.

std::string sstmac::logger::signature_
protected

Definition at line 217 of file logger.h.

event_manager* sstmac::logger::timer_
static

Definition at line 205 of file logger.h.

bool sstmac::logger::timer_on_
staticprotected

Definition at line 242 of file logger.h.

std::deque<std::string> sstmac::logger::user_params
staticprotected

Definition at line 211 of file logger.h.

bool sstmac::logger::user_params_checked_
static

Definition at line 110 of file logger.h.

spkt_unordered_map<std::string, bool> sstmac::logger::user_params_matched_
staticprotected

Definition at line 212 of file logger.h.

const char* sstmac::logger::white
static

Definition at line 178 of file logger.h.

const char* sstmac::logger::yellow
static

Definition at line 174 of file logger.h.


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