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  /// PyRosetta final stream could be redirected to some Python object which might be already got destroyed during Python exit
267 #ifndef PYROSETTA
268  //set_new_final_stream( &std::cerr );
269  //set_ios_hook(otstreamOP(), "");
270 
271  //bool need_flush = false;
272  for ( size_t i=0; i<v.size(); i++ ) {
273  if ( !v[i]->is_flushed() ) {
274  //v[i]->flush();
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;
277  }
278  }
279 #endif
280 
281 #ifdef CXX11
282 #ifdef MULTI_THREADED
283  std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
284 #endif
285 #endif
286 
287  //std::cout << "Erasing tracer: " << channel_ << std::endl;
288  std::vector< Tracer * > & all_tracers( TracerManager::get_instance()->all_tracers() );
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 );
292 }
293 
294 
295 /// @details re-init using data from another tracer object.
296 void Tracer::init( Tracer const & tr )
297 {
298  channel_ = tr.channel_;
299  priority_ = tr.priority_;
300 
301  visible_ = true;
302  muted_ = false;
303  mute_level_ = -1;
304  begining_of_the_line_ = true;
305  visibility_calculated_ = false;
306 
307 #ifdef CXX11
308 #ifdef MULTI_THREADED
309  std::lock_guard< std::recursive_mutex > lock( tracer_static_data_mutex );
310 #endif
311 #endif
312 
315  }
316 
317 }
318 
320 {
321  std::vector< otstream* > v = utility::tools::make_vector< otstream* >(
322  this, &Fatal, &Error, &Warning,
323  &Info, &Debug, &Trace);
324 
325  for ( size_t i=0; i<v.size(); i++ ) {
326  v[i]->flush();
327  }
328 }
329 
330 bool Tracer::visible( int priority ) const {
331 
332  if ( muted_ ) return false;
333  if ( priority > mute_level_ ) return false;
334  return true;
335 
336 }
337 
338 Tracer &
339 Tracer::operator ()(int priority)
340 {
341  this->priority(priority);
342  return *this;
343 }
344 
345 void Tracer::priority(int priority)
346 {
348  if ( visibility_calculated_ ) {
349  /*
350 #ifdef EXPERIMENTAL_TRACER_FEATURES
351  muted_ = priority >= mute_level_;
352 #endif // EXPERIMENTAL_TRACER_FEATURES
353  */
354  //visible_ = !muted_ && ( priority <= tracer_options_.level );
355  visible_ = !muted_ && ( priority <= mute_level_ );
356  }
357 }
358 
359 
360 /// @details Calculate visibility of current Tracer object and all of its proxies
362 {
370  visibility_calculated_ = true;
371 
372 }
373 
374 
375 /// @details Calculate visibility (static version) of current Tracer object using channel name and priority.
376 /// result stored in 'muted' and 'visible'.
378  std::string const & channel,
379  int priority,
380  bool & visible,
381  bool & muted,
382  int & mute_level_,
383  bool muted_by_default
384 )
385 {
386  visible = false;
387  if ( in(tracer_options_.muted, "all", true) ) {
388  if ( in(tracer_options_.unmuted, channel, false) ) visible = true;
389  else visible = false;
390  } else {
391  if ( in(tracer_options_.unmuted, "all", true) ) {
392  if ( in(tracer_options_.muted, channel, false) ) visible = false;
393  else visible = true;
394  } else { /// default bechavior: unmute unless muted_by_default is true
395  if ( muted_by_default ) {
396  if ( in(tracer_options_.unmuted, channel, false) ) visible = true;
397  else visible = false;
398  } else {
399  if ( in(tracer_options_.muted, channel, false) ) visible = false;
400  else visible = true;
401  }
402  }
403  }
404 
405  //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 ..
406 #ifdef USEMPI
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 ) {
412  int mpi_rank, mpi_nprocs;
413  MPI_Comm_rank (MPI_COMM_WORLD, &mpi_rank);/* get current process id */
414  MPI_Comm_size (MPI_COMM_WORLD, &mpi_nprocs);/* get number of processes */
416  }
417 
418  if ( in(tracer_options_.muted, "all_high_mpi_rank", true ) ) {
419  if ( mpi_rank_>=2 ) visible = false; //* visible: master and 1st client: rank 0 and rank1
420  }
421 
422  if ( in(tracer_options_.muted, "all_high_mpi_rank_filebuf", true ) ) {
423  if ( mpi_rank_>=4 ) visible = false; //* visible: master, filebuf and 1st client: rank 0, 1, 2
424  }
425 
426 #endif
427  muted = !visible;
428 
429  mute_level_ = tracer_options_.level;
430  calculate_tracer_level(tracer_options_.levels, channel, false, mute_level_);
431  //std::cout << "levels:" << tracer_options_.levels <<" ch:" << channel << " mute_level:" << mute_level_ << " priority:" << priority << std::endl;
432 
433  if ( priority > mute_level_ ) visible = false;
434 }
435 
436 
437 /// @details Check if string representing channel 'ch' is in vector<string> v. Return true if channel
438 /// is in vector, false otherwise.
439 /// Two mode of operation:
440 /// Strict: strict==true - channels compared verbatim.
441 /// Regular: strict==false - comparing with hierarchy in mind,
442 /// ie: ch='basic.pose' v[0]='basic' --> will yield true.
443 bool Tracer::in(utility::vector1<std::string> const & v, std::string const ch, bool strict)
444 {
445  for ( size_t i=1; i<=v.size(); i++ ) {
446  if ( v[i] == ch ) return true;
447 
448  if ( !strict ) {
449  if ( ch.size() > v[i].size() ) {
450  std::string s(ch); s.resize(v[i].size());
451  if ( s == v[i] ) return true;
452  }
453  }
454  }
455  return false;
456 }
457 
458 /// @brief Output a message in a manner that is safe if the Tracers/output are poorly initialized.
459 void Tracer::safe_output(std::string const & message ) {
460  if ( ios_hook() ) {
461  *ios_hook() << message << std::endl;
462  } else if ( final_stream() ) {
463  *final_stream() << message << std::endl;
464  } else {
465  std::cerr << "Tracer Error: " << message << std::endl;
466  }
467 }
468 
469 /// 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 )
470 bool Tracer::calculate_tracer_level(utility::vector1<std::string> const & v, std::string const ch, bool strict, int &res)
471 {
472  unsigned int len = 0;
473  bool math = false;
474  //std::cout << "Entring:calculate_tracer_level: v=" << v << " ch:" << ch << std::endl;
475  for ( size_t i=1; i<=v.size(); i++ ) {
476  bool flag = false;
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.");
480  continue;
481  }
482  //std::cout << "Split:" << spl << " size:" << spl[1].size() << std::endl;
483 
484  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!
485 
486  if ( spl[1] == ch ) flag=true;
487 
488  if ( !strict ) {
489  if ( ch.size() > spl[1].size() ) {
490  std::string s(ch); s.resize(spl[1].size());
491  if ( s == spl[1] ) flag=true;
492  }
493  }
494  if ( flag && ( len <= spl[1].size() ) ) { // If specified twice, use the later one.
495  math = true;
496  len = spl[1].size();
497  res = utility::string2int(spl[2]);
498  std::string const spl2_lower = ObjexxFCL::lowercased( spl[2] );
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;
505  if ( res == -1 ) {
506  safe_output( "WARNING: The setting '" + spl[2] + "' is not recognized as a valid tracer level." );
507  res = t_info; // Set such that you get standard amount of output instead of none.
508  }
509  //std::cout << "Match:" << spl << " ch:" << ch << " res:"<< res << std::endl;
510  } else {
511  //std::cout << "Fail:" << spl << " ch:" << ch << " res:"<< res << std::endl;
512  }
513 
514  }
515  //std::cout << "Leaving:calculate_tracer_level: v=" << v << " ch:" << ch << " match:" << math <<" res:"<< res << std::endl;
516  return math;
517 }
518 
519 
520 /// @dtails Write the contents of str to sout prepending the channel
521 /// name on each line if the print_channel_name flag is set.
522 template <class out_stream>
523 void Tracer::prepend_channel_name( out_stream & sout, std::string const &str )
524 {
525  std::string s = str;
526  begining_of_the_line_ = true;
527  for ( size_t i=0; i<s.size(); i++ ) {
528  if ( begining_of_the_line_ ) {
529 
530  sout << this->Reset;
531 
533  sout << channel_name_color_ << channel_ << ": ";
534  }
535 
536 #ifdef USEMPI
537  sout << "(" << mpi_rank_ << ") ";
538 #endif
539 
540  if ( tracer_options_.timestamp ) {
541  sout << utility::timestamp() << " ";
542  }
543 
544  sout << this->Reset << channel_color_;
545 
546  begining_of_the_line_ = false;
547  }
548  sout << s[i];
549  }
550 }
551 
552 
553 /// @details Inform Tracer that is contents was modified, and IO is in order.
554 void Tracer::t_flush(std::string const &str)
555 {
557  if ( ios_hook() && ios_hook().get()!=this &&
559  if ( ios_hook_raw_() || visible() ) {
560  prepend_channel_name<otstream>( *ios_hook(), str );
561  ios_hook()->flush();
562  }
563  }
564 
565  if ( !super_mute_() && visible() ) {
566  prepend_channel_name<std::ostream>( *final_stream(), str );
567  }
568 }
569 
570 
571 /// @details Return reference to static Tracer object (after setting it channel and priority).
572 Tracer &
573 T(std::string const & channel, TracerPriority priority)
574 {
575  static Tracer * t = new Tracer();
576  t->channel_ = channel;
577  t->priority_ = priority;
579  t->begining_of_the_line_ = true;
580  return *t;
581 }
582 
583 
584 /// @details Set OStringStream object to which all Tracers output
585 /// listed in the monitoring_channels_list should be copied. Note
586 /// this copies the output of channels even if they are invisible or
587 /// muted.
588 // void Tracer::set_ios_hook(otstreamOP tr, std::string const & monitoring_channels_list)
589 // {
590 // ios_hook_ = tr;
591 // monitoring_list_ = utility::split(monitoring_channels_list);
592 // ios_hook_raw_ = true;
593 // }
594 /// When raw==false same as above above but gives the option get only the
595 /// visible and unmuted tracers. It can be useful to get the raw
596 /// output for applications like the comparing tracers, where the
597 /// output should not change with command line parameters. It can be
598 /// useful to get the non-raw output in applications like using the
599 /// jd2 with MPI, where the output each job should match the output if
600 /// it was run on a single processor.
601 void Tracer::set_ios_hook(otstreamOP tr, std::string const & monitoring_channels_list, bool raw)
602 {
603  ios_hook() = tr;
604  monitoring_list_ = utility::split(monitoring_channels_list);
605  ios_hook_raw_() = raw;
606 }
607 
610  if ( instance_ == 0 ) {
611  instance_ = new TracerManager;
612  }
613  return instance_;
614 }
615 
616 std::vector< Tracer * > &
618  return all_tracers_;
619 }
620 
622 
623 void PyTracer::t_flush(std::string const &str)
624 {
625  buf_ += str;
626  output_callback(str);
627 }
628 
629 
630 } // 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:459
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:523
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:554
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
FileVectorOptionKey const s
Definition: SQLPDB.py:309
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:443
static bool initial_tracers_visibility_calculated_
Definition: Tracer.hh:363
std::vector< Tracer * > & all_tracers()
Definition: Tracer.cc:617
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:573
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:319
utility::vector1< std::string > string_split(std::string const &in, char splitchar)
Definition: string_util.cc:160
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:38
static bool & super_mute_()
global super mute flag that allow to mute all io no matter what.
Definition: Tracer.cc:114
StringVectorOptionKey const mute
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:609
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:219
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:361
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:601
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:623
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:470
Tracer & operator()(int priority)
Definition: Tracer.cc:339
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
FileVectorOptionKey const t
int mute_level_
channel muted priority level (above which level is channel muted), calculated using user suppied -lev...
Definition: Tracer.hh:333