27 #include <platform/types.hh>
67 std::recursive_mutex tracer_static_data_mutex;
75 static std::ostream * final_stream_ = &
std::cout;
98 static bool raw =
true;
107 static std::string
const all_channels(
"_Really_Unique_String_Object_To_Identify_All_Tracer_Channels__qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM");
116 static bool mute =
false;
131 std::string
const & channel
137 visibility_calculated_(false)
144 bool muted;
int mute_level;
155 int pr = tracer_.priority();
159 tracer_.priority(pr);
171 #ifdef MULTI_THREADED
172 std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
177 for ( std::vector<Tracer *>::iterator it = all_tracers.begin();
178 it != all_tracers.end(); ++it ) {
179 (*it)->flush_all_channels();
188 #ifdef MULTI_THREADED
189 std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
195 all_tracers[
ii ]->calculate_visibility();
213 init(channel,
"",
"", priority, muted_by_default);
217 Tracer::Tracer(std::string
const & channel, std::string
const & channel_color, std::string
const & channel_name_color,
TracerPriority priority,
bool muted_by_default) :
218 Fatal( *this,
t_fatal, channel ),
221 Info( *this,
t_info, channel ),
222 Debug( *this,
t_debug, channel ),
223 Trace( *this,
t_trace, channel )
225 init(channel, channel_color, channel_name_color, priority, muted_by_default);
228 void Tracer::init(std::string
const & channel, std::string
const & channel_color, std::string
const & channel_name_color,
TracerPriority priority,
bool muted_by_default)
244 #ifdef MULTI_THREADED
245 std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
262 std::vector< otstream* >
v = utility::tools::make_vector< otstream* >(
272 for (
size_t i=0; i<v.size(); i++ ) {
275 (*v[i]) << std::endl;
276 (*v[i]) <<
"WARNING: Message(s) above was printed in the end instead of proper place because this Tracer object has some contents left in inner buffer when destructor was called. Explicit call Tracer::flush() or end your IO with std::endl to disable this warning.\n" << std::endl;
282 #ifdef MULTI_THREADED
283 std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
289 std::vector< Tracer * >::iterator iter_this = std::find( all_tracers.begin(), all_tracers.end(), this );
290 assert( iter_this != all_tracers.end() );
291 all_tracers.erase( iter_this );
308 #ifdef MULTI_THREADED
309 std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
321 std::vector< otstream* >
v = utility::tools::make_vector< otstream* >(
325 for (
size_t i=0; i<v.size(); i++ ) {
332 if (
muted_ )
return false;
378 std::string
const & channel,
383 bool muted_by_default
389 else visible =
false;
395 if ( muted_by_default ) {
397 else visible =
false;
407 int already_initialized = 0;
408 int already_finalized = 0;
409 MPI_Initialized( &already_initialized );
410 MPI_Finalized( &already_finalized );
411 if ( already_initialized != 0 && already_finalized == 0 ) {
413 MPI_Comm_rank (MPI_COMM_WORLD, &mpi_rank);
414 MPI_Comm_size (MPI_COMM_WORLD, &mpi_nprocs);
433 if ( priority > mute_level_ ) visible =
false;
445 for (
size_t i=1; i<=v.size(); i++ ) {
446 if ( v[i] == ch )
return true;
449 if ( ch.size() > v[i].size() ) {
450 std::string
s(ch); s.resize(v[i].
size());
451 if ( s == v[i] )
return true;
461 *
ios_hook() << message << std::endl;
465 std::cerr <<
"Tracer Error: " << message << std::endl;
472 unsigned int len = 0;
475 for (
size_t i=1; i<=v.size(); i++ ) {
478 if ( spl.size() != 2 ) {
479 safe_output(
"WARNING: Cannot parse -out:levels setting '"+v[i]+
"'. Does not follow the format of 'tracer:level'. Ignoring.");
484 if ( spl[1] ==
"all" && len == 0 ) flag =
true;
486 if ( spl[1] == ch ) flag=
true;
489 if ( ch.size() > spl[1].size() ) {
490 std::string
s(ch); s.resize(spl[1].
size());
491 if ( s == spl[1] ) flag=
true;
494 if ( flag && ( len <= spl[1].
size() ) ) {
499 if ( spl2_lower ==
"fatal" ) res =
t_fatal;
500 if ( spl2_lower ==
"error" || spl2_lower ==
"errors" ) res =
t_error;
501 if ( spl2_lower ==
"warning" || spl2_lower ==
"warnings" ) res =
t_warning;
502 if ( spl2_lower ==
"info" ) res =
t_info;
503 if ( spl2_lower ==
"debug" ) res =
t_debug;
504 if ( spl2_lower ==
"trace" ) res =
t_trace;
506 safe_output(
"WARNING: The setting '" + spl[2] +
"' is not recognized as a valid tracer level." );
522 template <
class out_stream>
527 for (
size_t i=0; i<s.size(); i++ ) {
560 prepend_channel_name<otstream>( *
ios_hook(), str );
566 prepend_channel_name<std::ostream>( *
final_stream(), str );
616 std::vector< Tracer * > &
std::string timestamp()
Generate timestamp string.
int priority() const
get/set tracer priority level.
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Class to hold all Terminal ASCII codes as static data for CSI_Sequence. Note: that on non-tty termina...
char lowercased(char const c)
Lowercased Copy of a Character.
static CSI_Sequence const CSI_Underline("\x1b[4m")
static utility::CSI_Sequence bgCyan
static CSI_Sequence const CSI_bgYellow("\x1b[43m")
Common function to build vector, vector0, vector1, map.
static CSI_Sequence const CSI_bgRed("\x1b[41m")
static utility::CSI_Sequence Cyan
static void safe_output(std::string const &)
Output a message in a manner that is safe if the Tracers/output are poorly initialized.
bool is_flushed() const
Return true if inner string buffer is empty.
void prepend_channel_name(out_stream &sout, std::string const &str)
static utility::CSI_Sequence Red
static CSI_Sequence const CSI_Bold("\x1b[1m")
bool visibility_calculated_
is channel visibility already calculated?
static void flush_all_tracers()
static utility::CSI_Sequence bgBlack
int priority_
channel output priority level
virtual void t_flush(std::string const &)
overload member function.
utility::vector1< std::string > levels
list of muted channels
int level
system priority level
void calculate_visibility()
determine the visibility of the proxy
FileVectorOptionKey const s
static bool & ios_hook_raw_()
should the ios_hook_ the raw output?
TracerPriority
Priority levels for T() and Tracer object, modeled on the log4j project and its offspring. Priorities in Tracer are still ints so users can pass other arbitrary integer values (for now).
static void set_new_final_stream(std::ostream *new_final_stream)
static CSI_Sequence const CSI_Blue("\x1b[34m")
BooleanOptionKey const raw
static void set_default_final_stream()
bool timestamp
should a timestamp be added to the channel name?
static CSI_Sequence const CSI_Black("\x1b[30m")
static CSI_Sequence const CSI_bgBlue("\x1b[44m")
static CSI_Sequence const CSI_bgGreen("\x1b[42m")
static CSI_Sequence const CSI_Yellow("\x1b[33m")
static bool in(utility::vector1< std::string > const &, std::string const channel, bool strict)
return true if channel is inside vector, some logic apply.
static bool initial_tracers_visibility_calculated_
std::vector< Tracer * > & all_tracers()
bool muted_
is channel muted ?
static CSI_Sequence const CSI_Red("\x1b[31m")
static utility::CSI_Sequence bgRed
static CSI_Sequence const CSI_bgWhite("\x1b[47m")
Tracer & T(std::string const &channel, TracerPriority priority)
T is special function for assign tracer property on the static object.
static utility::vector1< std::string > monitoring_list_
list of channels for which outout should be redirected.
void flush_all_channels()
flush tracer buffer and flush buffers of all sub-channels ie: Fatal, Error, Warning, Info, Debug, Trace
utility::vector1< std::string > string_split(std::string const &in, char splitchar)
static CSI_Sequence const CSI_Green("\x1b[32m")
Fstring::size_type len(Fstring const &s)
Length.
utility::vector1< std::string > split(const std::string &s)
split given std::string using ' ' symbol.
static bool & super_mute_()
global super mute flag that allow to mute all io no matter what.
StringVectorOptionKey const mute
static CSI_Sequence const CSI_bgCyan("\x1b[46m")
std::string channel_name_color_
TracerProxy(Tracer &tracer, int priority, std::string const &channel)
virtual void t_flush(std::string const &)
Flush inner buffer: send it to bound Tracer object, and clean it.
static utility::CSI_Sequence Underline
std::string const & channel_color()
Tracer & Error(TracerPriority priority=t_error)
Predefined Error tracer.
void init(std::string const &channel, std::string const &channel_color, std::string const &channel_name_color, TracerPriority priority, bool muted_by_default)
init Tracer object with given parameters. This is a helper function to be called from various constru...
static utility::CSI_Sequence White
std::string const & channel_name_color()
static utility::CSI_Sequence Reset
vectorL: std::vector with L-based indexing
static otstreamOP & ios_hook()
link to Tracer like object where all output for selecting channels should go.
bool visible() const
Is this tracer currently visible?.
static utility::CSI_Sequence Magenta
std::string const & channel() const
static utility::CSI_Sequence Yellow
static utility::CSI_Sequence bgBlue
utility::pointer::shared_ptr< otstream > otstreamOP
static CSI_Sequence const CSI_bgMagenta("\x1b[45m")
static utility::CSI_Sequence Bold
static OstreamPointer & final_stream()
set ios hook for final tracer stream (deafult is std::cout).
data structure to store all system level options for Tracer system.
Tracer(std::string const &channel="", TracerPriority priority=t_info, bool muted_by_default=false)
Create Tracer object with given channel and priority.
utility::vector1< std::string > muted
list of muted channels
static utility::CSI_Sequence Blue
Tracer & Warning(TracerPriority priority=t_warning)
Predefined Warning tracer.
bool print_channel_name
should channel name be printed during the IO?
bool begining_of_the_line_
is current printing position a begining of the line?
static utility::CSI_Sequence bgWhite
static utility::CSI_Sequence bgYellow
static TracerManager * instance_
static TracerManager * get_instance()
std::string channel_color_
default colors for tracer output and tracer channel-name string (ie color of string such as: 'core...
static CSI_Sequence const CSI_White("\x1b[37m")
static int mpi_rank_
Mpi rank is this process
static utility::CSI_Sequence Black
int string2int(std::string st)
convert a string to an int, returns -1 on failure
ocstream cout(std::cout)
Wrapper around std::cout.
vector1: std::vector with 1-based indexing
std::ostream * OstreamPointer
void calculate_visibility()
calcualte visibility of the current object depending of the channel name and priority.
static void set_ios_hook(otstreamOP tr, std::string const &monitoring_channels_list, bool raw=true)
set ios hook for all tracer io operation.
static std::string const & get_all_channels_string()
virtual void t_flush(std::string const &)
overload member function.
static bool calculate_tracer_level(utility::vector1< std::string > const &v, std::string const ch, bool strict, int &res)
calculate channel priority with hierarchy in mind.
Tracer & operator()(int priority)
static CSI_Sequence const CSI_Reset("\x1b[0m")
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
TracerProxy Fatal
channels with predefined priority levels.
static utility::CSI_Sequence Green
static CSI_Sequence const CSI_bgBlack("\x1b[40m")
All system functions in utility that have no other home.
utility::vector1< std::string > unmuted
list of unmuted channels
std::string channel_
Data members.
Simple singleton class to hold the all_tracers_ array, which otherwise suffers from funky double-cons...
Some std::string helper functions.
THREAD_LOCAL basic::Tracer tr("struc_set_fragment_picker")
static TracerOptions tracer_options_
global option collection for Tracer IO.
static utility::CSI_Sequence bgGreen
std::vector< Tracer * > all_tracers_
bool visible_
is channel visible?
static void calculate_tracer_visibilities()
This function should be invoked after the options system has been initialized, so that the visibility...
static utility::CSI_Sequence bgMagenta
static CSI_Sequence const CSI_Cyan("\x1b[36m")
bool muted_by_default_
is channel muted by default?
static CSI_Sequence const CSI_Magenta("\x1b[35m")
virtual void output_callback(std::string)=0
FileVectorOptionKey const t
int mute_level_
channel muted priority level (above which level is channel muted), calculated using user suppied -lev...