Changeset 75:d56b1a718d33 in rrlib_logging


Ignore:
Timestamp:
07.01.2012 23:58:07 (8 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Message:

Replaced macro RRLIB_LOG_PATH by environment variable and renamed it to RRLIB_LOGGING_PATH

Location:
configuration
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • configuration/tConfiguration.cpp

    r74 r75  
    116116void tConfiguration::SetPrintsName(bool value) 
    117117{ 
    118   std::cout << "SetPrintsName: " << value << " in " << this->GetFullQualifiedName() << std::endl; 
    119118  this->prints_name = value; 
    120119  for (auto it = this->children.begin(); it != this->children.end(); ++it) 
  • configuration/tDomainRegistry.cpp

    r74 r75  
    3434// External includes (system with <>, local with "") 
    3535//---------------------------------------------------------------------- 
    36 #ifdef _LIB_RRLIB_XML2_WRAPPER_PRESENT_ 
    37 #include <iostream> 
    38 #include "rrlib/xml2_wrapper/tXMLDocument.h" 
    39 #endif 
    40  
     36#include <cstdlib> 
    4137#include <algorithm> 
    4238#include <cstring> 
    4339#include <sstream> 
    4440 
    45 #include <iostream> 
     41#ifdef _LIB_RRLIB_XML2_WRAPPER_PRESENT_ 
     42#include "rrlib/xml2_wrapper/tXMLDocument.h" 
     43#endif 
    4644 
    4745//---------------------------------------------------------------------- 
     
    5654// Namespace usage 
    5755//---------------------------------------------------------------------- 
    58 #ifdef _LIB_RRLIB_XML2_WRAPPER_PRESENT_ 
    59 using namespace rrlib::xml2; 
    60 #endif 
    6156 
    6257//---------------------------------------------------------------------- 
     
    8984    pad_multi_line_messages(true) 
    9085{ 
    91   // Create a string literal from the value of RRLIB_LOG_PATH and let p point to its beginning 
    92 #define __RRLIB_LOG_QUOTE_MACRO__(x) #x 
    93 #define __RRLIB_LOG_MAKE_STRING__(macro) __RRLIB_LOG_QUOTE_MACRO__(macro) 
    94   const char *p = __RRLIB_LOG_MAKE_STRING__(RRLIB_LOG_PATH); 
    95 #undef __RRLIB_LOG_MAKE_STRING__ 
    96 #undef __RRLIB_LOG_QUOTE_MACRO__ 
    97  
    98   // Fill a list of pointers to the components of our immutable RRLIB_LOG_PATH literal (no zero termination) 
    99   this->prefix_pointers.push_back(p); 
    100   while (*p) 
    101   { 
    102     if (*p == ':') 
    103     { 
    104       this->prefix_pointers.push_back(p + 1); 
    105     } 
    106     ++p; 
    107   } 
    108   this->prefix_pointers.push_back(p + 1); 
    109  
    110   // From the list of pointer calculate the component sizes and a lookup table for sorted access (longest-first) 
    111   for (size_t i = 0; i < this->prefix_pointers.size() - 1; ++i) 
    112   { 
    113     this->prefix_lengths.push_back(this->prefix_pointers[i + 1] - this->prefix_pointers[i] - 1); 
    114     this->prefix_indices_sorted_by_length.push_back(i); 
    115   } 
    116   std::sort(this->prefix_indices_sorted_by_length.begin(), this->prefix_indices_sorted_by_length.end(), 
    117             [this](size_t a, size_t b) 
    118   { 
    119     return this->prefix_lengths[a] > this->prefix_lengths[b]; 
     86  // Look at the environment variable RRLIB_LOGGING_PATH or a default value and let p point to its beginning 
     87  const char *rrlib_logging_path = std::getenv("RRLIB_LOGGING_PATH"); 
     88  if (rrlib_logging_path == NULL) 
     89  { 
     90    rrlib_logging_path = "/usr/include"; 
     91  } 
     92 
     93  // Fill a list of pointers to the components of our immutable rrlib_logging_path (no zero termination) 
     94  const char *begin_entry = rrlib_logging_path; 
     95  const char *end_entry = std::strchr(begin_entry, ':'); 
     96  while (end_entry) 
     97  { 
     98    this->rrlib_logging_path_entries.push_back(std::string(begin_entry, end_entry - begin_entry)); 
     99    begin_entry = end_entry + 1; 
     100    end_entry = std::strchr(begin_entry, ':'); 
     101  } 
     102  this->rrlib_logging_path_entries.push_back(begin_entry); 
     103 
     104  // For efficient best-fit lookup sort entries by length (longest-first) 
     105  std::sort(this->rrlib_logging_path_entries.begin(), this->rrlib_logging_path_entries.end(), 
     106            [](const std::string &a, const std::string &b) 
     107  { 
     108    return a.length() > b.length(); 
    120109  }); 
    121  
    122 //  for (auto it = this->prefix_indices_sorted_by_length.begin(); it != this->prefix_indices_sorted_by_length.end(); ++it) 
    123 //  { 
    124 //    std::cout << *it << " -> " << this->prefix_lengths[*it] << std::endl; 
    125 //  } 
    126110} 
    127111 
     
    189173 
    190174  // Iterate over sorted list of RRLIB_LOG_PATH components 
    191   for (auto it = this->prefix_indices_sorted_by_length.begin(); it != this->prefix_indices_sorted_by_length.end(); ++it) 
    192   { 
    193     const size_t length = this->prefix_lengths[*it]; 
     175  for (auto it = this->rrlib_logging_path_entries.begin(); it != this->rrlib_logging_path_entries.end(); ++it) 
     176  { 
     177    const size_t length = it->length(); 
    194178 
    195179    // Skip if prefix length does not fit to path structure 
     
    200184 
    201185    // Due to the longest-first sorted list the first match terminates our search 
    202     if (length > 0 && std::strncmp(filename, this->prefix_pointers[*it], length) == 0) 
     186    if (std::strncmp(filename, it->c_str(), length) == 0) 
    203187    { 
    204188      filename = filename + length + 1; 
     
    208192  } 
    209193 
    210   if (!found_prefix && this->prefix_lengths[this->prefix_indices_sorted_by_length.back()] > 0) 
     194  if (!found_prefix && !this->rrlib_logging_path_entries.back().empty()) 
    211195  { 
    212196    std::stringstream message; 
  • configuration/tDomainRegistry.h

    r74 r75  
    4343#ifndef __rrlib__logging__include_guard__ 
    4444#error Invalid include directive. Try #include "rrlib/logging/configuration.h" instead. 
    45 #endif 
    46  
    47 #ifndef RRLIB_LOG_PATH 
    48 #warning RRLIB_LOG_PATH not set. Using default path "/usr/include:/usr/include/finroc" which most likely is not sufficient for your setup. 
    49 #define RRLIB_LOG_PATH /usr/include:/usr/include/finroc 
    5045#endif 
    5146 
     
    222217private: 
    223218 
    224   std::vector<const char *> prefix_pointers; 
    225   std::vector<size_t> prefix_lengths; 
    226   std::vector<size_t> prefix_indices_sorted_by_length; 
     219  std::vector<std::string> rrlib_logging_path_entries; 
    227220 
    228221  mutable tConfiguration *global_configuration; 
Note: See TracChangeset for help on using the changeset viewer.