SST/macro
|
Base class of things which track events in the simulation, and output in different ways. More...
#include <logger.h>
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 logger & | operator<< (int i) |
virtual logger & | operator<< (long i) |
virtual logger & | operator<< (long long int i) |
virtual logger & | operator<< (unsigned int i) |
virtual logger & | operator<< (unsigned long int i) |
virtual logger & | operator<< (unsigned long long int i) |
virtual logger & | operator<< (bool i) |
virtual logger & | operator<< (const char *i) |
virtual logger & | operator<< (double i) |
virtual logger & | operator<< (long double i) |
virtual logger & | operator<< (const std::string &i) |
virtual logger & | operator<< (timestamp i) |
virtual logger & | operator<< (const std::pair< int, int > &p) |
template<class T > | |
logger & | operator<< (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_manager * | timer_ |
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_ |
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.
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.
namesig | My 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). |
os | the output stream to use. |
flush | If true, the logger will always call flush() on the output stream after it writes something to it. |
color | Set color with escape characters, most useful for debugging in a console. |
|
inline |
|
virtual |
Referenced by logger().
|
static |
|
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 |
Referenced by register_logger().
|
inline |
Indicates if this logger is turned on, which is useful for bypassing std::stringifying everything.
Definition at line 97 of file logger.h.
References active_, and set_user_param().
|
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).
Definition at line 199 of file logger.h.
References is_real_, and to_string().
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
virtual |
|
inline |
|
inlinestatic |
Unfortunately, everyone who wants loggers to get turned on/off has to call this.
log |
Definition at line 84 of file logger.h.
References delete_statics(), and loggers_.
|
inlinestatic |
Sets whether we should turn text coloring on (useful for debugging in a console)
c |
Definition at line 186 of file logger.h.
References debug_coloring_.
|
static |
Static function which should be called to change which loggers are currently turned on.
Calls update_all_active().
s | Signature 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 |
Referenced by is_real().
|
protected |
updates the active status of this logger based on the current user parameter
|
staticprotected |
updates all saved loggers based on the current user parameter
|
protected |
Definition at line 215 of file logger.h.
Referenced by is_active().
|
staticprotected |
Definition at line 236 of file logger.h.
Referenced by set_debug_coloring().
|
protected |
|
staticprotected |
Definition at line 213 of file logger.h.
Referenced by register_logger().
|
static |
|
staticprotected |
|
staticprotected |