| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Level.cc

Go to the documentation of this file.
00001 #include "Level.hh"
00002 #include <map>
00003 #include <vector>
00004 #include <iostream>
00005 #include <cstring>
00006 #include <cstdio>
00010 
00011 using namespace Logging;
00012 using std::string;
00013 using std::map;
00014 
00015 
00016 typedef std::vector< std::pair<Level,string> > SynonymTable_t;
00017 
00018 SynonymTable_t& GetSynonymTable()
00019 {
00020   static SynonymTable_t sTable;
00021   static bool first = true;
00022   if(first) {
00023     first = false;
00024 
00025     // Names with a 'k'
00026     sTable.push_back(std::pair<Level,string>(kVerbose   ,"kVerbose"));
00027     sTable.push_back(std::pair<Level,string>(kDebug3    ,"kDebug3"));
00028     sTable.push_back(std::pair<Level,string>(kDebug2    ,"kDebug2"));
00029     sTable.push_back(std::pair<Level,string>(kDebug1    ,"kDebug1"));
00030     sTable.push_back(std::pair<Level,string>(kMonitor   ,"kMonitor"));
00031     sTable.push_back(std::pair<Level,string>(kInfo      ,"kInfo"));
00032     sTable.push_back(std::pair<Level,string>(kWarning   ,"kWarning"));
00033     sTable.push_back(std::pair<Level,string>(kError     ,"kError"));
00034     sTable.push_back(std::pair<Level,string>(kFatal     ,"kFatal"));
00035     sTable.push_back(std::pair<Level,string>(kNever     ,"kNever"));
00036     sTable.push_back(std::pair<Level,string>(kDefault   ,"kDefault"));
00037     sTable.push_back(std::pair<Level,string>(kEverything,"kEverything")); 
00038     sTable.push_back(std::pair<Level,string>(kOff       ,"kOff"));
00039 
00040     // Names without a 'k;
00041     sTable.push_back(std::pair<Level,string>(kVerbose   ,"Verbose"));
00042     sTable.push_back(std::pair<Level,string>(kDebug3    ,"Debug3"));
00043     sTable.push_back(std::pair<Level,string>(kDebug2    ,"Debug2"));
00044     sTable.push_back(std::pair<Level,string>(kDebug1    ,"Debug1"));
00045     sTable.push_back(std::pair<Level,string>(kMonitor   ,"Monitor"));
00046     sTable.push_back(std::pair<Level,string>(kInfo      ,"Info"));
00047     sTable.push_back(std::pair<Level,string>(kWarning   ,"Warning"));
00048     sTable.push_back(std::pair<Level,string>(kError     ,"Error"));
00049     sTable.push_back(std::pair<Level,string>(kFatal     ,"Fatal"));
00050     sTable.push_back(std::pair<Level,string>(kNever     ,"Never"));
00051     sTable.push_back(std::pair<Level,string>(kDefault   ,"Default"));
00052     sTable.push_back(std::pair<Level,string>(kEverything,"Everything")); 
00053     sTable.push_back(std::pair<Level,string>(kOff       ,"Off"));
00054 
00055     // Short names
00056     sTable.push_back(std::pair<Level,string>(kVerbose   ,"verb"));
00057     sTable.push_back(std::pair<Level,string>(kDebug1    ,"debug"));
00058     sTable.push_back(std::pair<Level,string>(kMonitor   ,"mon"));
00059     sTable.push_back(std::pair<Level,string>(kInfo      ,"info"));
00060     sTable.push_back(std::pair<Level,string>(kWarning   ,"warn"));
00061     sTable.push_back(std::pair<Level,string>(kError     ,"err"));
00062     sTable.push_back(std::pair<Level,string>(kFatal     ,"fat"));
00063     sTable.push_back(std::pair<Level,string>(kDefault   ,"def"));
00064     sTable.push_back(std::pair<Level,string>(kDefault   ,"on"));
00065 
00066     // single letters
00067     sTable.push_back(std::pair<Level,string>(kVerbose   ,"V"));
00068     sTable.push_back(std::pair<Level,string>(kDebug1    ,"D"));
00069     sTable.push_back(std::pair<Level,string>(kMonitor   ,"M"));
00070     sTable.push_back(std::pair<Level,string>(kInfo      ,"I"));
00071     sTable.push_back(std::pair<Level,string>(kWarning   ,"W"));
00072     sTable.push_back(std::pair<Level,string>(kError     ,"E"));
00073     sTable.push_back(std::pair<Level,string>(kFatal     ,"F"));
00074   }
00075   return sTable;
00076 }
00077 
00078 
00079 string Logging::LevelToString(Level lvl)
00080 {
00081   // Get the table.
00082   SynonymTable_t& sTable = GetSynonymTable();
00083 
00084   // Look for the first direct match.
00085   for(int i=0;i<sTable.size();i++) {
00086     if(lvl == sTable[i].first) return sTable[i].second;
00087   }
00088 
00089   // Hmmm, no direct matches.  Return the raw number.
00090   char temp[10];
00091   sprintf(temp,"%d",lvl);
00092   return string(temp);
00093 }
00094 
00095 Level Logging::StringToLevel(string str)
00096 {
00097   // Get the table.
00098   SynonymTable_t& sTable = GetSynonymTable();
00099 
00100   // Look for the first direct match.
00101   for(int i=0;i<sTable.size();i++){
00102     const char* strc = str.c_str();
00103     if(strncasecmp(strc,sTable[i].second.c_str(),sTable[i].second.length()) == 0) {
00104       // We have an exact match!
00105       return sTable[i].first;
00106     }
00107   }
00108   
00109   // Try to interpret it as a numeric.
00110   int lvl;
00111   int res = sscanf(str.c_str(),"%d",&lvl);
00112   if(res>0) return (Level)lvl;
00113   
00114   // Can't find anything. return null value..
00115   return kInvalid;
00116 }
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:06:22 2011 for Log by doxygen 1.4.7