Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Tracer.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file src/basic/unti/tracer.cc
11 /// @brief Tracer IO system
12 /// @author Sergey Lyskov
13 
14 
15 #ifdef USEMPI
16 #include <mpi.h>
17 #endif
18 
19 #include <basic/Tracer.hh>
20 #include <ObjexxFCL/string.functions.hh> // for lowercased
21 #include <algorithm> // for find
22 #include <cassert> // for assert
23 #include <cstddef> // for size_t
24 #include <iosfwd> // for string, ostream
25 #include <iostream> // for cout, cerr
26 #include <ostream> // for operator<<, basic_ostream
27 #include <platform/types.hh> // for Size
28 #include <string> // for allocator, operator==, basi...
29 #include <utility/CSI_Sequence.hh> // for CSI_Sequence, CSI_Black
30 #include <utility/basic_sys_util.hh> // for timestamp
31 #include <utility/string_util.hh> // for split, string2int, string_s...
32 #include <utility/tools/make_vector.hh> // for make_vector
33 #include <utility/vector1.hh> // for vector1
34 #include <utility/vectorL.hh> // for vectorL
35 #include <vector> // for vector, vector<>::iterator
36 
37 #ifndef WIN32
38 #include <unistd.h>
39 #else
40 #include <io.h>
41 #endif
42 
43 #ifdef CXX11
44 #ifdef MULTI_THREADED
45 
46 #include <mutex>
47 
48 #endif
49 #endif
50 
51 
52 namespace basic {
53 
55 
56 TracerManager * TracerManager::instance_( 0 );
57 
58 #ifdef CXX11
59 #ifdef MULTI_THREADED
60 
61 /// @brief This mutex ensures that any time static data is read from or written to by
62 /// a tracer object, that the thread gets exclusive access to it.
63 /// In particular, the all_tracers_ array and the initial_tracers_visibility_calculated_
64 /// booleal need to be carefully locked so that multiple threads do not try to
65 /// initialize Tracers simultaneously, or try to inialize a Tracer while another thread
66 /// is calling calculate_tracer_visibilities().
67 std::recursive_mutex tracer_static_data_mutex;
68 
69 #endif
70 #endif
71 
72 
74 {
75  static std::ostream * final_stream_ = &std::cout;
76  return final_stream_;
77 }
78 
79 void Tracer::set_new_final_stream(std::ostream *new_final_stream)
80 {
81  final_stream() = new_final_stream;
82 }
83 
85 {
87 }
88 
89 
91 {
92  static otstreamOP hook;
93  return hook;
94 }
95 
96 bool &Tracer::ios_hook_raw_() // uninitilized, we will set correct output during set_ios_hook(...)
97 {
98  static bool raw = true;
99  return raw;
100 }
101 
103 
104 
105 //std::string const Tracer::AllChannels("_Really_Unique_String_Object_To_Identify_All_Tracer_Channels__qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM");
106 std::string const & Tracer::get_all_channels_string() {
107  static std::string const all_channels("_Really_Unique_String_Object_To_Identify_All_Tracer_Channels__qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM");
108  return all_channels;
109 }
110 
111 
113 
115 {
116  static bool mute = false;
117  return mute;
118 }
119 
120 int Tracer::mpi_rank_( 0 );
121 
122 
123 /// @details Static objects holding various ASCII CSI codes (see utility/CSI_Sequence.hh)
127 
129  Tracer & tracer,
130  int priority,
131  std::string const & channel
132 ) :
133  tracer_(tracer),
134  priority_(priority),
135  channel_(channel),
136  visible_(true),
137  visibility_calculated_(false)
138 {}
139 
140 
141 void
143 {
144  bool muted; int mute_level;
145  Tracer::calculate_visibility( channel_, priority_, visible_, muted, mute_level, tracer_.muted_by_default_ );
146  visibility_calculated_ = true;
147 }
148 
149 
150 /// Flush inner buffer: send it to bound Tracer object, and clean it.
151 void Tracer::TracerProxy::t_flush(std::string const & s)
152 {
154 
155  int pr = tracer_.priority();
156  tracer_.priority(priority_);
157  tracer_ << s;
158  tracer_.flush();
159  tracer_.priority(pr);
160 }
161 
162 
164 {
165  /// Do nothing here - contents will get flushed in Tracer destructor.
166 }
167 
169 {
170 #ifdef CXX11
171 #ifdef MULTI_THREADED
172  std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
173 #endif
174 #endif
175 
176  std::vector< Tracer * > & all_tracers( TracerManager::get_instance()->all_tracers() );
177  for ( std::vector<Tracer *>::iterator it = all_tracers.begin();
178  it != all_tracers.end(); ++it ) {
179  (*it)->flush_all_channels();
180  }
181 
182 }
183 
184 void
186 {
187 #ifdef CXX11
188 #ifdef MULTI_THREADED
189  std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
190 #endif
191 #endif
193  std::vector< Tracer * > & all_tracers( TracerManager::get_instance()->all_tracers() );
194  for ( platform::Size ii = 0; ii < all_tracers.size(); ++ii ) {
195  all_tracers[ ii ]->calculate_visibility();
196  }
197 }
198 
199 
200 /// @details Constructor of Tracer object.
201 /// Since most of the Tracer object will be created as static - they Constuctor will be called before
202 /// Option system is initialized. So we can't really calculate any vizibility or priority here.
203 /// Such calculation should be done later, whe first IO operation happend.
204 /// @todo Default Tracer level should probably be modified to t_info here and in options defn.
205 Tracer::Tracer(std::string const & channel, TracerPriority priority, bool muted_by_default) :
206  Fatal( *this, t_fatal, channel ),
207  Error( *this, t_error, channel ),
208  Warning( *this, t_warning, channel ),
209  Info( *this, t_info, channel ),
210  Debug( *this, t_debug, channel ),
211  Trace( *this, t_trace, channel )
212 {
213  init(channel, "", "", priority, muted_by_default);
214 }
215 
216 
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 ),
219  Error( *this, t_error, channel ),
220  Warning( *this, t_warning, channel ),
221  Info( *this, t_info, channel ),
222  Debug( *this, t_debug, channel ),
223  Trace( *this, t_trace, channel )
224 {
225  init(channel, channel_color, channel_name_color, priority, muted_by_default);
226 }
227 
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)
229 {
230  mute_level_ = -1;
231  visible_ = true;
232  muted_ = false;
233  muted_by_default_ = muted_by_default;
234  begining_of_the_line_ = true;
235  visibility_calculated_ = false;
236 
237  channel_ = channel;
239 
242 
243 #ifdef CXX11
244 #ifdef MULTI_THREADED
245  std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
246 #endif
247 #endif
248 
251  }
252 
253  TracerManager::get_instance()->all_tracers().push_back( this );
254 }
255 
257 {
258  /// We could not gurantee that option system was not deleted already, so we must disable
259  /// options access. However we don't want channel to withhold any output since it can be important.
260  /// We check if anything still present in channel buffer, and if it is - print it contents with warning.
261 
262  std::vector< otstream* > v = utility::tools::make_vector< otstream* >(
263  this, &Fatal, &Error, &Warning,
264  &Info, &Debug, &Trace);
265 
266  //bool need_flush = false;
267  for ( size_t i=0; i<v.size(); i++ ) {
268  if ( !v[i]->is_flushed() ) {
269  //v[i]->flush();
270  (*v[i]) << std::endl;
271  (*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;
272  }
273  }
274 
275 #ifdef CXX11
276 #ifdef MULTI_THREADED
277  std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
278 #endif
279 #endif
280 
281  //std::cout << "Erasing tracer: " << channel_ << std::endl;
282  std::vector< Tracer * > & all_tracers( TracerManager::get_instance()->all_tracers() );
283  std::vector< Tracer * >::iterator iter_this = std::find( all_tracers.begin(), all_tracers.end(), this );
284  assert( iter_this != all_tracers.end() );
285  all_tracers.erase( iter_this );
286 }
287 
288 
289 /// @details re-init using data from another tracer object.
290 void Tracer::init( Tracer const & tr )
291 {
292  channel_ = tr.channel_;
293  priority_ = tr.priority_;
294 
295  visible_ = true;
296  muted_ = false;
297  mute_level_ = -1;
298  begining_of_the_line_ = true;
299  visibility_calculated_ = false;
300 
301 #ifdef CXX11
302 #ifdef MULTI_THREADED
303  std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
304 #endif
305 #endif
306 
309  }
310 
311 }
312 
314 {
315  std::vector< otstream* > v = utility::tools::make_vector< otstream* >(
316  this, &Fatal, &Error, &Warning,
317  &Info, &Debug, &Trace);
318 
319  for ( size_t i=0; i<v.size(); i++ ) {
320  v[i]->flush();
321  }
322 }
323 
324 bool Tracer::visible( int priority ) const {
325 
326  if ( muted_ ) return false;
327  if ( priority > mute_level_ ) return false;
328  return true;
329 
330 }
331 
332 Tracer &
333 Tracer::operator ()(int priority)
334 {
335  this->priority(priority);
336  return *this;
337 }
338 
339 void Tracer::priority(int priority)
340 {
342  if ( visibility_calculated_ ) {
343  /*
344 #ifdef EXPERIMENTAL_TRACER_FEATURES
345  muted_ = priority >= mute_level_;
346 #endif // EXPERIMENTAL_TRACER_FEATURES
347  */
348  //visible_ = !muted_ && ( priority <= tracer_options_.level );
349  visible_ = !muted_ && ( priority <= mute_level_ );
350  }
351 }
352 
353 
354 /// @details Calculate visibility of current Tracer object and all of its proxies
356 {
364  visibility_calculated_ = true;
365 
366 }
367 
368 
369 /// @details Calculate visibility (static version) of current Tracer object using channel name and priority.
370 /// result stored in 'muted' and 'visible'.
372  std::string const & channel,
373  int priority,
374  bool & visible,
375  bool & muted,
376  int & mute_level_,
377  bool muted_by_default
378 )
379 {
380  visible = false;
381  if ( in(tracer_options_.muted, "all", true) ) {
382  if ( in(tracer_options_.unmuted, channel, false) ) visible = true;
383  else visible = false;
384  } else {
385  if ( in(tracer_options_.unmuted, "all", true) ) {
386  if ( in(tracer_options_.muted, channel, false) ) visible = false;
387  else visible = true;
388  } else { /// default bechavior: unmute unless muted_by_default is true
389  if ( muted_by_default ) {
390  if ( in(tracer_options_.unmuted, channel, false) ) visible = true;
391  else visible = false;
392  } else {
393  if ( in(tracer_options_.muted, channel, false) ) visible = false;
394  else visible = true;
395  }
396  }
397  }
398 
399  //if we are in MPI mode --- most of the time one doesn't want to see output from all nodes just the master and 1st client is plenty ..
400 #ifdef USEMPI
401  int already_initialized = 0;
402  int already_finalized = 0;
403  MPI_Initialized( &already_initialized );
404  MPI_Finalized( &already_finalized );
405  if ( already_initialized != 0 && already_finalized == 0 ) {
406  int mpi_rank, mpi_nprocs;
407  MPI_Comm_rank (MPI_COMM_WORLD, &mpi_rank);/* get current process id */
408  MPI_Comm_size (MPI_COMM_WORLD, &mpi_nprocs);/* get number of processes */
410  }
411 
412  if ( in(tracer_options_.muted, "all_high_mpi_rank", true ) ) {
413  if ( mpi_rank_>=2 ) visible = false; //* visible: master and 1st client: rank 0 and rank1
414  }
415 
416  if ( in(tracer_options_.muted, "all_high_mpi_rank_filebuf", true ) ) {
417  if ( mpi_rank_>=4 ) visible = false; //* visible: master, filebuf and 1st client: rank 0, 1, 2
418  }
419 
420 #endif
421  muted = !visible;
422 
423  mute_level_ = tracer_options_.level;
424  calculate_tracer_level(tracer_options_.levels, channel, false, mute_level_);
425  //std::cout << "levels:" << tracer_options_.levels <<" ch:" << channel << " mute_level:" << mute_level_ << " priority:" << priority << std::endl;
426 
427  if ( priority > mute_level_ ) visible = false;
428 }
429 
430 
431 /// @details Check if string representing channel 'ch' is in vector<string> v. Return true if channel
432 /// is in vector, false otherwise.
433 /// Two mode of operation:
434 /// Strict: strict==true - channels compared verbatim.
435 /// Regular: strict==false - comparing with hierarchy in mind,
436 /// ie: ch='basic.pose' v[0]='basic' --> will yield true.
437 bool Tracer::in(utility::vector1<std::string> const & v, std::string const ch, bool strict)
438 {
439  for ( size_t i=1; i<=v.size(); i++ ) {
440  if ( v[i] == ch ) return true;
441 
442  if ( !strict ) {
443  if ( ch.size() > v[i].size() ) {
444  std::string s(ch); s.resize(v[i].size());
445  if ( s == v[i] ) return true;
446  }
447  }
448  }
449  return false;
450 }
451 
452 /// @brief Output a message in a manner that is safe if the Tracers/output are poorly initialized.
453 void Tracer::safe_output(std::string const & message ) {
454  if ( ios_hook() ) {
455  *ios_hook() << message << std::endl;
456  } else if ( final_stream() ) {
457  *final_stream() << message << std::endl;
458  } else {
459  std::cerr << "Tracer Error: " << message << std::endl;
460  }
461 }
462 
463 /// Same as before but return integer value for matched channel or closest match (we asume that 'v' in levels format, ie like: <channel name>:level )
464 bool Tracer::calculate_tracer_level(utility::vector1<std::string> const & v, std::string const ch, bool strict, int &res)
465 {
466  unsigned int len = 0;
467  bool math = false;
468  //std::cout << "Entring:calculate_tracer_level: v=" << v << " ch:" << ch << std::endl;
469  for ( size_t i=1; i<=v.size(); i++ ) {
470  bool flag = false;
472  if ( spl.size() != 2 ) {
473  safe_output("WARNING: Cannot parse -out:levels setting '"+v[i]+"'. Does not follow the format of 'tracer:level'. Ignoring.");
474  continue;
475  }
476  //std::cout << "Split:" << spl << " size:" << spl[1].size() << std::endl;
477 
478  if ( spl[1] == "all" && len == 0 ) flag = true; // we can asume that 'all' is shorter then any valid core/protocol path... but we don't!
479 
480  if ( spl[1] == ch ) flag=true;
481 
482  if ( !strict ) {
483  if ( ch.size() > spl[1].size() ) {
484  std::string s(ch); s.resize(spl[1].size());
485  if ( s == spl[1] ) flag=true;
486  }
487  }
488  if ( flag && ( len <= spl[1].size() ) ) { // If specified twice, use the later one.
489  math = true;
490  len = spl[1].size();
491  res = utility::string2int(spl[2]);
492  std::string const spl2_lower = ObjexxFCL::lowercased( spl[2] );
493  if ( spl2_lower == "fatal" ) res = t_fatal;
494  if ( spl2_lower == "error" || spl2_lower == "errors" ) res = t_error;
495  if ( spl2_lower == "warning" || spl2_lower == "warnings" ) res = t_warning;
496  if ( spl2_lower == "info" ) res = t_info;
497  if ( spl2_lower == "debug" ) res = t_debug;
498  if ( spl2_lower == "trace" ) res = t_trace;
499  if ( res == -1 ) {
500  safe_output( "WARNING: The setting '" + spl[2] + "' is not recognized as a valid tracer level." );
501  res = t_info; // Set such that you get standard amount of output instead of none.
502  }
503  //std::cout << "Match:" << spl << " ch:" << ch << " res:"<< res << std::endl;
504  } else {
505  //std::cout << "Fail:" << spl << " ch:" << ch << " res:"<< res << std::endl;
506  }
507 
508  }
509  //std::cout << "Leaving:calculate_tracer_level: v=" << v << " ch:" << ch << " match:" << math <<" res:"<< res << std::endl;
510  return math;
511 }
512 
513 
514 /// @dtails Write the contents of str to sout prepending the channel
515 /// name on each line if the print_channel_name flag is set.
516 template <class out_stream>
517 void Tracer::prepend_channel_name( out_stream & sout, std::string const &str )
518 {
519  std::string s = str;
520  begining_of_the_line_ = true;
521  for ( size_t i=0; i<s.size(); i++ ) {
522  if ( begining_of_the_line_ ) {
523 
524  sout << this->Reset;
525 
527  sout << channel_name_color_ << channel_ << ": ";
528  }
529 
530 #ifdef USEMPI
531  sout << "(" << mpi_rank_ << ") ";
532 #endif
533 
534  if ( tracer_options_.timestamp ) {
535  sout << utility::timestamp() << " ";
536  }
537 
538  sout << this->Reset << channel_color_;
539 
540  begining_of_the_line_ = false;
541  }
542  sout << s[i];
543  }
544 }
545 
546 
547 /// @details Inform Tracer that is contents was modified, and IO is in order.
548 void Tracer::t_flush(std::string const &str)
549 {
551  if ( ios_hook() && ios_hook().get()!=this &&
553  if ( ios_hook_raw_() || visible() ) {
554  prepend_channel_name<otstream>( *ios_hook(), str );
555  ios_hook()->flush();
556  }
557  }
558 
559  if ( !super_mute_() && visible() ) {
560  prepend_channel_name<std::ostream>( *final_stream(), str );
561  }
562 }
563 
564 
565 /// @details Return reference to static Tracer object (after setting it channel and priority).
566 Tracer &
567 T(std::string const & channel, TracerPriority priority)
568 {
569  static Tracer * t = new Tracer();
570  t->channel_ = channel;
571  t->priority_ = priority;
573  t->begining_of_the_line_ = true;
574  return *t;
575 }
576 
577 
578 /// @details Set OStringStream object to which all Tracers output
579 /// listed in the monitoring_channels_list should be copied. Note
580 /// this copies the output of channels even if they are invisible or
581 /// muted.
582 // void Tracer::set_ios_hook(otstreamOP tr, std::string const & monitoring_channels_list)
583 // {
584 // ios_hook_ = tr;
585 // monitoring_list_ = utility::split(monitoring_channels_list);
586 // ios_hook_raw_ = true;
587 // }
588 /// When raw==false same as above above but gives the option get only the
589 /// visible and unmuted tracers. It can be useful to get the raw
590 /// output for applications like the comparing tracers, where the
591 /// output should not change with command line parameters. It can be
592 /// useful to get the non-raw output in applications like using the
593 /// jd2 with MPI, where the output each job should match the output if
594 /// it was run on a single processor.
595 void Tracer::set_ios_hook(otstreamOP tr, std::string const & monitoring_channels_list, bool raw)
596 {
597  ios_hook() = tr;
598  monitoring_list_ = utility::split(monitoring_channels_list);
599  ios_hook_raw_() = raw;
600 }
601 
604  if ( instance_ == 0 ) {
605  instance_ = new TracerManager;
606  }
607  return instance_;
608 }
609 
610 std::vector< Tracer * > &
612  return all_tracers_;
613 }
614 
616 
617 void PyTracer::t_flush(std::string const &str)
618 {
619  buf_ += str;
620  output_callback(str);
621 }
622 
623 
624 } // namespace basic
std::string timestamp()
Generate timestamp string.
int priority() const
get/set tracer priority level.
Definition: Tracer.hh:196
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Definition: ocstream.hh:290
Class to hold all Terminal ASCII codes as static data for CSI_Sequence. Note: that on non-tty termina...
Definition: CSI_Sequence.hh:26
char lowercased(char const c)
Lowercased Copy of a Character.
static CSI_Sequence const CSI_Underline("\x1b[4m")
static utility::CSI_Sequence bgCyan
Definition: Tracer.hh:265
static CSI_Sequence const CSI_bgYellow("\x1b[43m")
Common function to build vector, vector0, vector1, map.
virtual ~Tracer()
Definition: Tracer.cc:256
static CSI_Sequence const CSI_bgRed("\x1b[41m")
static utility::CSI_Sequence Cyan
Definition: Tracer.hh:265
static void safe_output(std::string const &)
Output a message in a manner that is safe if the Tracers/output are poorly initialized.
Definition: Tracer.cc:453
bool is_flushed() const
Return true if inner string buffer is empty.
Definition: Tracer.hh:79
void prepend_channel_name(out_stream &sout, std::string const &str)
Definition: Tracer.cc:517
static utility::CSI_Sequence Red
Definition: Tracer.hh:265
static CSI_Sequence const CSI_Bold("\x1b[1m")
bool visibility_calculated_
is channel visibility already calculated?
Definition: Tracer.hh:348
static void flush_all_tracers()
Definition: Tracer.cc:168
static utility::CSI_Sequence bgBlack
Definition: Tracer.hh:265
int priority_
channel output priority level
Definition: Tracer.hh:330
virtual void t_flush(std::string const &)
overload member function.
Definition: Tracer.cc:548
utility::vector1< std::string > levels
list of muted channels
Definition: Tracer.hh:125
dictionary size
Definition: amino_acids.py:44
int level
system priority level
Definition: Tracer.hh:110
void calculate_visibility()
determine the visibility of the proxy
Definition: Tracer.cc:142
static bool & ios_hook_raw_()
should the ios_hook_ the raw output?
Definition: Tracer.cc:96
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).
Definition: Tracer.hh:38
static void set_new_final_stream(std::ostream *new_final_stream)
Definition: Tracer.cc:79
static CSI_Sequence const CSI_Blue("\x1b[34m")
static void set_default_final_stream()
Definition: Tracer.cc:84
bool timestamp
should a timestamp be added to the channel name?
Definition: Tracer.hh:116
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.
Definition: Tracer.cc:437
static bool initial_tracers_visibility_calculated_
Definition: Tracer.hh:363
std::vector< Tracer * > & all_tracers()
Definition: Tracer.cc:611
bool muted_
is channel muted ?
Definition: Tracer.hh:339
static CSI_Sequence const CSI_Red("\x1b[31m")
static utility::CSI_Sequence bgRed
Definition: Tracer.hh:265
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.
Definition: Tracer.cc:567
TracerProxy Warning
Definition: Tracer.hh:262
static utility::vector1< std::string > monitoring_list_
list of channels for which outout should be redirected.
Definition: Tracer.hh:358
TracerProxy Info
Definition: Tracer.hh:262
void flush_all_channels()
flush tracer buffer and flush buffers of all sub-channels ie: Fatal, Error, Warning, Info, Debug, Trace
Definition: Tracer.cc:313
utility::vector1< std::string > string_split(std::string const &in, char splitchar)
Definition: string_util.cc:158
static CSI_Sequence const CSI_Green("\x1b[32m")
Fstring::size_type len(Fstring const &s)
Length.
Definition: Fstring.hh:2207
utility::vector1< std::string > split(const std::string &s)
split given std::string using ' ' symbol.
Definition: string_util.cc:59
static bool & super_mute_()
global super mute flag that allow to mute all io no matter what.
Definition: Tracer.cc:114
static CSI_Sequence const CSI_bgCyan("\x1b[46m")
TracerProxy Trace
Definition: Tracer.hh:262
std::string channel_name_color_
Definition: Tracer.hh:327
TracerProxy(Tracer &tracer, int priority, std::string const &channel)
Definition: Tracer.cc:128
virtual void t_flush(std::string const &)
Flush inner buffer: send it to bound Tracer object, and clean it.
Definition: Tracer.cc:151
static utility::CSI_Sequence Underline
Definition: Tracer.hh:265
std::string const & channel_color()
Definition: Tracer.hh:202
Tracer & Error(TracerPriority priority=t_error)
Predefined Error tracer.
Definition: Tracer.hh:395
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...
Definition: Tracer.cc:228
static utility::CSI_Sequence White
Definition: Tracer.hh:265
std::string const & channel_name_color()
Definition: Tracer.hh:205
Tracer IO system.
static utility::CSI_Sequence Reset
Definition: Tracer.hh:265
vectorL: std::vector with L-based indexing
static otstreamOP & ios_hook()
link to Tracer like object where all output for selecting channels should go.
Definition: Tracer.cc:90
bool visible() const
Is this tracer currently visible?.
Definition: Tracer.hh:190
TracerProxy Error
Definition: Tracer.hh:262
static utility::CSI_Sequence Magenta
Definition: Tracer.hh:265
std::string const & channel() const
Definition: Tracer.hh:200
static utility::CSI_Sequence Yellow
Definition: Tracer.hh:265
Terminal ASCII codes.
static utility::CSI_Sequence bgBlue
Definition: Tracer.hh:265
utility::pointer::shared_ptr< otstream > otstreamOP
Definition: Tracer.hh:103
static CSI_Sequence const CSI_bgMagenta("\x1b[45m")
static utility::CSI_Sequence Bold
Definition: Tracer.hh:265
static OstreamPointer & final_stream()
set ios hook for final tracer stream (deafult is std::cout).
Definition: Tracer.cc:73
data structure to store all system level options for Tracer system.
Definition: Tracer.hh:107
Tracer(std::string const &channel="", TracerPriority priority=t_info, bool muted_by_default=false)
Create Tracer object with given channel and priority.
Definition: Tracer.cc:205
utility::vector1< std::string > muted
list of muted channels
Definition: Tracer.hh:119
static utility::CSI_Sequence Blue
Definition: Tracer.hh:265
Tracer & Warning(TracerPriority priority=t_warning)
Predefined Warning tracer.
Definition: Tracer.hh:398
bool print_channel_name
should channel name be printed during the IO?
Definition: Tracer.hh:113
bool begining_of_the_line_
is current printing position a begining of the line?
Definition: Tracer.hh:345
static utility::CSI_Sequence bgWhite
Definition: Tracer.hh:265
static utility::CSI_Sequence bgYellow
Definition: Tracer.hh:265
static TracerManager * instance_
Definition: Tracer.hh:387
static TracerManager * get_instance()
Definition: Tracer.cc:603
std::string channel_color_
default colors for tracer output and tracer channel-name string (ie color of string such as: 'core...
Definition: Tracer.hh:327
static CSI_Sequence const CSI_White("\x1b[37m")
static int mpi_rank_
Mpi rank is this process
Definition: Tracer.hh:369
static utility::CSI_Sequence Black
Definition: Tracer.hh:265
int string2int(std::string st)
convert a string to an int, returns -1 on failure
Definition: string_util.cc:217
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
vector1: std::vector with 1-based indexing
std::ostream * OstreamPointer
Definition: Tracer.hh:174
void calculate_visibility()
calcualte visibility of the current object depending of the channel name and priority.
Definition: Tracer.cc:355
static void set_ios_hook(otstreamOP tr, std::string const &monitoring_channels_list, bool raw=true)
set ios hook for all tracer io operation.
Definition: Tracer.cc:595
int mpi_rank()
Definition: mpi_util.cc:254
static std::string const & get_all_channels_string()
Definition: Tracer.cc:106
virtual void t_flush(std::string const &)
overload member function.
Definition: Tracer.cc:617
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.
Definition: Tracer.cc:464
Tracer & operator()(int priority)
Definition: Tracer.cc:333
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 ...
Definition: Tracer.hh:134
TracerProxy Fatal
channels with predefined priority levels.
Definition: Tracer.hh:262
static utility::CSI_Sequence Green
Definition: Tracer.hh:265
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
Definition: Tracer.hh:122
std::string channel_
Data members.
Definition: Tracer.hh:324
Simple singleton class to hold the all_tracers_ array, which otherwise suffers from funky double-cons...
Definition: Tracer.hh:378
Some std::string helper functions.
THREAD_LOCAL basic::Tracer tr("struc_set_fragment_picker")
static TracerOptions tracer_options_
global option collection for Tracer IO.
Definition: Tracer.hh:361
std::size_t Size
Definition: types.hh:37
static utility::CSI_Sequence bgGreen
Definition: Tracer.hh:265
std::vector< Tracer * > all_tracers_
Definition: Tracer.hh:388
int mpi_nprocs()
Definition: mpi_util.cc:265
bool visible_
is channel visible?
Definition: Tracer.hh:336
static void calculate_tracer_visibilities()
This function should be invoked after the options system has been initialized, so that the visibility...
Definition: Tracer.cc:185
static utility::CSI_Sequence bgMagenta
Definition: Tracer.hh:265
static CSI_Sequence const CSI_Cyan("\x1b[36m")
TracerProxy Debug
Definition: Tracer.hh:262
bool muted_by_default_
is channel muted by default?
Definition: Tracer.hh:342
static CSI_Sequence const CSI_Magenta("\x1b[35m")
virtual void output_callback(std::string)=0
std::string buf_
Definition: Tracer.hh:418
int mute_level_
channel muted priority level (above which level is channel muted), calculated using user suppied -lev...
Definition: Tracer.hh:333