SimpleLogger.cpp
Go to the documentation of this file.
1 #include "SimpleLogger.hpp"
2 
3 namespace iv
4 {
5 
7 {
8  // 0
9  { SimpleLogger::Flags::Disabled, "Disabled" },
10 
11  // 1
12  { SimpleLogger::Flags::Enabled, "Enabled" },
13  { SimpleLogger::Flags::Critical, "Critical" },
14  { SimpleLogger::Flags::SrcInfo, "SrcInfo" },
15  { SimpleLogger::Flags::InstanceDump, "InstanceDump" },
16 };
17 
19  DebugInstanceListener( inst, inst->getSystem< InstanceSystem >() ),
20  cm( inst, this, "SimpleLogger" ),
21  text_view( &this->cm, &iv::TextOutput ),
22  trace_change_counter( 0 )
23 {
24  // prefix used for trace info
25  this->text_view.prefix_push( " " );
26 }
27 
28 void SimpleLogger::Print( std::string name, LogId id, std::string entry )
29 {
30  // consider changing trace info
31  unsigned counter = LogTrace::GetChangeCounter();
32  if( this->trace_change_counter != counter )
33  {
34  this->trace_change_counter = counter;
35  this->text_view.prefix_pop();
36  LogTrace::PrintTrace( this->text_view.out() );
37  this->text_view.prefix_push( " " );
38  }
39 
40  //
41  for( int i = 0; i < 25 - (int)name.length(); i++ )
42  this->text_view.out() << " ";
43 
44  this->text_view.out() << name << " | " << StringIO_Write( id, &this->cm ) << ": ";
45  this->text_view.prefix_push( " | " );
46  this->text_view.out() << entry << std::endl;
47  this->text_view.prefix_pop();
48 }
49 
50 void SimpleLogger::ClientLog( ClientMarker const * marker, SrcInfo const & info, LogId id, std::string const & message )
51 {
52  Flags flags = this->ClientLogFlags( marker, id );
53 
54  if( int( flags ) & int( Flags::Enabled ) )
55  {
56  this->Print( marker->name_id(), id, message );
57  }
58 
59  if( int( flags ) & int( Flags::SrcInfo ) )
60  {
61  this->text_view.out() << " (emitted from " << info.file << ":" << info.line << ")" << std::endl;
62  }
63 
64  if( int( flags ) & int( Flags::InstanceDump ) )
65  {
66  TreeDebugView tree( &this->cm );
67  tree.Push( marker->instance()->instance_name().c_str() );
68  marker->instance()->debug_print_clients( &tree );
69  tree.Write( TreeDebugView::Style::BoldFramesWeakLinks, &this->text_view );
70  }
71 
72  if( int( flags ) & int( Flags::Critical ) )
73  {
74  // break / abort
75  #ifndef NDEBUG
76  raise( SIGABRT );
77  #endif
78  }
79 }
80 
81 bool SimpleLogger::ClientLogEnabled( ClientMarker const * marker, LogId id )
82 {
83  return int( this->ClientLogFlags( marker, id ) ) & int( Flags::Enabled );
84 }
85 
86 void SimpleLogger::SystemLog( System const * system, SrcInfo const & info, LogId id, std::string const & message )
87 {
88  Flags flags = this->SystemLogFlags( system, id );
89 
90  if( int( flags ) & int( Flags::Enabled ) )
91  {
92  this->Print( system->debug_name(), id, message );
93  }
94 
95  if( int( flags ) & int( Flags::SrcInfo ) )
96  {
97  this->text_view.out() << " (emitted from " << info.file << ":" << info.line << ")" << std::endl;
98  }
99 
100  if( int( flags ) & int( Flags::Critical ) )
101  {
102  // break / abort
103  #ifndef NDEBUG
104  raise( SIGABRT );
105  #endif
106  }
107 }
108 
109 bool SimpleLogger::SystemLogEnabled( System const * system, LogId id )
110 {
111  return int( this->SystemLogFlags( system, id ) ) & int( Flags::Enabled );
112 }
113 
114 }