Changeset 71:01bc36a9ed22 in rrlib_logging


Ignore:
Timestamp:
06.01.2012 11:38:28 (9 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Message:

Revised message printing. Includes some fixes in tStream::operator << overloads.

Files:
1 added
6 edited
5 moved

Legend:

Unmodified
Added
Removed
  • configuration/tConfiguration.cpp

    r69 r71  
    3939// Internal includes with "" 
    4040//---------------------------------------------------------------------- 
     41#include "rrlib/logging/configuration/tDomainRegistry.h" 
    4142 
    4243//---------------------------------------------------------------------- 
     
    6465//---------------------------------------------------------------------- 
    6566#ifdef _RRLIB_LOGGING_LESS_OUTPUT_ 
    66 const bool cDEFAULT_PRINT_TIME = false;                 //!< Default print time setting for reduced output mode 
    67 const bool cDEFAULT_PRINT_NAME = false;                 //!< Default print name setting for reduced output mode 
    68 const bool cDEFAULT_PRINT_LEVEL = false;                //!< Default print level setting for reduced output mode 
    69 const bool cDEFAULT_PRINT_LOCATION = false;             //!< Default print location setting for reduced output mode 
     67const bool cDEFAULT_PRINTS_TIME = false;                //!< Default prints time setting for reduced output mode 
     68const bool cDEFAULT_PRINTS_NAME = false;                //!< Default prints name setting for reduced output mode 
     69const bool cDEFAULT_PRINTS_LEVEL = false;               //!< Default prints level setting for reduced output mode 
     70const bool cDEFAULT_PRINTS_LOCATION = false;            //!< Default prints location setting for reduced output mode 
    7071const tLogLevel cDEFAULT_MAX_LOG_LEVEL = eLL_WARNING;   //!< Default max log level for reduced output mode 
    7172const int cDEFAULT_SINK_MASK = 1 << eLS_STDOUT;         //!< Default output stream mask 
    7273#else 
    73 const bool cDEFAULT_PRINT_TIME = false;               //!< Default print time setting for normal output mode 
    74 const bool cDEFAULT_PRINT_NAME = false;               //!< Default print name setting for normal output mode 
    75 const bool cDEFAULT_PRINT_LEVEL = false;              //!< Default print level setting for normal output mode 
    76 const bool cDEFAULT_PRINT_LOCATION = true;            //!< Default print location setting for normal output mode 
    77 const tLogLevel cDEFAULT_MAX_LOG_LEVEL = eLL_DEBUG;   //!< Default max log level for normal output mode 
    78 const int cDEFAULT_SINK_MASK = 1 << eLS_STDOUT;       //!< Default output stream mask 
     74const bool cDEFAULT_PRINTS_TIME = false;                //!< Default prints time setting for normal output mode 
     75const bool cDEFAULT_PRINTS_NAME = false;                //!< Default prints name setting for normal output mode 
     76const bool cDEFAULT_PRINTS_LEVEL = false;               //!< Default prints level setting for normal output mode 
     77const bool cDEFAULT_PRINTS_LOCATION = true;             //!< Default prints location setting for normal output mode 
     78const tLogLevel cDEFAULT_MAX_LOG_LEVEL = eLL_DEBUG;     //!< Default max log level for normal output mode 
     79const int cDEFAULT_SINK_MASK = 1 << eLS_STDOUT;         //!< Default output stream mask 
    7980#endif 
    8081 
     
    8889tConfiguration::tConfiguration(const tConfiguration *parent, const std::string &name) 
    8990    : parent(parent), 
    90     name(name)//, 
    91 //    print_time(cDEFAULT_PRINT_TIME), 
    92 //    print_name(cDEFAULT_PRINT_NAME), 
    93 //    print_level(cDEFAULT_PRINT_LEVEL), 
    94 //    print_location(cDEFAULT_PRINT_LOCATION), 
    95 //    max_message_level(cDEFAULT_MAX_LOG_LEVEL), 
     91    name(name), 
     92    prints_time(cDEFAULT_PRINTS_TIME), 
     93    prints_name(cDEFAULT_PRINTS_NAME), 
     94    prints_level(cDEFAULT_PRINTS_LEVEL), 
     95    prints_location(cDEFAULT_PRINTS_LOCATION), 
     96    max_message_level(cDEFAULT_MAX_LOG_LEVEL)//, 
    9697//    sink_mask(cDEFAULT_SINK_MASK) 
    97 {} 
    98  
    99 //tConfiguration::tConfiguration(const tConfiguration &other) 
    100 //    : print_time(other.print_time), 
    101 //    print_name(other.print_name), 
    102 //    print_level(other.print_level), 
    103 //    print_location(other.print_location), 
    104 //    max_message_level(other.max_message_level), 
    105 //    sink_mask(other.sink_mask) 
    106 //{} 
    107 // 
    108 ////---------------------------------------------------------------------- 
    109 //// tConfiguration operator = 
    110 ////---------------------------------------------------------------------- 
    111 //tConfiguration &tConfiguration::operator = (const tConfiguration other) 
    112 //{ 
    113 //  this->print_time = other.print_time; 
    114 //  this->print_name = other.print_name; 
    115 //  this->print_level = other.print_level; 
    116 //  this->print_location = other.print_location; 
    117 //  this->max_message_level = other.max_message_level; 
    118 //  this->sink_mask = other.sink_mask; 
    119 //  return *this; 
    120 //} 
     98{ 
     99  this->stream_buffer.AddStream(std::cout); 
     100} 
    121101 
    122102//---------------------------------------------------------------------- 
     
    136116const tConfiguration &tConfiguration::GetConfigurationByName(const char *domain_name) const 
    137117{ 
    138   assert(domain_name); 
    139  
    140   if (!*domain_name) 
     118  assert(domain_name && *domain_name); 
     119 
     120  const char *delimiter = std::strchr(domain_name, '.'); 
     121 
     122  if (!delimiter) 
     123  { 
     124    return this->LookupChild(domain_name, std::strlen(domain_name)); 
     125  } 
     126 
     127  return this->LookupChild(domain_name, delimiter - domain_name).GetConfigurationByName(delimiter + 1); 
     128} 
     129 
     130//---------------------------------------------------------------------- 
     131// tConfiguration GetConfigurationByFilename 
     132//---------------------------------------------------------------------- 
     133const tConfiguration &tConfiguration::GetConfigurationByFilename(const char *filename) const 
     134{ 
     135  assert(filename && *filename); 
     136 
     137  const char *delimiter = std::strchr(filename, '/'); 
     138 
     139  if (!delimiter) 
    141140  { 
    142141    return *this; 
    143142  } 
    144143 
    145   const char *p = std::strchr(domain_name, '.'); 
    146   if (p) 
    147   { 
    148     return this->LookupChild(domain_name, p - domain_name).GetConfigurationByName(p + 1); 
    149   } 
    150  
    151   return this->LookupChild(domain_name, std::strlen(domain_name)); 
    152 } 
    153  
    154 //---------------------------------------------------------------------- 
    155 // tConfiguration GetConfigurationByFilename 
    156 //---------------------------------------------------------------------- 
    157 const tConfiguration &tConfiguration::GetConfigurationByFilename(const char *filename) const 
    158 { 
    159   assert(filename); 
    160  
    161   // Return directly if filename does not contain any folders (leaf) 
    162   const char *p = std::strchr(filename, '/'); 
    163   if (!p) 
    164   { 
    165     return *this; 
    166   } 
    167  
    168   return this->LookupChild(filename, p - filename).GetConfigurationByFilename(p + 1); 
     144  return this->LookupChild(filename, delimiter - filename).GetConfigurationByFilename(delimiter + 1); 
    169145} 
    170146 
     
    200176  } 
    201177 
     178  // Add child if needed 
    202179  if (!configuration) 
    203180  { 
    204181    configuration = new tConfiguration(this, std::string(name, length)); 
     182    const tConfiguration *parent = configuration->parent; 
     183    size_t full_name_length = 0; 
     184    while (parent) 
     185    { 
     186      full_name_length += parent->Name().length() + 1; 
     187      parent = parent->parent; 
     188    } 
     189    tDomainRegistry::GetInstance().UpdateMaxDomainNameLength(full_name_length + configuration->Name().length()); 
    205190    this->children.insert(insertion_point, configuration); 
    206191  } 
  • configuration/tConfiguration.h

    r69 r71  
    7171//---------------------------------------------------------------------- 
    7272#include "rrlib/logging/log_levels.h" 
     73#include "rrlib/logging/messages/tStreamBuffer.h" 
    7374 
    7475//---------------------------------------------------------------------- 
     
    113114class tConfiguration 
    114115{ 
    115   friend class tLogDomainRegistryImplementation; 
     116  friend class tDomainRegistryImplementation; 
    116117 
    117118//---------------------------------------------------------------------- 
     
    155156  { 
    156157    return this->max_message_level; 
     158  } 
     159 
     160  inline tStreamBuffer &StreamBuffer() const 
     161  { 
     162    return this->stream_buffer; 
    157163  } 
    158164 
     
    175181//  int sink_mask; 
    176182 
     183  mutable tStreamBuffer stream_buffer; 
     184 
    177185  mutable std::list<tConfiguration *> children; 
    178186 
  • configuration/tDomainRegistry.cpp

    r69 r71  
    2020// 
    2121//---------------------------------------------------------------------- 
    22 /*!\file    tLogDomainRegistry.cpp 
     22/*!\file    tDomainRegistry.cpp 
    2323 * 
    2424 * \author  Tobias Foehst 
     
    2929//---------------------------------------------------------------------- 
    3030#define __rrlib__logging__include_guard__ 
    31 #include "rrlib/logging/configuration/tLogDomainRegistry.h" 
     31#include "rrlib/logging/configuration/tDomainRegistry.h" 
    3232 
    3333//---------------------------------------------------------------------- 
     
    8181 
    8282//---------------------------------------------------------------------- 
    83 // tLogDomainRegistryImplementation constructors 
    84 //---------------------------------------------------------------------- 
    85 tLogDomainRegistryImplementation::tLogDomainRegistryImplementation() 
    86     : global_configuration(new tConfiguration(0, "")) 
    87 //    : max_domain_name_length(0), 
    88 //    pad_prefix_columns(true), 
    89 //    pad_multi_line_messages(true) 
     83// tDomainRegistryImplementation constructors 
     84//---------------------------------------------------------------------- 
     85tDomainRegistryImplementation::tDomainRegistryImplementation() 
     86    : global_configuration(new tConfiguration(0, "")), 
     87    max_domain_name_length(0), 
     88    pad_prefix_columns(true), 
     89    pad_multi_line_messages(true) 
    9090{ 
    9191  // Create a string literal from the value of RRLIB_LOG_PATH and let p point to its beginning 
     
    124124//    std::cout << *it << " -> " << this->prefix_lengths[*it] << std::endl; 
    125125//  } 
    126  
    127  
    128 //  this->domain_configurations.push_back(tConfigurationSharedPointer(new tConfiguration("."))); 
    129 //  this->domains.push_back(std::shared_ptr<tLogDomain>(new tLogDomain(this->domain_configurations.back()))); 
    130 } 
    131  
    132 //---------------------------------------------------------------------- 
    133 // tLogDomainRegistryImplementation destructor 
    134 //---------------------------------------------------------------------- 
    135 tLogDomainRegistryImplementation::~tLogDomainRegistryImplementation() 
     126} 
     127 
     128//---------------------------------------------------------------------- 
     129// tDomainRegistryImplementation destructor 
     130//---------------------------------------------------------------------- 
     131tDomainRegistryImplementation::~tDomainRegistryImplementation() 
    136132{ 
    137133  delete this->global_configuration; 
     
    139135 
    140136//---------------------------------------------------------------------- 
    141 // tLogDomainRegistryImplementation GetConfigurationByFilename 
    142 //---------------------------------------------------------------------- 
    143 const tConfiguration &tLogDomainRegistryImplementation::GetConfigurationByFilename(const char *filename) const 
     137// tDomainRegistryImplementation GetConfigurationByFilename 
     138//---------------------------------------------------------------------- 
     139const tConfiguration &tDomainRegistryImplementation::GetConfigurationByFilename(const char *filename) const 
    144140{ 
    145141  bool found_prefix = false; 
     
    176172} 
    177173 
    178 ////---------------------------------------------------------------------- 
    179 //// tLogDomainRegistry GetSubDomain 
    180 ////---------------------------------------------------------------------- 
    181 //tLogDomainSharedPointer tLogDomainRegistry::GetSubDomain(const std::string &name, tLogDomainSharedPointer parent) 
    182 //{ 
    183 //  assert(name.length() > 0); 
    184 //  assert(parent != tLogDomainSharedPointer()); 
    185 //  const std::string full_qualified_domain_name(parent->GetName() + (parent->parent ? "." : "") + name); 
    186 //  size_t i = this->GetDomainIndexByName(full_qualified_domain_name); 
    187 //  if (i == this->domains.size()) 
    188 //  { 
    189 //    tConfigurationSharedPointer configuration(this->GetConfigurationByName(full_qualified_domain_name)); 
    190 //    this->domains.push_back(std::shared_ptr<tLogDomain>(new tLogDomain(configuration, *const_cast<tLogDomain *>(parent.get())))); 
    191 //    return this->domains.back(); 
    192 //  } 
    193 //  return this->domains[i]; 
    194 //} 
    195 // 
    196 ////---------------------------------------------------------------------- 
    197 //// tLogDomainRegistry SetDomainConfiguresSubTree 
    198 ////---------------------------------------------------------------------- 
    199 //void tLogDomainRegistry::SetDomainConfiguresSubTree(const std::string &name, bool value) 
    200 //{ 
    201 //  tConfigurationSharedPointer configuration(this->GetConfigurationByName(name)); 
    202 //  configuration->configure_sub_tree = value; 
    203 //  this->PropagateDomainConfigurationToChildren(name); 
    204 //} 
    205 // 
    206 ////---------------------------------------------------------------------- 
    207 //// tLogDomainRegistry SetDomainPrintsTime 
    208 ////---------------------------------------------------------------------- 
    209 //void tLogDomainRegistry::SetDomainPrintsTime(const std::string &name, bool value) 
    210 //{ 
    211 //  tConfigurationSharedPointer configuration(this->GetConfigurationByName(name)); 
    212 //  configuration->print_time = value; 
    213 //  this->PropagateDomainConfigurationToChildren(name); 
    214 //} 
    215 // 
    216 ////---------------------------------------------------------------------- 
    217 //// tLogDomainRegistry SetDomainPrintsName 
    218 ////---------------------------------------------------------------------- 
    219 //void tLogDomainRegistry::SetDomainPrintsName(const std::string &name, bool value) 
    220 //{ 
    221 //  tConfigurationSharedPointer configuration(this->GetConfigurationByName(name)); 
    222 //  configuration->print_name = value; 
    223 //  this->PropagateDomainConfigurationToChildren(name); 
    224 //} 
    225 // 
    226 ////---------------------------------------------------------------------- 
    227 //// tLogDomainRegistry SetDomainPrintsLevel 
    228 ////---------------------------------------------------------------------- 
    229 //void tLogDomainRegistry::SetDomainPrintsLevel(const std::string &name, bool value) 
    230 //{ 
    231 //  tConfigurationSharedPointer configuration(this->GetConfigurationByName(name)); 
    232 //  configuration->print_level = value; 
    233 //  this->PropagateDomainConfigurationToChildren(name); 
    234 //} 
    235 // 
    236 ////---------------------------------------------------------------------- 
    237 //// tLogDomainRegistry SetDomainPrintsLocation 
    238 ////---------------------------------------------------------------------- 
    239 //void tLogDomainRegistry::SetDomainPrintsLocation(const std::string &name, bool value) 
    240 //{ 
    241 //  tConfigurationSharedPointer configuration(this->GetConfigurationByName(name)); 
    242 //  configuration->print_location = value; 
    243 //  this->PropagateDomainConfigurationToChildren(name); 
    244 //} 
    245 // 
    246 ////---------------------------------------------------------------------- 
    247 //// tLogDomainRegistry SetDomainMaxMessageLevel 
    248 ////---------------------------------------------------------------------- 
    249 //void tLogDomainRegistry::SetDomainMaxMessageLevel(const std::string &name, tLogLevel value) 
    250 //{ 
    251 //  tLogLevel effective_value = std::max(value, eLL_ERROR); 
    252 // 
    253 //#ifdef _RRLIB_LOGGING_LESS_OUTPUT_ 
    254 //  effective_value = std::min(value, eLL_DEBUG); 
    255 //#endif 
    256 // 
    257 //  tConfigurationSharedPointer configuration(this->GetConfigurationByName(name)); 
    258 //  configuration->max_message_level = effective_value; 
    259 //  this->PropagateDomainConfigurationToChildren(name); 
    260 //} 
    261 // 
    262 ////---------------------------------------------------------------------- 
    263 //// tLogDomainRegistry SetDomainSink 
    264 ////---------------------------------------------------------------------- 
    265 //void tLogDomainRegistry::SetDomainSink(const std::string &name, tLogSink sink_1, tLogSink sink_2, tLogSink sink_3, tLogSink sink_4) 
    266 //{ 
    267 //  int mask = 0; 
    268 //  mask |= (sink_1 != eLS_DIMENSION) ? (1 << sink_1) : 0; 
    269 //  mask |= (sink_2 != eLS_DIMENSION) ? (1 << sink_2) : 0; 
    270 //  mask |= (sink_3 != eLS_DIMENSION) ? (1 << sink_3) : 0; 
    271 //  mask |= (sink_4 != eLS_DIMENSION) ? (1 << sink_4) : 0; 
    272 //  this->SetDomainSinkMask(name, mask); 
    273 //} 
    274 // 
    275 ////---------------------------------------------------------------------- 
    276 //// tLogDomainRegistry SetDomainSinkMask 
    277 ////---------------------------------------------------------------------- 
    278 //void tLogDomainRegistry::SetDomainSinkMask(const std::string &name, int mask) 
    279 //{ 
    280 //  tConfigurationSharedPointer configuration(this->GetConfigurationByName(name)); 
    281 //  configuration->sink_mask = mask; 
    282 //  this->PropagateDomainConfigurationToChildren(name); 
    283 //} 
    284 // 
    285 ////---------------------------------------------------------------------- 
    286 //// tLogDomainRegistry GetDomainIndexByName 
    287 ////---------------------------------------------------------------------- 
    288 //const size_t tLogDomainRegistry::GetDomainIndexByName(const std::string &name) const 
    289 //{ 
    290 //  for (size_t i = 0; i < this->domains.size(); ++i) 
    291 //  { 
    292 //    if (this->domains[i]->GetName() == name) 
    293 //    { 
    294 //      return i; 
    295 //    } 
    296 //  } 
    297 //  return this->domains.size(); 
    298 //} 
    299 // 
    300 ////---------------------------------------------------------------------- 
    301 //// tLogDomainRegistry GetConfigurationByName 
    302 ////---------------------------------------------------------------------- 
    303 //tConfigurationSharedPointer tLogDomainRegistry::GetConfigurationByName(const std::string &name) 
    304 //{ 
    305 //  for (std::vector<tConfigurationSharedPointer>::iterator it = this->domain_configurations.begin(); it != this->domain_configurations.end(); ++it) 
    306 //  { 
    307 //    if ((*it)->name == name) 
    308 //    { 
    309 //      return *it; 
    310 //    } 
    311 //  } 
    312 //  this->domain_configurations.push_back(tConfigurationSharedPointer(new tConfiguration(name))); 
    313 //  this->max_domain_name_length = std::max(this->max_domain_name_length, name.length()); 
    314 //  return this->domain_configurations.back(); 
    315 //} 
    316 // 
    317 ////---------------------------------------------------------------------- 
    318 //// tLogDomainRegistry PropagateDomainConfigurationToChildren 
    319 ////---------------------------------------------------------------------- 
    320 //void tLogDomainRegistry::PropagateDomainConfigurationToChildren(const std::string &name) 
    321 //{ 
    322 //  size_t i = this->GetDomainIndexByName(name); 
    323 //  if (i != this->domains.size()) 
    324 //  { 
    325 //    for (std::vector<tLogDomain *>::iterator it = this->domains[i]->children.begin(); it != this->domains[i]->children.end(); ++it) 
    326 //    { 
    327 //      (*it)->ConfigureSubTree(); 
    328 //    } 
    329 //  } 
    330 //} 
    331 // 
    332 ////---------------------------------------------------------------------- 
    333 //// tLogDomainRegistry ConfigureFromFile 
    334 ////---------------------------------------------------------------------- 
    335 //bool tLogDomainRegistry::ConfigureFromFile(const std::string &file_name) 
     174//---------------------------------------------------------------------- 
     175// tDomainRegistryImplementation UpdateMaxDomainNameLength 
     176//---------------------------------------------------------------------- 
     177void tDomainRegistryImplementation::UpdateMaxDomainNameLength(size_t added_domain_name_length) 
     178{ 
     179  this->max_domain_name_length = std::max(this->max_domain_name_length, added_domain_name_length); 
     180} 
     181 
     182////---------------------------------------------------------------------- 
     183//// tDomainRegistry ConfigureFromFile 
     184////---------------------------------------------------------------------- 
     185//bool tDomainRegistry::ConfigureFromFile(const std::string &file_name) 
    336186//{ 
    337187//#ifdef _LIB_RRLIB_XML2_WRAPPER_PRESENT_ 
     
    343193//  catch (const tXML2WrapperException &e) 
    344194//  { 
    345 //    std::cerr << "RRLib Logging: tLogDomainRegistry::ConfigureFromFile >> " << e.what() << std::endl; 
     195//    std::cerr << "RRLib Logging: tDomainRegistry::ConfigureFromFile >> " << e.what() << std::endl; 
    346196//    return false; 
    347197//  } 
    348198//#else 
    349 //  std::cerr << "RRLib Logging: tLogDomainRegistry::ConfigureFromFile >> XML support not available due to missing rrlib_mca2_wrapper." << std::endl; 
     199//  std::cerr << "RRLib Logging: tDomainRegistry::ConfigureFromFile >> XML support not available due to missing rrlib_mca2_wrapper." << std::endl; 
    350200//  return false; 
    351201//#endif 
     
    355205// 
    356206////---------------------------------------------------------------------- 
    357 //// tLogDomainRegistry ConfigureFromXMLNode 
    358 ////---------------------------------------------------------------------- 
    359 //bool tLogDomainRegistry::ConfigureFromXMLNode(const tXMLNode &node) 
     207//// tDomainRegistry ConfigureFromXMLNode 
     208////---------------------------------------------------------------------- 
     209//bool tDomainRegistry::ConfigureFromXMLNode(const tXMLNode &node) 
    360210//{ 
    361211//  if (node.GetName() != "rrlib_logging") 
    362212//  { 
    363 //    std::cerr << "RRLib Logging: tLogDomainRegistry::ConfigureFromXMLNode >> Unexpected content (Not an rrlib_logging tree)" << std::endl; 
     213//    std::cerr << "RRLib Logging: tDomainRegistry::ConfigureFromXMLNode >> Unexpected content (Not an rrlib_logging tree)" << std::endl; 
    364214//    return false; 
    365215//  } 
     
    389239//  catch (const tXML2WrapperException &e) 
    390240//  { 
    391 //    std::cerr << "RRLib Logging: tLogDomainRegistry::ConfigureFromXMLNode >> " << e.what() << std::endl; 
     241//    std::cerr << "RRLib Logging: tDomainRegistry::ConfigureFromXMLNode >> " << e.what() << std::endl; 
    392242//    return false; 
    393243//  } 
     
    397247// 
    398248////---------------------------------------------------------------------- 
    399 //// tLogDomainRegistry AddConfigurationFromXMLNode 
    400 ////---------------------------------------------------------------------- 
    401 //bool tLogDomainRegistry::AddConfigurationFromXMLNode(const tXMLNode &node, const std::string &parent_name) 
     249//// tDomainRegistry AddConfigurationFromXMLNode 
     250////---------------------------------------------------------------------- 
     251//bool tDomainRegistry::AddConfigurationFromXMLNode(const tXMLNode &node, const std::string &parent_name) 
    402252//{ 
    403253//  static const char *level_names_init[eLL_DIMENSION - eLL_ERROR] = { "error", "warning", "debug_warning", "debug", "debug_verbose_1", "debug_verbose_2", "debug_verbose_3" }; 
     
    459309//      if (sinks_configured) 
    460310//      { 
    461 //        std::cerr << "RRLib Logging: tLogDomainRegistry::AddConfigurationFromXMLNode >> Sink already configured in domain element!" << std::endl; 
     311//        std::cerr << "RRLib Logging: tDomainRegistry::AddConfigurationFromXMLNode >> Sink already configured in domain element!" << std::endl; 
    462312//        return false; 
    463313//      } 
  • configuration/tDomainRegistry.h

    r69 r71  
    2020// 
    2121//---------------------------------------------------------------------- 
    22 /*!\file    tLogDomainRegistry.h 
     22/*!\file    tDomainRegistry.h 
    2323 * 
    2424 * \author  Tobias Foehst 
     
    2626 * \date    2010-06-16 
    2727 * 
    28  * \brief Contains tLogDomainRegistry 
    29  * 
    30  * \b tLogDomainRegistry 
    31  * 
    32  * tLogDomainRegistry is a central management facility for logging 
    33  * domains and their configuration. 
     28 * \brief Contains tDomainRegistry 
     29 * 
     30 * \b tDomainRegistry 
     31 * 
     32 * tDomainRegistry is a central management facility for logging domains 
     33 * and their configuration. 
    3434 * In RRLib logging messages can be send via several logging domains. 
    3535 * These have to be created and maintained using a single instance of 
    36  * tLogDomainRegistry. Thus, this class implements the singleton 
    37  * pattern and contains a list of logging domains and configurations 
    38  * that either were created along with active domains or were configured 
    39  * by the user from a file or calling the appropriate methods. 
     36 * tDomainRegistry. Thus, this class implements the singleton pattern 
     37 * and contains a list of logging domains and configurations that 
     38 * either were created along with active domains or were configured by 
     39 * the user from a file or calling the appropriate methods. 
    4040 * 
    4141 */ 
     
    5050#endif 
    5151 
    52 #ifndef __rrlib__logging__configuration__tLogDomainRegistry_h__ 
    53 #define __rrlib__logging__configuration__tLogDomainRegistry_h__ 
     52#ifndef __rrlib__logging__configuration__tDomainRegistry_h__ 
     53#define __rrlib__logging__configuration__tDomainRegistry_h__ 
    5454 
    5555//---------------------------------------------------------------------- 
     
    8989// Class declaration 
    9090//---------------------------------------------------------------------- 
    91 //! The central management facility for logging domains and their configuration 
     91//! The central management facility for logging domains and theirconfiguration 
    9292/*! In RRLib logging messages can be send via several logging domains. 
    9393 *  These have to be created and maintained using a single instance of 
    94  *  this class. Thus, this class registers a list of active logging domains 
    95  *  and configurations that either were created along with active domains 
    96  *  or were configured by the user from a file or calling the appropriate 
    97  *  methods. 
     94 *  this class. Thus, this class registers a list of active logging domain 
     95 *  configurations that either were created by sending messages or were 
     96 *  configured by the user from a file or calling the appropriate methods. 
    9897 *  It must be used via the singleton holder typedef below. 
    9998 */ 
    100 class tLogDomainRegistryImplementation 
     99class tDomainRegistryImplementation 
    101100{ 
    102101 
     
    106105public: 
    107106 
    108   /*! Ctor of tLogDomainRegistryImplementation 
    109    * 
    110    */ 
    111   tLogDomainRegistryImplementation(); 
    112  
    113   /*! Dtor of tLogDomainRegistryImplementation 
    114    * 
    115    */ 
    116   ~tLogDomainRegistryImplementation(); 
     107  /*! Ctor of tDomainRegistryImplementation 
     108   * 
     109   */ 
     110  tDomainRegistryImplementation(); 
     111 
     112  /*! Dtor of tDomainRegistryImplementation 
     113   * 
     114   */ 
     115  ~tDomainRegistryImplementation(); 
    117116 
    118117  inline const tConfiguration &GetGlobalConfiguration() const 
     
    123122 
    124123  const tConfiguration &GetConfigurationByFilename(const char *filename) const; 
    125  
    126 //  /*! Get a subdomain with given name and parent. 
    127 //   * 
    128 //   * This method can be used to access a subdomain of the given parent 
    129 //   * with given name. It then implements the lookup and if the domain 
    130 //   * was not found creates a new one and applies an eventually existing 
    131 //   * configuration. 
    132 //   * 
    133 //   * \param name     The name of the subdomain (local part) 
    134 //   * \param parent   The parent of the subdomain 
    135 //   * 
    136 //   * \returns The found or newly created domain object as a shared pointer 
    137 //   */ 
    138 //  tLogDomainSharedPointer GetSubDomain(const std::string &name, tLogDomainSharedPointer parent); 
    139124 
    140125//  /*! Set a prefix for filenames that are created as log 
     
    164149//    return this->file_name_prefix; 
    165150//  } 
    166 // 
    167 //  /*! Set if columns in prefix output should be padded or not 
    168 //   * 
    169 //   * If the prefix output columns should be aligned, the fields for the 
    170 //   * domain name and message level are padded with spaces to the right. 
    171 //   * 
    172 //   * \param value   The new value of this flag 
    173 //   */ 
    174 //  inline void SetPadPrefixColumns(bool value) 
    175 //  { 
    176 //    this->pad_prefix_columns = value; 
    177 //  } 
    178 // 
    179 //  /*! Get if columns in prefix output should be padded or not 
    180 //   * 
    181 //   * If the prefix output columns should be aligned, the fields for the 
    182 //   * domain name and message level are padded with spaces to the right. 
    183 //   * 
    184 //   * \returns Whether the columns in prefix output should be padded or not 
    185 //   */ 
    186 //  inline const bool GetPadPrefixColumns() const 
    187 //  { 
    188 //    return this->pad_prefix_columns; 
    189 //  } 
    190 // 
    191 //  /*! Set if rows in output should be padded to start after the prefix or not 
    192 //   * 
    193 //   * For multiline output following line do not have a prefix. Thus, they start 
    194 //   * in the first column whearas the first row started right after the prefix. 
    195 //   * This flag allows to choose if subsequent lines should be padded to match the 
    196 //   * first row or not. 
    197 //   * 
    198 //   * \param value   The new value of this flag 
    199 //   */ 
    200 //  inline void SetPadMultiLineMessages(bool value) 
    201 //  { 
    202 //    this->pad_multi_line_messages = value; 
    203 //  } 
    204 // 
    205 //  /*! Get if rows in output should be padded to start after the prefix or not 
    206 //   * 
    207 //   * For multiline output following line do not have a prefix. Thus, they start 
    208 //   * in the first column whearas the first row started right after the prefix. 
    209 //   * This flag allows to choose if subsequent lines should be padded to match the 
    210 //   * first row or not. 
    211 //   * 
    212 //   * \returns Whether the rows should be padded or not 
    213 //   */ 
    214 //  inline const bool GetPadMultiLineMessages() const 
    215 //  { 
    216 //    return this->pad_multi_line_messages; 
    217 //  } 
    218 // 
    219 //  /*! Get the length of the longest full qualified domain name 
    220 //   * 
    221 //   * This method can be used for formatting user dialogs 
    222 //   * 
    223 //   * \returns The length of the longest domain name 
    224 //   */ 
    225 //  std::string::size_type GetMaxDomainNameLength() const 
    226 //  { 
    227 //    return this->max_domain_name_length; 
    228 //  } 
    229 // 
    230 //  /*! Set if the domain configures its subtree or not 
    231 //   * 
    232 //   * If set to true every configuration update to the given domain 
    233 //   * will be propagated to its subtree. 
    234 //   * 
    235 //   * \param name    The full qualified name of the domain 
    236 //   * \param value   The new value of the setting 
    237 //   */ 
    238 //  void SetDomainConfiguresSubTree(const std::string &name, bool value); 
    239 // 
    240 //  /*! Set if the domain should prepend the current time to each message 
    241 //   * 
    242 //   * If set to true every message will start with the current time 
    243 //   * 
    244 //   * \param name    The full qualified name of the domain 
    245 //   * \param value   The new value of the setting 
    246 //   */ 
    247 //  void SetDomainPrintsTime(const std::string &name, bool value); 
    248 // 
    249 //  /*! Set if the domain should prepend messages with its name 
    250 //   * 
    251 //   * If set to true every message will include the full qualified domain 
    252 //   * name 
    253 //   * 
    254 //   * \param name    The full qualified name of the domain 
    255 //   * \param value   The new value of the setting 
    256 //   */ 
    257 //  void SetDomainPrintsName(const std::string &name, bool value); 
    258 // 
    259 //  /*! Set if the domain should prepend messages with their level 
    260 //   * 
    261 //   * If set to true every message will include its level 
    262 //   * 
    263 //   * \param name    The full qualified name of the domain 
    264 //   * \param value   The new value of the setting 
    265 //   */ 
    266 //  void SetDomainPrintsLevel(const std::string &name, bool value); 
    267 // 
    268 //  /*! Set if the domain should prepend the message with its location 
    269 //   * 
    270 //   * If set to true every message will include its location in code. 
    271 //   * This is extremely helpful during debugging phases. 
    272 //   * 
    273 //   * \param name    The full qualified name of the domain 
    274 //   * \param value   The new value of the setting 
    275 //   */ 
    276 //  void SetDomainPrintsLocation(const std::string &name, bool value); 
    277 // 
    278 //  /*! Set the maximal message level of the given domain 
    279 //   * 
    280 //   * The output of each message that has a level above the given value 
    281 //   * will be suppressed. Default is eML_DEBUG or eML_WARNING depending on 
    282 //   * compile flags. 
    283 //   * 
    284 //   * \param name    The full qualified name of the domain 
    285 //   * \param value   The new value of the setting 
    286 //   */ 
    287 //  void SetDomainMaxMessageLevel(const std::string &name, tLogLevel value); 
    288 // 
    289 //  /*! Set the output streams that should be used as sink by the given domain 
    290 //   * 
    291 //   * \param name     The full qualified name of the domain 
    292 //   * \param sink_1   The first sink to be used by the given domain 
    293 //   * \param sink_2   The second sink to be used by the given domain 
    294 //   * \param sink_3   The third sink to be used by the given domain 
    295 //   * \param sink_4   The fourth sink to be used by the given domain 
    296 //   */ 
    297 //  void SetDomainSink(const std::string &name, tLogSink sink_1, tLogSink sink_2 = eLS_DIMENSION, tLogSink sink_3 = eLS_DIMENSION, tLogSink sink_4 = eLS_DIMENSION); 
    298 // 
    299 //  /*! Read domain configuration from a given XML file 
    300 //   * 
    301 //   * The overall configuration of the logging domains tends to be 
    302 //   * too complicated for a classical command line option interface. 
    303 //   * Therefore, it is possible to specify the configuration in form 
    304 //   * of an XML file following the DTD -//RRLIB//logging 
    305 //   * 
    306 //   * \param file_name   The XML file to be read 
    307 //   * 
    308 //   * \returns Whether the configuration could be read and applied or not 
    309 //   */ 
    310 //  bool ConfigureFromFile(const std::string &file_name); 
    311 // 
     151 
     152  /*! Set if columns in prefix output should be padded or not 
     153   * 
     154   * If the prefix output columns should be aligned, the fields for the 
     155   * domain name and message level are padded with spaces to the right. 
     156   * 
     157   * \param value   The new value of this flag 
     158   */ 
     159  inline void SetPadPrefixColumns(bool value) 
     160  { 
     161    this->pad_prefix_columns = value; 
     162  } 
     163 
     164  /*! Get if columns in prefix output should be padded or not 
     165   * 
     166   * If the prefix output columns should be aligned, the fields for the 
     167   * domain name and message level are padded with spaces to the right. 
     168   * 
     169   * \returns Whether the columns in prefix output should be padded or not 
     170   */ 
     171  inline const bool GetPadPrefixColumns() const 
     172  { 
     173    return this->pad_prefix_columns; 
     174  } 
     175 
     176  /*! Set if rows in output should be padded to start after the prefix or not 
     177   * 
     178   * For multiline output following line do not have a prefix. Thus, they start 
     179   * in the first column whearas the first row started right after the prefix. 
     180   * This flag allows to choose if subsequent lines should be padded to match the 
     181   * first row or not. 
     182   * 
     183   * \param value   The new value of this flag 
     184   */ 
     185  inline void SetPadMultiLineMessages(bool value) 
     186  { 
     187    this->pad_multi_line_messages = value; 
     188  } 
     189 
     190  /*! Get if rows in output should be padded to start after the prefix or not 
     191   * 
     192   * For multiline output following line do not have a prefix. Thus, they start 
     193   * in the first column whearas the first row started right after the prefix. 
     194   * This flag allows to choose if subsequent lines should be padded to match the 
     195   * first row or not. 
     196   * 
     197   * \returns Whether the rows should be padded or not 
     198   */ 
     199  inline const bool GetPadMultiLineMessages() const 
     200  { 
     201    return this->pad_multi_line_messages; 
     202  } 
     203 
     204  void UpdateMaxDomainNameLength(size_t added_domain_name_length); 
     205 
     206  /*! Get the length of the longest full qualified domain name 
     207   * 
     208   * This method can be used for formatting user dialogs 
     209   * 
     210   * \returns The length of the longest domain name 
     211   */ 
     212  inline size_t MaxDomainNameLength() const 
     213  { 
     214    return this->max_domain_name_length; 
     215  } 
     216 
    312217//#ifdef _LIB_RRLIB_XML2_WRAPPER_PRESENT_ 
    313218//  /*! Read domain configuration from a given XML node 
     
    337242 
    338243//  std::string file_name_prefix; 
    339 //  std::vector<std::shared_ptr<tLogDomain> > domains; 
    340 //  std::vector<tConfigurationSharedPointer> domain_configurations; 
    341 //  std::string::size_type max_domain_name_length; 
    342 //  bool pad_prefix_columns; 
    343 //  bool pad_multi_line_messages; 
    344 // 
    345 //  /*! Get the index of the domain with the given name 
    346 //   * 
    347 //   * Helper method that implements the lookup for existing domains 
    348 //   * 
    349 //   * \param name   The name of the wanted domain 
    350 //   * 
    351 //   * \returns The index of the domain if found. If not, the methods returns the size of the domain vector. 
    352 //   */ 
    353 //  const size_t GetDomainIndexByName(const std::string &name) const; 
    354 // 
    355 //  /*! Get a configuration object for a domain with the given name 
    356 //   * 
    357 //   * This methods implements the lookup for existing domain names and 
    358 //   * creates a new configuration object for new names. 
    359 //   * 
    360 //   * \param name   The name of the domain to be configured 
    361 //   * 
    362 //   * \returns The wanted domain configuration as a shared pointer 
    363 //   */ 
    364 //  tConfigurationSharedPointer GetConfigurationByName(const std::string &name); 
    365 // 
    366 //  /*! Update configuration the subtree of a domain for recursion 
    367 //   * 
    368 //   * If the configuration of one domain is changed start update of its 
    369 //   * subtree. This method should always be called because the decision 
    370 //   * about recursive configuration is done within its call. 
    371 //   * That keeps update methods simpler. 
    372 //   * 
    373 //   * \param name   The name of the updated domain 
    374 //   */ 
    375 //  void PropagateDomainConfigurationToChildren(const std::string &name); 
    376 // 
    377 //  /*! Set the output streams that should be used by the given domain 
    378 //   * 
    379 //   * \param name   The full qualified name of the domain 
    380 //   * \param mask   The mask that represents the streams to be used as sink 
    381 //   */ 
    382 //  void SetDomainSinkMask(const std::string &name, int mask); 
    383 // 
     244  size_t max_domain_name_length; 
     245  bool pad_prefix_columns; 
     246  bool pad_multi_line_messages; 
     247 
    384248//#ifdef _LIB_RRLIB_XML2_WRAPPER_PRESENT_ 
    385249//  /*! Add a domain configuration from a given XML node 
     
    399263}; 
    400264 
    401 typedef util::tSingletonHolder<tLogDomainRegistryImplementation, util::singleton::CreateUsingNew, util::singleton::NoDestruction> tLogDomainRegistry; 
     265typedef util::tSingletonHolder<tDomainRegistryImplementation, util::singleton::NoDestruction> tDomainRegistry; 
    402266 
    403267//---------------------------------------------------------------------- 
  • default_log_description.cpp

    r69 r71  
    4646 
    4747//---------------------------------------------------------------------- 
     48// Namespace declaration 
     49//---------------------------------------------------------------------- 
     50namespace rrlib 
     51{ 
     52namespace logging 
     53{ 
     54 
     55//---------------------------------------------------------------------- 
    4856// Forward declarations / typedefs / enums 
    4957//---------------------------------------------------------------------- 
     
    5765//---------------------------------------------------------------------- 
    5866 
    59 namespace rrlib 
    60 { 
    61 namespace logging 
    62 { 
    6367char *default_log_description = const_cast<char *>("<Log description not defined>"); 
     68 
     69//---------------------------------------------------------------------- 
     70// End of namespace declaration 
     71//---------------------------------------------------------------------- 
    6472} 
    6573} 
  • messages/implementation.cpp

    r69 r71  
    3434// External includes (system with <>, local with "") 
    3535//---------------------------------------------------------------------- 
    36 #include <iostream> 
     36#include <cstdio> 
     37#include <ctime> 
    3738 
    3839//---------------------------------------------------------------------- 
    3940// Internal includes with "" 
    4041//---------------------------------------------------------------------- 
    41 #include "rrlib/logging/configuration/tLogDomainRegistry.h" 
     42#include "rrlib/logging/configuration/tDomainRegistry.h" 
    4243 
    4344//---------------------------------------------------------------------- 
     
    6970//---------------------------------------------------------------------- 
    7071 
     72//---------------------------------------------------------------------- 
     73// GetConfiguration 
     74//---------------------------------------------------------------------- 
    7175const tConfiguration &GetConfiguration(const char *filename, const char *domain_name) 
    7276{ 
     
    7579    if (domain_name[0] == '.') 
    7680    { 
    77       return tLogDomainRegistry::GetInstance().GetGlobalConfiguration().GetConfigurationByName(domain_name + 1); 
     81      return tDomainRegistry::GetInstance().GetGlobalConfiguration().GetConfigurationByName(domain_name + 1); 
    7882    } 
    79     return tLogDomainRegistry::GetInstance().GetConfigurationByFilename(filename).GetConfigurationByName(domain_name); 
     83    return tDomainRegistry::GetInstance().GetConfigurationByFilename(filename).GetConfigurationByName(domain_name); 
    8084  } 
    81   return tLogDomainRegistry::GetInstance().GetConfigurationByFilename(filename); 
     85  return tDomainRegistry::GetInstance().GetConfigurationByFilename(filename); 
     86} 
     87 
     88//---------------------------------------------------------------------- 
     89// SendFormattedTimeToStream 
     90//---------------------------------------------------------------------- 
     91void SendFormattedTimeToStream(tStream &stream) 
     92{ 
     93  char time_string_buffer[9]; 
     94  timespec time; 
     95  clock_gettime(CLOCK_REALTIME, &time); 
     96  strftime(time_string_buffer, sizeof(time_string_buffer), "%T", localtime(&time.tv_sec)); 
     97  char nsec_string_buffer[11]; 
     98  snprintf(nsec_string_buffer, sizeof(nsec_string_buffer), ".%09ld", time.tv_nsec); 
     99  stream << "[ " << time_string_buffer << nsec_string_buffer << " ] "; 
     100} 
     101 
     102//---------------------------------------------------------------------- 
     103// SetColor 
     104//---------------------------------------------------------------------- 
     105void SetColor(tStreamBuffer &stream_buffer, tLogLevel level) 
     106{ 
     107  switch (level) 
     108  { 
     109  case eLL_ERROR: 
     110    stream_buffer.SetColor(eLSBE_BOLD, eLSBC_RED); 
     111    break; 
     112  case eLL_WARNING: 
     113    stream_buffer.SetColor(eLSBE_BOLD, eLSBC_BLUE); 
     114    break; 
     115  case eLL_DEBUG_WARNING: 
     116    stream_buffer.SetColor(eLSBE_DARK, eLSBC_YELLOW); 
     117    break; 
     118  case eLL_DEBUG: 
     119    stream_buffer.SetColor(eLSBE_DARK, eLSBC_GREEN); 
     120    break; 
     121  case eLL_DEBUG_VERBOSE_1: 
     122    stream_buffer.SetColor(eLSBE_REGULAR, eLSBC_CYAN); 
     123    break; 
     124  case eLL_DEBUG_VERBOSE_2: 
     125    stream_buffer.SetColor(eLSBE_REGULAR, eLSBC_CYAN); 
     126    break; 
     127  case eLL_DEBUG_VERBOSE_3: 
     128    stream_buffer.SetColor(eLSBE_REGULAR, eLSBC_CYAN); 
     129    break; 
     130  default: 
     131    ; 
     132  } 
     133} 
     134 
     135//---------------------------------------------------------------------- 
     136// SendFormattedDomainNameToStream 
     137//---------------------------------------------------------------------- 
     138void SendFormattedDomainNameToStream(tStream &stream, const std::string &domain_name) 
     139{ 
     140  char name_string_buffer[128]; 
     141  snprintf(name_string_buffer, sizeof(name_string_buffer), "%-*s ", static_cast<int>((tDomainRegistry::GetInstance().GetPadPrefixColumns() ? tDomainRegistry::GetInstance().MaxDomainNameLength() : 0)), domain_name.c_str()); 
     142  stream << name_string_buffer; 
     143} 
     144 
     145//---------------------------------------------------------------------- 
     146// SendFormattedLevelToStream 
     147//---------------------------------------------------------------------- 
     148void SendFormattedLevelToStream(tStream &stream, tLogLevel level) 
     149{ 
     150  const char *level_name = 0; 
     151  switch (level) 
     152  { 
     153  case eLL_ERROR: 
     154    level_name = "[error]"; 
     155    break; 
     156  case eLL_WARNING: 
     157    level_name = "[warning]"; 
     158    break; 
     159  case eLL_DEBUG_WARNING: 
     160    level_name = "[debug]"; 
     161    break; 
     162  case eLL_DEBUG: 
     163    level_name = "[debug]"; 
     164    break; 
     165  case eLL_DEBUG_VERBOSE_1: 
     166    level_name = "[verbose]"; 
     167    break; 
     168  case eLL_DEBUG_VERBOSE_2: 
     169    level_name = "[verbose]"; 
     170    break; 
     171  case eLL_DEBUG_VERBOSE_3: 
     172    level_name = "[verbose]"; 
     173    break; 
     174  default: 
     175    level_name = ""; 
     176    break; 
     177  } 
     178  char name_string_buffer[128]; 
     179  snprintf(name_string_buffer, sizeof(name_string_buffer), "%-*s ", (tDomainRegistry::GetInstance().GetPadPrefixColumns() ? 9 : 0), level_name); 
     180  stream << name_string_buffer; 
     181} 
     182 
     183//---------------------------------------------------------------------- 
     184// SendFormattedLocationToStream 
     185//---------------------------------------------------------------------- 
     186void SendFormattedLocationToStream(tStream &stream, const char *filename, unsigned int line) 
     187{ 
     188  char location_string_buffer[128]; 
     189  snprintf(location_string_buffer, sizeof(location_string_buffer), "[%s:%u] ", filename, line); 
     190  stream << location_string_buffer; 
    82191} 
    83192 
  • messages/implementation.h

    r69 r71  
    4242// External includes (system with <>, local with "") 
    4343//---------------------------------------------------------------------- 
    44 #include <iostream> 
    4544#include <cstdarg> 
    4645 
     
    4948//---------------------------------------------------------------------- 
    5049#include "rrlib/logging/log_levels.h" 
    51 #include "rrlib/logging/configuration/tLogDomainRegistry.h" 
    5250#include "rrlib/logging/configuration/tConfiguration.h" 
     51#include "rrlib/logging/messages/tStream.h" 
    5352 
    5453//---------------------------------------------------------------------- 
     
    6867const tConfiguration &GetConfiguration(const char *filename, const char *domain_name = 0); 
    6968 
     69 
     70 
     71void SendFormattedTimeToStream(tStream &stream); 
     72void SendFormattedDomainNameToStream(tStream &stream, const std::string &domain_name); 
     73void SetColor(tStreamBuffer &stream_buffer, tLogLevel level); 
     74void SendFormattedLevelToStream(tStream &stream, tLogLevel level); 
     75void SendFormattedLocationToStream(tStream &stream, const char *filename, unsigned int line); 
     76 
     77 
     78 
     79namespace 
     80{ 
     81template <typename THead> 
     82void SendDataToStream(tStream &stream, THead head) 
     83{ 
     84  stream << head; 
     85} 
     86 
     87template <typename THead, typename ... TTail> 
     88void SendDataToStream(tStream &stream, THead head, TTail ... tail) 
     89{ 
     90  stream << head; 
     91  SendDataToStream(stream, tail...); 
     92} 
     93} 
     94 
     95 
     96 
    7097template <typename TLogDescription, typename ... TArgs> 
    71 void Print(const tConfiguration &domain_configuration, const TLogDescription &log_description, const char *function, const char *filename, unsigned int line, tLogLevel level, const TArgs &... args) 
     98void Print(const tConfiguration &domain_configuration, const TLogDescription &log_description, const char *function, const char *filename, unsigned int line, tLogLevel level, TArgs ... args) 
    7299{ 
    73100  if (level > domain_configuration.MaxMessageLevel()) 
     
    76103  } 
    77104 
    78   std::cout << domain_configuration.GetFullQualifiedName() << " " << log_description << std::endl; 
     105  tStream stream(domain_configuration.StreamBuffer()); 
     106  domain_configuration.StreamBuffer().InitializeMultiLinePadding(); 
    79107 
     108  if (level != eLL_USER) 
     109  { 
     110 
     111    if (domain_configuration.PrintsTime()) 
     112    { 
     113      SendFormattedTimeToStream(stream); 
     114    } 
     115 
     116    SetColor(domain_configuration.StreamBuffer(), level); 
     117 
     118#ifndef _RRLIB_LOGGING_LESS_OUTPUT_ 
     119    if (domain_configuration.PrintsName()) 
     120    { 
     121      SendFormattedDomainNameToStream(stream, domain_configuration.GetFullQualifiedName()); 
     122    } 
     123    if (domain_configuration.PrintsLevel()) 
     124    { 
     125      SendFormattedLevelToStream(stream, level); 
     126    } 
     127#endif 
     128 
     129    stream << log_description << "::" << function << " "; 
     130 
     131#ifndef _RRLIB_LOGGING_LESS_OUTPUT_ 
     132    if (domain_configuration.PrintsLocation()) 
     133    { 
     134      SendFormattedLocationToStream(stream, filename, line); 
     135    } 
     136#endif 
     137 
     138    stream << ">> "; 
     139 
     140    domain_configuration.StreamBuffer().ResetColor(); 
     141 
     142    switch (level) 
     143    { 
     144    case eLL_ERROR: 
     145      stream << "ERROR: "; 
     146      break; 
     147    case eLL_WARNING: 
     148    case eLL_DEBUG_WARNING: 
     149      stream << "WARNING: "; 
     150      break; 
     151    default: 
     152      ; 
     153    } 
     154 
     155  } 
     156 
     157  domain_configuration.StreamBuffer().MarkEndOfPrefixForMultiLinePadding(); 
     158 
     159  SendDataToStream(stream, args...); 
    80160} 
    81161 
  • messages/tStream.h

    r65 r71  
    2020// 
    2121//---------------------------------------------------------------------- 
    22 /*!\file    tLogStream.h 
     22/*!\file    tStream.h 
    2323 * 
    2424 * \author  Tobias Foehst 
    25  * \author  Max Reichardt 
    2625 * 
    2726 * \date    2010-07-06 
    2827 * 
    29  * \brief Contains tLogStream 
    30  * 
    31  * \b tLogStream 
     28 * \brief Contains tStream 
     29 * 
     30 * \b tStream 
    3231 * 
    3332 * This proxy class for std::ostream allows synchronized streaming. 
     
    3736 * 
    3837 * By returning a proxy for each output stream the logging domain creates 
    39  * creates a temporary object that lives as long as consecutive streaming 
    40  * operations are performed. Afterwards, the proxy will be desctructed 
     38 * a temporary object that lives as long as consecutive streaming 
     39 * operations are performed. Afterwards, the proxy will be destroyed 
    4140 * immediately. Hence, the correct times for acquiring and releasing the 
    4241 * lock are defined. 
     
    4948//---------------------------------------------------------------------- 
    5049#ifndef __rrlib__logging__include_guard__ 
    51 #error Invalid include directive. Try #include "rrlib/logging/definitions.h" instead. 
     50#error Invalid include directive. Try #include "rrlib/logging/messages.h" instead. 
    5251#endif 
    5352 
    54 #ifndef __rrlib__logging__tLogStream_h__ 
    55 #define __rrlib__logging__tLogStream_h__ 
     53#ifndef __rrlib__logging__tStream_h__ 
     54#define __rrlib__logging__tStream_h__ 
    5655 
    5756//---------------------------------------------------------------------- 
    5857// External includes (system with <>, local with "") 
    5958//---------------------------------------------------------------------- 
     59#include <iostream> 
     60#include <mutex> 
     61 
    6062#include <exception> 
    6163#include <boost/type_traits/is_base_of.hpp> 
    6264#include <boost/utility/enable_if.hpp> 
    63 #include <memory> 
    6465 
    6566//---------------------------------------------------------------------- 
    6667// Internal includes with "" 
    6768//---------------------------------------------------------------------- 
    68 #include "rrlib/logging/tLogStreamContext.h" 
     69#include "rrlib/logging/messages/tStreamBuffer.h" 
    6970 
    7071//---------------------------------------------------------------------- 
     
    8384// Forward declarations / typedefs / enums 
    8485//---------------------------------------------------------------------- 
    85 //! Shared pointer to instances of tLogDomain for user space 
    86 class tLogDomain; 
    87 typedef std::shared_ptr<const tLogDomain> tLogDomainSharedPointer; 
    8886 
    8987//---------------------------------------------------------------------- 
     
    9694 * 
    9795 *  By returning a proxy for each output stream the logging domain creates 
    98  *  creates a temporary object that lives as long as consecutive streaming 
    99  *  operations are performed. Afterwards, the proxy will be desctructed 
     96 *  a temporary object that lives as long as consecutive streaming 
     97 *  operations are performed. Afterwards, the proxy will be destroyed 
    10098 *  immediately. Hence, the correct times for acquiring and releasing the 
    10199 *  lock are defined. 
     
    106104 * 
    107105 */ 
    108 class tLogStream 
     106class tStream 
    109107{ 
    110108 
     
    114112public: 
    115113 
    116   /*! The ctor of tLogStream 
     114  /*! The ctor of tStream 
    117115   * 
    118116   * Acquires a lock for the output. 
     
    120118   * 
    121119   * \param stream   The std::ostream that is used via this proxy 
    122    * \param mutex    Mutex to acquire while this proxy is used 
    123    */ 
    124   explicit tLogStream(std::shared_ptr<tLogStreamContext> stream_context) 
    125       : stream_context(stream_context) 
    126   {} 
    127  
    128   /*! The copy ctor of tLogStream 
    129    * 
    130    * Copies a tLogStream object and its lock. 
    131    * This methods blocks until the lock can be re-acquired. 
    132    * 
    133    * \param other   The other tLogStream object 
    134    */ 
    135   tLogStream(const tLogStream &other) 
    136       : stream_context(other.stream_context) 
    137   {} 
     120   */ 
     121  explicit tStream(tStreamBuffer &stream_buffer); 
     122 
     123  /*! The ctor of tStream 
     124   * 
     125   * Releases the lock for the output and takes care of flushing and trailing newlines. 
     126   */ 
     127  ~tStream(); 
    138128 
    139129  /*! Implicit conversion to std::ostream for e.g. std::ostream_iterator 
     
    144134   * \returns A reference to the underlying std::ostream 
    145135   */ 
    146   operator std::ostream &() 
    147   { 
    148     return this->stream_context->GetStream(); 
     136  inline operator std::ostream &() 
     137  { 
     138    return this->stream; 
    149139  } 
    150140 
     
    159149   */ 
    160150  template <typename T> 
    161   inline typename boost::disable_if<boost::is_base_of<std::exception, T>, tLogStream &>::type operator << (const T &value) 
    162   { 
    163     this->stream_context->GetStream() << value; 
     151  inline typename boost::disable_if<boost::is_base_of<std::exception, T>, tStream>::type &operator << (const T &value) 
     152  { 
     153    this->stream << value; 
    164154    return *this; 
    165155  } 
     
    173163   * \returns A reference to the altered stream (in this case the proxy) 
    174164   */ 
    175   inline tLogStream &operator << (const std::exception &exception) 
    176   { 
    177     this->stream_context->GetStream() << "Exception (" << typeid(exception).name() << "): " << exception.what(); 
     165  inline tStream &operator << (std::exception &exception) 
     166  { 
     167    this->stream << "Exception (" << typeid(exception).name() << "): " << exception.what(); 
    178168    return *this; 
    179169  } 
     
    188178   * \returns A reference to the altered stream (in this case the proxy) 
    189179   */ 
    190   inline tLogStream &operator << (bool value) 
    191   { 
    192     this->stream_context->GetStream() << (value ? "<true>" : "<false>"); 
     180  inline tStream &operator << (bool value) 
     181  { 
     182    this->stream << (value ? "<true>" : "<false>"); 
    193183    return *this; 
    194184  } 
     
    206196   */ 
    207197  template <typename T> 
    208   inline tLogStream &operator << (const T *pointer) 
     198  inline tStream &operator << (const T *pointer) 
    209199  { 
    210200    if (pointer == 0) 
    211201    { 
    212       this->stream_context->GetStream() << "<nullptr>"; 
     202      this->stream << "<nullptr>"; 
    213203      return *this; 
    214204    } 
    215     this->stream_context->GetStream() << pointer; 
    216     return *this; 
    217   } 
    218  
     205    this->stream << pointer; 
     206    return *this; 
     207  } 
     208 
     209  template <typename T> 
     210  inline tStream &operator << (T *pointer) 
     211  { 
     212    *this << const_cast<const T *>(pointer); 
     213    return *this; 
     214  } 
     215 
     216  template <typename T, typename ... Args> 
     217  inline tStream &operator << (T(*function)(Args...)) 
     218  { 
     219    *this << reinterpret_cast<void *>(function); 
     220    return *this; 
     221  } 
    219222 
    220223  /*! Streaming operator for functions (forwarder) 
     
    228231   * \returns A reference to the altered stream (in this case the proxy) 
    229232   */ 
    230   inline tLogStream &operator << (std::ostream &(&manipulator)(std::ostream &)) 
    231   { 
    232     manipulator(this->stream_context->GetStream()); 
    233     return *this; 
    234   } 
    235  
    236   inline tLogStream &Evaluate() 
    237   { 
    238     return *this; 
    239   } 
    240  
    241   inline tLogStream &Evaluate(tLogDomainSharedPointer(&)()) 
    242   { 
    243     return *this; 
    244   } 
    245  
    246   template <typename T1, typename ... TRest> 
    247   inline tLogStream &Evaluate(const T1 &arg1, const TRest &... args) 
    248   { 
    249     *this << arg1; 
    250     this->Evaluate(args...); 
    251     return *this; 
    252   } 
    253  
    254   template <typename T1, typename ... TRest> 
    255   inline tLogStream &Evaluate(tLogDomainSharedPointer(&)(), const T1 &arg1, const TRest &... args) 
    256   { 
    257     *this << arg1; 
    258     this->Evaluate(args...); 
     233  inline tStream &operator << (std::ios_base &(*manipulator)(std::ios_base &)) 
     234  { 
     235    manipulator(this->stream); 
    259236    return *this; 
    260237  } 
     
    265242private: 
    266243 
    267   std::shared_ptr<tLogStreamContext> stream_context; 
     244  std::ostream stream; 
     245  std::unique_lock<std::mutex> lock; 
     246 
     247  // Prohibit copy 
     248  tStream(const tStream &other); 
    268249 
    269250  // Prohibit assignment 
    270   tLogStream &operator = (const tLogStream &other); 
     251  tStream &operator = (const tStream &other); 
    271252 
    272253  // Prohibit creation on heap 
  • messages/tStreamBuffer.cpp

    r65 r71  
    2020// 
    2121//---------------------------------------------------------------------- 
    22 /*!\file    tLogStreamBuffer.cpp 
     22/*!\file    tStreamBuffer.cpp 
    2323 * 
    2424 * \author  Tobias Foehst 
     
    2929//---------------------------------------------------------------------- 
    3030#define __rrlib__logging__include_guard__ 
    31 #include "rrlib/logging/tLogStreamBuffer.h" 
     31#include "rrlib/logging/messages/tStreamBuffer.h" 
    3232 
    3333//---------------------------------------------------------------------- 
     
    4545// Internal includes with "" 
    4646//---------------------------------------------------------------------- 
    47 #include "rrlib/logging/tLogDomainRegistry.h" 
     47#include "rrlib/logging/configuration/tDomainRegistry.h" 
    4848#include "rrlib/util/fstream/fileno.h" 
    4949 
     
    5555// Namespace usage 
    5656//---------------------------------------------------------------------- 
    57 using namespace rrlib::logging; 
     57 
     58//---------------------------------------------------------------------- 
     59// Namespace declaration 
     60//---------------------------------------------------------------------- 
     61namespace rrlib 
     62{ 
     63namespace logging 
     64{ 
    5865 
    5966//---------------------------------------------------------------------- 
     
    7077 
    7178//---------------------------------------------------------------------- 
    72 // tLogStreamBuffer WriteCharacterToBuffers 
    73 //---------------------------------------------------------------------- 
    74 int tLogStreamBuffer::WriteCharacterToBuffers(int c) 
     79// tStreamBuffer constructors 
     80//---------------------------------------------------------------------- 
     81tStreamBuffer::tStreamBuffer() 
     82    : ends_with_newline(false), 
     83    multi_line_pad_width(0), 
     84    collect_multi_line_pad_width(false), 
     85    pad_before_next_character(false) 
     86{} 
     87 
     88//---------------------------------------------------------------------- 
     89// tStreamBuffer WriteCharacterToBuffers 
     90//---------------------------------------------------------------------- 
     91int tStreamBuffer::WriteCharacterToBuffers(int c) 
    7592{ 
    7693  int result = c; 
     
    86103 
    87104//---------------------------------------------------------------------- 
    88 // tLogStreamBuffer overflow 
    89 //---------------------------------------------------------------------- 
    90 int tLogStreamBuffer::overflow(int c) 
     105// tStreamBuffer overflow 
     106//---------------------------------------------------------------------- 
     107int tStreamBuffer::overflow(int c) 
    91108{ 
    92109  if (c == EOF) 
     
    125142 
    126143//---------------------------------------------------------------------- 
    127 // tLogStreamBuffer sync 
    128 //---------------------------------------------------------------------- 
    129 int tLogStreamBuffer::sync() 
     144// tStreamBuffer sync 
     145//---------------------------------------------------------------------- 
     146int tStreamBuffer::sync() 
    130147{ 
    131148  int result = 0; 
     
    141158 
    142159//---------------------------------------------------------------------- 
    143 // tLogStreamBuffer SetColor 
    144 //---------------------------------------------------------------------- 
    145 void tLogStreamBuffer::SetColor(tLogStreamBufferEffect effect, tLogStreamBufferColor color) 
     160// tStreamBuffer SetColor 
     161//---------------------------------------------------------------------- 
     162void tStreamBuffer::SetColor(tStreamBufferEffect effect, tStreamBufferColor color) 
    146163{ 
    147164  char control_sequence[16]; 
     
    162179 
    163180//---------------------------------------------------------------------- 
    164 // tLogStreamBuffer ResetColor 
    165 //---------------------------------------------------------------------- 
    166 void tLogStreamBuffer::ResetColor() 
     181// tStreamBuffer ResetColor 
     182//---------------------------------------------------------------------- 
     183void tStreamBuffer::ResetColor() 
    167184{ 
    168185  const char *control_sequence = "\033[;0m"; 
     
    182199 
    183200//---------------------------------------------------------------------- 
    184 // tLogStreamBuffer InitializeMultiLinePadding 
    185 //---------------------------------------------------------------------- 
    186 void tLogStreamBuffer::InitializeMultiLinePadding() 
    187 { 
    188   if (!tLogDomainRegistry::GetInstance()->GetPadMultiLineMessages()) 
     201// tStreamBuffer InitializeMultiLinePadding 
     202//---------------------------------------------------------------------- 
     203void tStreamBuffer::InitializeMultiLinePadding() 
     204{ 
     205  if (!tDomainRegistry::GetInstance().GetPadMultiLineMessages()) 
    189206  { 
    190207    return; 
     
    196213 
    197214//---------------------------------------------------------------------- 
    198 // tLogStreamBuffer MarkEndOfPrefixForMultiLinePadding 
    199 //---------------------------------------------------------------------- 
    200 void tLogStreamBuffer::MarkEndOfPrefixForMultiLinePadding() 
     215// tStreamBuffer MarkEndOfPrefixForMultiLinePadding 
     216//---------------------------------------------------------------------- 
     217void tStreamBuffer::MarkEndOfPrefixForMultiLinePadding() 
    201218{ 
    202219  this->collect_multi_line_pad_width = false; 
    203220} 
    204221 
     222//---------------------------------------------------------------------- 
     223// End of namespace declaration 
     224//---------------------------------------------------------------------- 
     225} 
     226} 
  • messages/tStreamBuffer.h

    r65 r71  
    2020// 
    2121//---------------------------------------------------------------------- 
    22 /*!\file    tLogStreamBuffer.h 
     22/*!\file    tStreamBuffer.h 
    2323 * 
    2424 * \author  Tobias Foehst 
     
    2626 * \date    2010-06-23 
    2727 * 
    28  * \brief Contains tLogStreamBuffer 
     28 * \brief Contains tStreamBuffer 
    2929 * 
    30  * \b tLogStreamBuffer 
     30 * \b tStreamBuffer 
    3131 * 
    32  * tLogStreamBuffer is an implementation for std::ostreams with 
    33  * multiple sinks. Using a std::ostream for output internally uses a 
    34  * std::streambuf for the low level operations necessary to print the 
    35  * stream input to a file or terminal. By specializing std::streambuf in 
    36  * this class it is possible to collect the streambuffers of several 
    37  * ostreams and supply all these streams with own input,  like tee in 
    38  * UNIX shells. 
     32 * tStreamBuffer is an implementation for std::ostreams with multiple 
     33 * sinks. Using a std::ostream for output internally uses a std::streambuf 
     34 * for the low level operations necessary to print stream input to a file 
     35 * or terminal. By specializing std::streambuf in this class it is possible 
     36 * to collect the streambuffers of several ostreams and supply all these 
     37 * streams with own input, like tee in UNIX shells. 
    3938 * 
    4039 * Having an empty buffer vector also implements a null stream that does 
     
    4443//---------------------------------------------------------------------- 
    4544#ifndef __rrlib__logging__include_guard__ 
    46 #error Invalid include directive. Try #include "rrlib/logging/definitions.h" instead. 
     45#error Invalid include directive. Try #include "rrlib/logging/messages.h" instead. 
    4746#endif 
    4847 
    49 #ifndef __rrlib__logging__tLogStreamBuffer_h__ 
    50 #define __rrlib__logging__tLogStreamBuffer_h__ 
     48#ifndef __rrlib__logging__tStreamBuffer_h__ 
     49#define __rrlib__logging__tStreamBuffer_h__ 
    5150 
    5251//---------------------------------------------------------------------- 
     
    7675// Forward declarations / typedefs / enums 
    7776//---------------------------------------------------------------------- 
    78 enum tLogStreamBufferEffect 
     77enum tStreamBufferEffect 
    7978{ 
    8079  eLSBE_REGULAR, 
     
    8887}; 
    8988 
    90 enum tLogStreamBufferColor 
     89enum tStreamBufferColor 
    9190{ 
    9291  eLSBC_DEFAULT, 
     
    106105//! A streambuffer implementation for std::ostreams with multiple sinks 
    107106/*! Using a std::ostream for output internally uses a std::streambuf for 
    108  *  the low level operations necessary to print the stream input to a 
    109  *  file or terminal. By specializing std::streambuf in this class it is 
     107 *  the low level operations necessary to print stream input to a file 
     108 *  or terminal. By specializing std::streambuf in this class it is 
    110109 *  possible to collect the streambuffers of several ostreams and supply 
    111110 *  all these streams with own input, like tee in UNIX shells. 
     111 * 
    112112 *  Having an empty buffer vector also implements a null stream that does 
    113113 *  not open /dev/null to swallow all input. 
    114114 * 
    115115 */ 
    116 class tLogStreamBuffer : public std::streambuf 
     116class tStreamBuffer : public std::streambuf 
    117117{ 
    118118 
     
    122122public: 
    123123 
    124   /*! The ctor of tLogStreamBuffer 
     124  /*! The ctor of tStreamBuffer 
    125125   * 
    126126   */ 
    127   tLogStreamBuffer() 
    128       : ends_with_newline(false), 
    129       multi_line_pad_width(0), 
    130       collect_multi_line_pad_width(false), 
    131       pad_before_next_character(false) 
    132   {} 
     127  tStreamBuffer(); 
    133128 
    134129  /*! Add a target output stream to this buffer 
     
    165160  } 
    166161 
    167   void SetColor(tLogStreamBufferEffect effect, tLogStreamBufferColor color); 
     162  void SetColor(tStreamBufferEffect effect, tStreamBufferColor color); 
    168163 
    169164  void ResetColor(); 
  • test/test_messages.cpp

    r69 r71  
    3636#include <stdexcept> 
    3737#include <iterator> 
     38#include <iomanip> 
    3839 
    3940extern "C" 
     
    149150  local::Test::function(); 
    150151 
    151 //  RRLIB_LOG_PRINT(eLL_ERROR, std::runtime_error("runtime_error")); 
     152  RRLIB_LOG_PRINT(eLL_ERROR, std::runtime_error("runtime_error")); 
    152153 
    153   RRLIB_LOG_PRINT(eLL_WARNING, std::hex, 324); 
     154  RRLIB_LOG_PRINT(eLL_WARNING, "0x", std::setw(20), std::setfill('0'), std::hex, 324); 
    154155 
    155156  RRLIB_LOG_PRINT(eLL_ERROR, "Das hier ist ein mehrzeiliger\nFehler."); 
     
    163164  test_static.NonStaticMethod(); 
    164165 
     166  int *a = 0; 
     167  const int *b = 0; 
     168  RRLIB_LOG_PRINT(eLL_DEBUG, "Pointer: ", a); 
     169  RRLIB_LOG_PRINT(eLL_DEBUG, "Const-Pointer: ", b); 
     170  RRLIB_LOG_PRINT(eLL_DEBUG, "Bool: ", true, false); 
     171  RRLIB_LOG_PRINT(eLL_DEBUG, "Function: ", main); 
     172 
    165173  return EXIT_SUCCESS; 
    166174} 
Note: See TracChangeset for help on using the changeset viewer.