Changeset 98:f40464cb142a in rrlib_logging


Ignore:
Timestamp:
11.12.2012 16:26:45 (8 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Transplant:
1727082938366fba9e8d78ca273789cda82834b5
Message:

Made instantiation of log domain configuration more aware of context regarding RRLIB_LOGGING_LESS_OUTPUT

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • configuration.cpp

    r95 r98  
    103103// SetDomainPrintsName 
    104104//---------------------------------------------------------------------- 
    105 void SetDomainPrintsName(const std::string &domain_name, bool value) 
    106 { 
    107   const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(NULL, domain_name.c_str())).SetPrintsName(value); 
     105void SetDomainPrintsName(const std::string &domain_name, bool value, const tDefaultConfigurationContext &default_context) 
     106{ 
     107  const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(default_context, NULL, domain_name.c_str())).SetPrintsName(value); 
    108108} 
    109109 
     
    111111// SetDomainPrintsTime 
    112112//---------------------------------------------------------------------- 
    113 void SetDomainPrintsTime(const std::string &domain_name, bool value) 
    114 { 
    115   const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(NULL, domain_name.c_str())).SetPrintsTime(value); 
     113void SetDomainPrintsTime(const std::string &domain_name, bool value, const tDefaultConfigurationContext &default_context) 
     114{ 
     115  const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(default_context, NULL, domain_name.c_str())).SetPrintsTime(value); 
    116116} 
    117117 
     
    119119// SetDomainPrintsLevel 
    120120//---------------------------------------------------------------------- 
    121 void SetDomainPrintsLevel(const std::string &domain_name, bool value) 
    122 { 
    123   const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(NULL, domain_name.c_str())).SetPrintsLevel(value); 
     121void SetDomainPrintsLevel(const std::string &domain_name, bool value, const tDefaultConfigurationContext &default_context) 
     122{ 
     123  const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(default_context, NULL, domain_name.c_str())).SetPrintsLevel(value); 
    124124} 
    125125 
     
    127127// SetDomainPrintsLocation 
    128128//---------------------------------------------------------------------- 
    129 void SetDomainPrintsLocation(const std::string &domain_name, bool value) 
    130 { 
    131   const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(NULL, domain_name.c_str())).SetPrintsLocation(value); 
     129void SetDomainPrintsLocation(const std::string &domain_name, bool value, const tDefaultConfigurationContext &default_context) 
     130{ 
     131  const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(default_context, NULL, domain_name.c_str())).SetPrintsLocation(value); 
    132132} 
    133133 
     
    135135// SetDomainMaxMessageLevel 
    136136//---------------------------------------------------------------------- 
    137 void SetDomainMaxMessageLevel(const std::string &domain_name, tLogLevel level) 
    138 { 
    139   const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(NULL, domain_name.c_str())).SetMaxMessageLevel(level); 
     137void SetDomainMaxMessageLevel(const std::string &domain_name, tLogLevel level, const tDefaultConfigurationContext &default_context) 
     138{ 
     139  const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(default_context, NULL, domain_name.c_str())).SetMaxMessageLevel(level); 
    140140} 
    141141 
     
    143143// SetDomainSink 
    144144//---------------------------------------------------------------------- 
    145 void SetDomainSink(const std::string &domain_name, tLogSink sink_1, tLogSink sink_2, tLogSink sink_3, tLogSink sink_4) 
    146 { 
    147   const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(NULL, domain_name.c_str())).SetSinkMask(sink_1 | sink_2 | sink_3 | sink_4); 
     145void SetDomainSink(const std::string &domain_name, tLogSink sink_1, tLogSink sink_2, tLogSink sink_3, tLogSink sink_4, const tDefaultConfigurationContext &default_context) 
     146{ 
     147  const_cast<tConfiguration &>(tDomainRegistry::Instance().GetConfiguration(default_context, NULL, domain_name.c_str())).SetSinkMask(sink_1 | sink_2 | sink_3 | sink_4); 
    148148} 
    149149 
     
    165165  }; 
    166166 
    167   RecursionHandler::Print(tDomainRegistry::Instance().GetConfiguration(NULL, ".")); 
     167  RecursionHandler::Print(tDomainRegistry::Instance().GetConfiguration(cDEFAULT_CONTEXT, NULL, ".")); 
    168168} 
    169169 
  • configuration.h

    r95 r98  
    4242#include "rrlib/logging/log_levels.h" 
    4343#include "rrlib/logging/default_log_description.h" 
     44#include "rrlib/logging/configuration/tConfiguration.h" 
    4445#include "rrlib/logging/configuration/tDomainRegistry.h" 
    4546 
     
    6869void SetPadMultiLineMessages(bool value); 
    6970 
    70 void SetDomainPrintsName(const std::string &domain_name, bool value); 
     71void SetDomainPrintsName(const std::string &domain_name, bool value, const tDefaultConfigurationContext &default_context = cDEFAULT_CONTEXT); 
    7172 
    72 void SetDomainPrintsTime(const std::string &domain_name, bool value); 
     73void SetDomainPrintsTime(const std::string &domain_name, bool value, const tDefaultConfigurationContext &default_context = cDEFAULT_CONTEXT); 
    7374 
    74 void SetDomainPrintsLevel(const std::string &domain_name, bool value); 
     75void SetDomainPrintsLevel(const std::string &domain_name, bool value, const tDefaultConfigurationContext &default_context = cDEFAULT_CONTEXT); 
    7576 
    76 void SetDomainPrintsLocation(const std::string &domain_name, bool value); 
     77void SetDomainPrintsLocation(const std::string &domain_name, bool value, const tDefaultConfigurationContext &default_context = cDEFAULT_CONTEXT); 
    7778 
    78 void SetDomainMaxMessageLevel(const std::string &domain_name, tLogLevel level); 
     79void SetDomainMaxMessageLevel(const std::string &domain_name, tLogLevel level, const tDefaultConfigurationContext &default_context = cDEFAULT_CONTEXT); 
    7980 
    80 void SetDomainSink(const std::string &domain_name, tLogSink sink_1, tLogSink sink_2 = (tLogSink)0, tLogSink sink_3 = (tLogSink)0, tLogSink sink_4 = (tLogSink)0); 
     81void SetDomainSink(const std::string &domain_name, tLogSink sink_1, tLogSink sink_2 = (tLogSink)0, tLogSink sink_3 = (tLogSink)0, tLogSink sink_4 = (tLogSink)0, const tDefaultConfigurationContext &default_context = cDEFAULT_CONTEXT); 
    8182 
    8283void PrintDomainConfigurations(); 
  • configuration/tConfiguration.cpp

    r97 r98  
    6565// Const values 
    6666//---------------------------------------------------------------------- 
    67 #ifdef RRLIB_LOGGING_LESS_OUTPUT 
    68 const bool cDEFAULT_PRINTS_NAME = false;                       //!< Default prints name setting for reduced output mode 
    69 const bool cDEFAULT_PRINTS_TIME = false;                       //!< Default prints time setting for reduced output mode 
    70 const bool cDEFAULT_PRINTS_LEVEL = false;                      //!< Default prints level setting for reduced output mode 
    71 const bool cDEFAULT_PRINTS_LOCATION = false;                   //!< Default prints location setting for reduced output mode 
    72 const tLogLevel cDEFAULT_MAX_LOG_LEVEL = tLogLevel::WARNING;   //!< Default max log level for reduced output mode 
    73 const int cDEFAULT_SINK_MASK = 1 << eLOG_SINK_STDOUT;          //!< Default output stream mask 
    74 #else 
    75 const bool cDEFAULT_PRINTS_NAME = false;                       //!< Default prints name setting for normal output mode 
    76 const bool cDEFAULT_PRINTS_TIME = false;                       //!< Default prints time setting for normal output mode 
    77 const bool cDEFAULT_PRINTS_LEVEL = false;                      //!< Default prints level setting for normal output mode 
    78 const bool cDEFAULT_PRINTS_LOCATION = true;                    //!< Default prints location setting for normal output mode 
    79 const tLogLevel cDEFAULT_MAX_LOG_LEVEL = tLogLevel::DEBUG;     //!< Default max log level for normal output mode 
    80 const int cDEFAULT_SINK_MASK = 1 << eLOG_SINK_STDOUT;          //!< Default output stream mask 
    81 #endif 
    82  
    8367const int cLOG_SINK_COMBINED_FILE_CHILD_MASK = 1 << eLOG_SINK_DIMENSION; 
    8468 
     
    9074// tConfiguration constructors 
    9175//---------------------------------------------------------------------- 
    92 tConfiguration::tConfiguration(const tConfiguration *parent, const std::string &name) 
     76tConfiguration::tConfiguration(const tDefaultConfigurationContext &default_context, const tConfiguration *parent, const std::string &name) 
    9377  : parent(parent), 
    9478    name(name), 
    95     prints_name(parent ? parent->prints_name : cDEFAULT_PRINTS_NAME), 
    96     prints_time(parent ? parent->prints_time : cDEFAULT_PRINTS_TIME), 
    97     prints_level(parent ? parent->prints_level : cDEFAULT_PRINTS_LEVEL), 
    98     prints_location(parent ? parent->prints_location : cDEFAULT_PRINTS_LOCATION), 
    99     max_message_level(parent ? parent->max_message_level : cDEFAULT_MAX_LOG_LEVEL), 
    100     sink_mask(parent ? parent->sink_mask | cLOG_SINK_COMBINED_FILE_CHILD_MASK : cDEFAULT_SINK_MASK), 
     79    prints_name(parent ? parent->prints_name : default_context.cPRINTS_NAME), 
     80    prints_time(parent ? parent->prints_time : default_context.cPRINTS_TIME), 
     81    prints_level(parent ? parent->prints_level : default_context.cPRINTS_LEVEL), 
     82    prints_location(parent ? parent->prints_location : default_context.cPRINTS_LOCATION), 
     83    max_message_level(parent ? parent->max_message_level : default_context.cMAX_LOG_LEVEL), 
     84    sink_mask(parent ? parent->sink_mask | cLOG_SINK_COMBINED_FILE_CHILD_MASK : default_context.cSINK_MASK), 
    10185    stream_buffer_ready(false) 
    10286{ 
     
    199183// tConfiguration GetConfigurationByName 
    200184//---------------------------------------------------------------------- 
    201 const tConfiguration &tConfiguration::GetConfigurationByName(const char *domain_name) const 
     185const tConfiguration &tConfiguration::GetConfigurationByName(const tDefaultConfigurationContext &default_context, const char *domain_name) const 
    202186{ 
    203187  assert(domain_name && *domain_name); 
     
    207191  if (!delimiter) 
    208192  { 
    209     return this->LookupChild(domain_name, std::strlen(domain_name)); 
    210   } 
    211  
    212   return this->LookupChild(domain_name, delimiter - domain_name).GetConfigurationByName(delimiter + 1); 
     193    return this->LookupChild(default_context, domain_name, std::strlen(domain_name)); 
     194  } 
     195 
     196  return this->LookupChild(default_context, domain_name, delimiter - domain_name).GetConfigurationByName(default_context, delimiter + 1); 
    213197} 
    214198 
     
    216200// tConfiguration GetConfigurationByFilename 
    217201//---------------------------------------------------------------------- 
    218 const tConfiguration &tConfiguration::GetConfigurationByFilename(const char *filename) const 
     202const tConfiguration &tConfiguration::GetConfigurationByFilename(const tDefaultConfigurationContext &default_context, const char *filename) const 
    219203{ 
    220204  assert(filename && *filename); 
     
    227211  } 
    228212 
    229   return this->LookupChild(filename, delimiter - filename).GetConfigurationByFilename(delimiter + 1); 
     213  return this->LookupChild(default_context, filename, delimiter - filename).GetConfigurationByFilename(default_context, delimiter + 1); 
    230214} 
    231215 
     
    233217// tConfiguration LookupChild 
    234218//---------------------------------------------------------------------- 
    235 const tConfiguration &tConfiguration::LookupChild(const char *name, size_t length) const 
     219const tConfiguration &tConfiguration::LookupChild(const tDefaultConfigurationContext &default_context, const char *name, size_t length) const 
    236220{ 
    237221  tConfiguration *configuration = 0; 
     
    267251  if (!configuration) 
    268252  { 
    269     configuration = new tConfiguration(this, std::string(name, length)); 
     253    configuration = new tConfiguration(default_context, this, std::string(name, length)); 
    270254    const tConfiguration *parent = configuration->parent; 
    271255    size_t full_name_length = 0; 
  • configuration/tConfiguration.h

    r96 r98  
    100100  eLOG_SINK_DIMENSION        //!< Endmarker and dimension of tLogSink 
    101101}; 
     102 
     103struct tDefaultConfigurationContext 
     104{ 
     105  const bool cPRINTS_NAME; 
     106  const bool cPRINTS_TIME; 
     107  const bool cPRINTS_LEVEL; 
     108  const bool cPRINTS_LOCATION; 
     109  const tLogLevel cMAX_LOG_LEVEL; 
     110  const int cSINK_MASK; 
     111}; 
     112#ifdef RRLIB_LOGGING_LESS_OUTPUT 
     113static const tDefaultConfigurationContext cDEFAULT_CONTEXT 
     114{ 
     115  false, false, false, false, tLogLevel::WARNING, 1 << eLOG_SINK_STDOUT 
     116}; 
     117#else 
     118static const tDefaultConfigurationContext cDEFAULT_CONTEXT 
     119{ 
     120  false, false, false, true, tLogLevel::DEBUG, 1 << eLOG_SINK_STDOUT 
     121}; 
     122#endif 
    102123 
    103124//---------------------------------------------------------------------- 
     
    203224  mutable std::list<tConfiguration *> children; 
    204225 
    205   tConfiguration(const tConfiguration *parent, const std::string &name); 
     226  tConfiguration(const tDefaultConfigurationContext &default_context, const tConfiguration *parent, const std::string &name); 
    206227 
    207228  tConfiguration(const tConfiguration &other); 
     
    209230  tConfiguration &operator = (const tConfiguration other); 
    210231 
    211   const tConfiguration &GetConfigurationByName(const char *domain_name) const; 
    212  
    213   const tConfiguration &GetConfigurationByFilename(const char *filename) const; 
    214  
    215   const tConfiguration &LookupChild(const char *name, size_t length) const; 
     232  const tConfiguration &GetConfigurationByName(const tDefaultConfigurationContext &default_context, const char *domain_name) const; 
     233 
     234  const tConfiguration &GetConfigurationByFilename(const tDefaultConfigurationContext &default_context, const char *filename) const; 
     235 
     236  const tConfiguration &LookupChild(const tDefaultConfigurationContext &default_context, const char *name, size_t length) const; 
    216237 
    217238  void PrepareStreamBuffer() const; 
  • configuration/tDomainRegistry.cpp

    r85 r98  
    7575//---------------------------------------------------------------------- 
    7676tDomainRegistryImplementation::tDomainRegistryImplementation() 
    77   : global_configuration(new tConfiguration(0, "")), 
     77  : global_configuration(new tConfiguration(cDEFAULT_CONTEXT, 0, "")), 
    7878    max_domain_name_length(0), 
    7979    pad_prefix_columns(true), 
     
    117117// tDomainRegistryImplementation GetConfiguration 
    118118//---------------------------------------------------------------------- 
    119 const tConfiguration &tDomainRegistryImplementation::GetConfiguration(const char *filename, const char *domain_name) 
     119const tConfiguration &tDomainRegistryImplementation::GetConfiguration(const tDefaultConfigurationContext &default_context, const char *filename, const char *domain_name) 
    120120{ 
    121121  if (domain_name) 
     
    125125    { 
    126126      assert(this->global_configuration); 
    127       return (domain_name[1] == 0) ? *this->global_configuration : this->global_configuration->GetConfigurationByName(domain_name + 1); 
     127      return (domain_name[1] == 0) ? *this->global_configuration : this->global_configuration->GetConfigurationByName(default_context, domain_name + 1); 
    128128    } 
    129     return tDomainRegistry::Instance().GetConfigurationByFilename(filename).GetConfigurationByName(domain_name); 
    130   } 
    131   return tDomainRegistry::Instance().GetConfigurationByFilename(filename); 
     129    return tDomainRegistry::Instance().GetConfigurationByFilename(default_context, filename).GetConfigurationByName(default_context, domain_name); 
     130  } 
     131  return tDomainRegistry::Instance().GetConfigurationByFilename(default_context, filename); 
    132132} 
    133133 
     
    164164// tDomainRegistryImplementation GetConfigurationByFilename 
    165165//---------------------------------------------------------------------- 
    166 const tConfiguration &tDomainRegistryImplementation::GetConfigurationByFilename(const char *filename) const 
     166const tConfiguration &tDomainRegistryImplementation::GetConfigurationByFilename(const tDefaultConfigurationContext &default_context, const char *filename) const 
    167167{ 
    168168  bool found_prefix = false; 
     
    196196 
    197197  assert(this->global_configuration); 
    198   return this->global_configuration->GetConfigurationByFilename(filename); 
     198  return this->global_configuration->GetConfigurationByFilename(default_context, filename); 
    199199} 
    200200 
  • configuration/tDomainRegistry.h

    r93 r98  
    110110  ~tDomainRegistryImplementation(); 
    111111 
    112   const tConfiguration &GetConfiguration(const char *filename, const char *domain_name = 0); 
     112  const tConfiguration &GetConfiguration(const tDefaultConfigurationContext &default_context, const char *filename, const char *domain_name = 0); 
    113113 
    114114  /*! Set a prefix for filenames that are created as log 
     
    211211  bool pad_multi_line_messages; 
    212212 
    213   const tConfiguration &GetConfigurationByFilename(const char *filename) const; 
     213  const tConfiguration &GetConfigurationByFilename(const tDefaultConfigurationContext &default_context, const char *filename) const; 
    214214 
    215215}; 
  • messages/implementation.cpp

    r94 r98  
    7373// GetConfiguration 
    7474//---------------------------------------------------------------------- 
    75 const tConfiguration &GetConfiguration(const char *filename, const char *domain_name) 
     75const tConfiguration &GetConfiguration(const char *filename, const char *domain_name, const tDefaultConfigurationContext &default_context) 
    7676{ 
    77   return tDomainRegistry::Instance().GetConfiguration(filename, domain_name); 
     77  return tDomainRegistry::Instance().GetConfiguration(default_context, filename, domain_name); 
    7878} 
    7979 
  • messages/implementation.h

    r94 r98  
    6262// Implementation 
    6363//---------------------------------------------------------------------- 
    64 const tConfiguration &GetConfiguration(const char *filename, const char *domain_name = 0); 
    6564 
    66  
     65const tConfiguration &GetConfiguration(const char *filename, const char *domain_name = 0, const tDefaultConfigurationContext &default_context = cDEFAULT_CONTEXT); 
    6766 
    6867void SendFormattedTimeToStream(tStream &stream); 
Note: See TracChangeset for help on using the changeset viewer.