Changeset 73:9a9a1f10cdd9 in rrlib_logging


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

Changed macro definitions and lookup for explicit specified domains.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • configuration/tDomainRegistry.cpp

    r71 r73  
    135135 
    136136//---------------------------------------------------------------------- 
     137// tDomainRegistryImplementation GetConfiguration 
     138//---------------------------------------------------------------------- 
     139const tConfiguration &tDomainRegistryImplementation::GetConfiguration(const char *filename, const char *domain_name) const 
     140{ 
     141  if (domain_name) 
     142  { 
     143    if (domain_name[0] == '.') 
     144    { 
     145      assert(this->global_configuration); 
     146      this->global_configuration->GetConfigurationByName(domain_name + 1); 
     147    } 
     148    return tDomainRegistry::Instance().GetConfigurationByFilename(filename).GetConfigurationByName(domain_name); 
     149  } 
     150  return tDomainRegistry::Instance().GetConfigurationByFilename(filename); 
     151} 
     152 
     153//---------------------------------------------------------------------- 
    137154// tDomainRegistryImplementation GetConfigurationByFilename 
    138155//---------------------------------------------------------------------- 
  • configuration/tDomainRegistry.h

    r71 r73  
    115115  ~tDomainRegistryImplementation(); 
    116116 
    117   inline const tConfiguration &GetGlobalConfiguration() const 
    118   { 
    119     assert(this->global_configuration); 
    120     return *this->global_configuration; 
    121   } 
     117  const tConfiguration &GetConfiguration(const char *filename, const char *domain_name = 0) const; 
    122118 
    123119  const tConfiguration &GetConfigurationByFilename(const char *filename) const; 
     
    246242  bool pad_multi_line_messages; 
    247243 
     244  const tConfiguration &GetConfigurationByFilename(const char *filename) const; 
     245 
    248246//#ifdef _LIB_RRLIB_XML2_WRAPPER_PRESENT_ 
    249247//  /*! Add a domain configuration from a given XML node 
  • messages.h

    r69 r73  
    5454// Namespace declaration 
    5555//---------------------------------------------------------------------- 
    56 // The macro interface and defaul GetLogDescription function must live 
     56// The macro interface and default GetLogDescription function must live 
    5757// within the global namespace 
    5858 
     
    9797/*! Macro to print messages to explicitly specified domain using stream semantics 
    9898 * 
    99  * \param level    The level of the message 
    100  * \param domain   The domain the message should be printed to 
    101  * \param args     The data to be put into the underlying stream 
    102  */ 
    103 #define RRLIB_LOG_PRINT(level, domain_name, args...) \ 
    104   do \ 
    105   { \ 
    106     if ((level) <= rrlib::logging::eLL_DEBUG) \ 
    107     { \ 
    108       __RRLIB_LOG_PRINT__(rrlib::logging::GetConfiguration(__FILE__, domain_name), level, args) \ 
     99 * \param domain   The domain the message should be printed to 
     100 * \param level    The level of the message 
     101 * \param args     The data to be put into the underlying stream 
     102 */ 
     103#define RRLIB_LOG_PRINT_TO(domain_name, level, args...) \ 
     104  do \ 
     105  { \ 
     106    if ((level) <= rrlib::logging::eLL_DEBUG) \ 
     107    { \ 
     108      __RRLIB_LOG_PRINT__(rrlib::logging::GetConfiguration(__FILE__, #domain_name), level, args) \ 
    109109    } \ 
    110110  } while (0) \ 
     
    126126/*! Macro to print messages to explicitly specified domain using stream semantics from static context 
    127127 * 
    128  * \param level    The level of the message 
    129  * \param domain   The domain the message should be printed to 
    130  * \param args     The data to be put into the underlying stream 
    131  */ 
    132 #define RRLIB_LOG_PRINT_STATIC(level, domain_name, args...) \ 
    133   do \ 
    134   { \ 
    135     if ((level) <= rrlib::logging::eLL_DEBUG) \ 
    136     { \ 
    137       __RRLIB_LOG_PRINT_STATIC__(rrlib::logging::GetConfiguration(__FILE__, domain_name), level, args) \ 
     128 * \param domain   The domain the message should be printed to 
     129 * \param level    The level of the message 
     130 * \param args     The data to be put into the underlying stream 
     131 */ 
     132#define RRLIB_LOG_PRINT_STATIC_TO(domain_name, level, args...) \ 
     133  do \ 
     134  { \ 
     135    if ((level) <= rrlib::logging::eLL_DEBUG) \ 
     136    { \ 
     137      __RRLIB_LOG_PRINT_STATIC__(rrlib::logging::GetConfiguration(__FILE__, #domain_name), level, args) \ 
    138138    } \ 
    139139  } while (0) \ 
     
    155155/*! Macro to print messages to explicitly specified domain using printf semantics 
    156156 * 
    157  * \param level    The level of the message 
    158  * \param domain   The domain the message should be printed to 
    159  * \param args     The format string for printf and the optional arguments to be printed 
    160  */ 
    161 #define RRLIB_LOG_PRINTF(level, domain_name, args...) \ 
    162   do \ 
    163   { \ 
    164     if ((level) <= rrlib::logging::eLL_DEBUG) \ 
    165     { \ 
    166       __RRLIB_LOG_PRINTF__(rrlib::logging::GetConfiguration(__FILE__, domain_name), level, args) \ 
     157 * \param domain   The domain the message should be printed to 
     158 * \param level    The level of the message 
     159 * \param args     The format string for printf and the optional arguments to be printed 
     160 */ 
     161#define RRLIB_LOG_PRINTF_TO(domain_name, level, args...) \ 
     162  do \ 
     163  { \ 
     164    if ((level) <= rrlib::logging::eLL_DEBUG) \ 
     165    { \ 
     166      __RRLIB_LOG_PRINTF__(rrlib::logging::GetConfiguration(__FILE__, #domain_name), level, args) \ 
    167167    } \ 
    168168  } while (0) \ 
     
    184184/*! Macro to print messages to explicitly specified domain using printf semantics from static context 
    185185 * 
    186  * \param level    The level of the message 
    187  * \param domain   The domain the message should be printed to 
    188  * \param args     The format string for printf and the optional arguments to be printed 
    189  */ 
    190 #define RRLIB_LOG_PRINTF_STATIC(level, domain_name, args...) \ 
    191   do \ 
    192   { \ 
    193     if ((level) <= rrlib::logging::eLL_DEBUG) \ 
    194     { \ 
    195       __RRLIB_LOG_PRINTF_STATIC__(rrlib::logging::GetConfiguration(__FILE__, domain_name), level, args) \ 
     186 * \param domain   The domain the message should be printed to 
     187 * \param level    The level of the message 
     188 * \param args     The format string for printf and the optional arguments to be printed 
     189 */ 
     190#define RRLIB_LOG_PRINTF_STATIC_TO(domain_name, level, args...) \ 
     191  do \ 
     192  { \ 
     193    if ((level) <= rrlib::logging::eLL_DEBUG) \ 
     194    { \ 
     195      __RRLIB_LOG_PRINTF_STATIC__(rrlib::logging::GetConfiguration(__FILE__, #domain_name), level, args) \ 
    196196    } \ 
    197197  } while (0) \ 
     
    209209/*! Macro to print messages to explicitly specified domain using stream semantics 
    210210 * 
    211  * \param level    The level of the message 
    212  * \param domain   The domain the message should be printed to 
    213  * \param args     The data to be put into the underlying stream 
    214  */ 
    215 #define RRLIB_LOG_PRINT_EXPLICIT(level, domain_name, args...) \ 
    216   __RRLIB_LOG_PRINT__(rrlib::logging::GetConfiguration(__FILE__, domain_name), level, args) \ 
     211 * \param domain   The domain the message should be printed to 
     212 * \param level    The level of the message 
     213 * \param args     The data to be put into the underlying stream 
     214 */ 
     215#define RRLIB_LOG_PRINT_TO(domain_name, level, args...) \ 
     216  __RRLIB_LOG_PRINT__(rrlib::logging::GetConfiguration(__FILE__, #domain_name), level, args) \ 
    217217    
    218218/*! Macro to print messages using stream semantics static context 
     
    226226/*! Macro to print messages to explicitly specified using stream semantics static context 
    227227 * 
    228  * \param level    The level of the message 
    229  * \param domain   The domain the message should be printed to 
    230  * \param args     The data to be put into the underlying stream 
    231  */ 
    232 #define RRLIB_LOG_PRINT_STATIC_EXPLICIT(level, domain_name, args...) \ 
    233   __RRLIB_LOG_PRINT_STATIC__(rrlib::logging::GetConfiguration(__FILE__, domain_name), level, args) \ 
     228 * \param domain   The domain the message should be printed to 
     229 * \param level    The level of the message 
     230 * \param args     The data to be put into the underlying stream 
     231 */ 
     232#define RRLIB_LOG_PRINT_STATIC_TO(domain_name, level, args...) \ 
     233  __RRLIB_LOG_PRINT_STATIC__(rrlib::logging::GetConfiguration(__FILE__, #domain_name), level, args) \ 
    234234    
    235235/*! Macro to print messages using printf semantics 
     
    243243/*! Macro to print messages to explicitly specified using printf semantics 
    244244 * 
    245  * \param level    The level of the message 
    246  * \param domain   The domain the message should be printed to 
    247  * \param args     The format string for printf and the optional arguments to be printed 
    248  */ 
    249 #define RRLIB_LOG_PRINTF_EXPLICIT(level, domain_name, args...) \ 
    250   __RRLIB_LOG_PRINTF__(rrlib::logging::GetConfiguration(__FILE__, domain_name), level, args) \ 
     245 * \param domain   The domain the message should be printed to 
     246 * \param level    The level of the message 
     247 * \param args     The format string for printf and the optional arguments to be printed 
     248 */ 
     249#define RRLIB_LOG_PRINTF_TO(domain_name, level, args...) \ 
     250  __RRLIB_LOG_PRINTF__(rrlib::logging::GetConfiguration(__FILE__, #domain_name), level, args) \ 
    251251    
    252252/*! Macro to print messages using printf semantics from static context 
     
    260260/*! Macro to print messages to explicitly specified using printf semantics from static context 
    261261 * 
    262  * \param level    The level of the message 
    263  * \param domain   The domain the message should be printed to 
    264  * \param args     The format string for printf and the optional arguments to be printed 
    265  */ 
    266 #define RRLIB_LOG_PRINTF_STATIC_EXPLICIT(level, domain_name, args...) \ 
    267   __RRLIB_LOG_PRINTF_STATIC__(rrlib::logging::GetConfiguration(__FILE__, domain_name), level, args) \ 
     262 * \param domain   The domain the message should be printed to 
     263 * \param level    The level of the message 
     264 * \param args     The format string for printf and the optional arguments to be printed 
     265 */ 
     266#define RRLIB_LOG_PRINTF_STATIC_TO(domain_name, level, args...) \ 
     267  __RRLIB_LOG_PRINTF_STATIC__(rrlib::logging::GetConfiguration(__FILE__, #domain_name), level, args) \ 
    268268    
    269269#endif 
  • test/test_messages.cpp

    r71 r73  
    5858// Namespace usage 
    5959//---------------------------------------------------------------------- 
    60 using namespace rrlib::logging; 
    6160 
    6261//---------------------------------------------------------------------- 
     
    7978  static void function() 
    8079  { 
    81     RRLIB_LOG_PRINT_EXPLICIT(eLL_DEBUG_WARNING, "my_domain", "this ", "is a ", "local class test"); 
     80    RRLIB_LOG_PRINT_TO(my_domain, rrlib::logging::eLL_DEBUG_WARNING, "this ", "is a ", "local class test"); 
    8281 
    83     RRLIB_LOG_PRINT(eLL_WARNING, "foo"); 
    84     RRLIB_LOG_PRINT_EXPLICIT(eLL_ERROR, "my_domain", "foo2"); 
     82    RRLIB_LOG_PRINT(rrlib::logging::eLL_WARNING, "foo"); 
     83    RRLIB_LOG_PRINT_TO(my_domain, rrlib::logging::eLL_ERROR, "foo2"); 
    8584    if (true) 
    8685    { 
    87       RRLIB_LOG_PRINTF_EXPLICIT(eLL_DEBUG, "my_domain", "%s\n", "FOO"); 
     86      RRLIB_LOG_PRINTF_TO(my_domain, rrlib::logging::eLL_DEBUG, "%s\n", "FOO"); 
    8887    } 
    8988  } 
     
    101100  static void StaticMethod() 
    102101  { 
    103     RRLIB_LOG_PRINT_STATIC(eLL_USER, "From static method"); 
     102    RRLIB_LOG_PRINT_STATIC(rrlib::logging::eLL_USER, "From static method"); 
    104103  } 
    105104 
    106105  void NonStaticMethod() 
    107106  { 
    108     RRLIB_LOG_PRINT(eLL_USER, "From non-static method"); 
     107    RRLIB_LOG_PRINT(rrlib::logging::eLL_USER, "From non-static method"); 
    109108  } 
    110109}; 
     
    113112int main(int argc, char **argv) 
    114113{ 
    115   default_log_description = basename(argv[0]); 
     114  rrlib::logging::default_log_description = basename(argv[0]); 
    116115 
    117116#ifdef _LIB_RRLIB_XML2_WRAPPER_PRESENT_ 
     
    123122#endif 
    124123 
    125 //  tLogDomainRegistry::GetInstance()->SetOutputFileNamePrefix(basename(argv[0])); 
     124  rrlib::logging::SetLogFilenamePrefix(basename(argv[0])); 
    126125 
    127  
    128 //  std::cout << tLogDomainRegistry::GetInstance() << std::endl; 
     126  std::cout << rrlib::logging::tDomainRegistry::Instance().LogFilenamePrefix() << std::endl; 
    129127 
    130128//  tLogDomainRegistry::GetInstance()->SetDomainConfiguresSubTree("global", true); 
     
    143141 
    144142 
    145   RRLIB_LOG_PRINT(eLL_WARNING, "foo"); 
     143  RRLIB_LOG_PRINT(rrlib::logging::eLL_WARNING, "foo"); 
    146144 
    147145  libA::Test(); 
     
    150148  local::Test::function(); 
    151149 
    152   RRLIB_LOG_PRINT(eLL_ERROR, std::runtime_error("runtime_error")); 
     150  RRLIB_LOG_PRINT(rrlib::logging::eLL_ERROR, std::runtime_error("runtime_error")); 
    153151 
    154   RRLIB_LOG_PRINT(eLL_WARNING, "0x", std::setw(20), std::setfill('0'), std::hex, 324); 
     152  RRLIB_LOG_PRINT(rrlib::logging::eLL_WARNING, "0x", std::setw(20), std::setfill('0'), std::hex, 324); 
    155153 
    156   RRLIB_LOG_PRINT(eLL_ERROR, "Das hier ist ein mehrzeiliger\nFehler."); 
    157   RRLIB_LOG_PRINT(eLL_USER, "Und das hier ein mehrzeiliger\nText fuer den lieben Benutzer."); 
     154  RRLIB_LOG_PRINT(rrlib::logging::eLL_ERROR, "Das hier ist ein mehrzeiliger\nFehler."); 
     155  RRLIB_LOG_PRINT(rrlib::logging::eLL_USER, "Und das hier ein mehrzeiliger\nText fuer den lieben Benutzer."); 
    158156 
    159157  const char* texts[] = {"Dies", "ist", "ein", "kleiner", "Text."}; 
    160   RRLIB_LOG_PRINT(eLL_DEBUG, rrlib::util::Join(texts, texts + 5, " ")); 
     158  RRLIB_LOG_PRINT(rrlib::logging::eLL_DEBUG, rrlib::util::Join(texts, texts + 5, " ")); 
    161159 
    162160  TestStatic test_static; 
     
    166164  int *a = 0; 
    167165  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); 
     166  RRLIB_LOG_PRINT(rrlib::logging::eLL_DEBUG, "Pointer: ", a); 
     167  RRLIB_LOG_PRINT(rrlib::logging::eLL_DEBUG, "Const-Pointer: ", b); 
     168  RRLIB_LOG_PRINT(rrlib::logging::eLL_DEBUG, "Bool: ", true, false); 
     169  RRLIB_LOG_PRINT(rrlib::logging::eLL_DEBUG, "Function: ", main); 
    172170 
    173171  return EXIT_SUCCESS; 
Note: See TracChangeset for help on using the changeset viewer.