| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
#include <vjConfig.h> |
|---|
| 35 |
|
|---|
| 36 |
#include <Kernel/vjDebug.h> |
|---|
| 37 |
|
|---|
| 38 |
#include <Sync/vjMutex.h> |
|---|
| 39 |
#include <Kernel/vjStreamLock.h> |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
vjSingletonImp(vjDebug); |
|---|
| 47 |
|
|---|
| 48 |
#include <vjConfig.h> |
|---|
| 49 |
#include <stdlib.h> |
|---|
| 50 |
|
|---|
| 51 |
#include <Sync/vjMutex.h> |
|---|
| 52 |
#include <Threads/vjThread.h> |
|---|
| 53 |
#include <Kernel/vjStreamLock.h> |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
vjDebug::vjDebug() |
|---|
| 58 |
{ |
|---|
| 59 |
indentLevel = 0; |
|---|
| 60 |
debugLevel = 1; |
|---|
| 61 |
|
|---|
| 62 |
char* debug_lev = getenv("VJ_DEBUG_NFY_LEVEL"); |
|---|
| 63 |
if(debug_lev != NULL) |
|---|
| 64 |
{ |
|---|
| 65 |
debugLevel = atoi(debug_lev); |
|---|
| 66 |
std::cout << "VJ_DEBUG_NFY_LEVEL: Set to " << debugLevel << std::endl |
|---|
| 67 |
<< std::flush; |
|---|
| 68 |
} else { |
|---|
| 69 |
std::cout << "VJ_DEBUG_NFY_LEVEL: Not found. " << std::endl << std::flush; |
|---|
| 70 |
std::cout << "VJ_DEBUG_NFY_LEVEL: Defaults to " << debugLevel |
|---|
| 71 |
<< std::endl << std::flush; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
setDefaultCategoryNames(); |
|---|
| 75 |
getAllowedCatsFromEnv(); |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
std::ostream& vjDebug::getStream(int cat, int level, bool show_thread_info, |
|---|
| 79 |
bool use_indent, int indentChange, bool lockStream) |
|---|
| 80 |
{ |
|---|
| 81 |
if(indentChange < 0) |
|---|
| 82 |
indentLevel += indentChange; |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
#ifdef LOCK_DEBUG_STREAM |
|---|
| 88 |
if(lockStream) |
|---|
| 89 |
{ |
|---|
| 90 |
debugLock().acquire(); |
|---|
| 91 |
} |
|---|
| 92 |
#endif |
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
if(show_thread_info) |
|---|
| 105 |
std::cout << "[" << vjThread::self() << "] VJ: "; |
|---|
| 106 |
else if(use_indent) |
|---|
| 107 |
std::cout << " "; |
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
if(use_indent) |
|---|
| 112 |
{ |
|---|
| 113 |
for(int i=0;i<indentLevel;i++) |
|---|
| 114 |
std::cout << "\t"; |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
if(indentChange > 0) |
|---|
| 118 |
indentLevel += indentChange; |
|---|
| 119 |
|
|---|
| 120 |
return std::cout; |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
void vjDebug::addCategoryName(std::string name, int cat) |
|---|
| 124 |
{ |
|---|
| 125 |
mCategoryNames[name] = cat; |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
void vjDebug::addAllowedCategory(int cat) |
|---|
| 129 |
{ |
|---|
| 130 |
if((int)mAllowedCategories.size() < (cat+1)) |
|---|
| 131 |
growAllowedCategoryVector(cat+1); |
|---|
| 132 |
|
|---|
| 133 |
mAllowedCategories[cat] = true; |
|---|
| 134 |
} |
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
bool vjDebug::isCategoryAllowed(int cat) |
|---|
| 138 |
{ |
|---|
| 139 |
|
|---|
| 140 |
if((int)mAllowedCategories.size() < (cat+1)) |
|---|
| 141 |
growAllowedCategoryVector(cat+1); |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
if((mAllowedCategories[vjDBG_ALL]) || (cat == vjDBG_ALL)) |
|---|
| 146 |
return true; |
|---|
| 147 |
else |
|---|
| 148 |
return mAllowedCategories[cat]; |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
void vjDebug::setDefaultCategoryNames() |
|---|
| 152 |
{ |
|---|
| 153 |
|
|---|
| 154 |
addCategoryName(vjDBG_ALLstr,vjDBG_ALL); |
|---|
| 155 |
addCategoryName(vjDBG_ERRORstr,vjDBG_ERROR); |
|---|
| 156 |
addCategoryName(vjDBG_KERNELstr,vjDBG_KERNEL); |
|---|
| 157 |
addCategoryName(vjDBG_INPUT_MGRstr,vjDBG_INPUT_MGR); |
|---|
| 158 |
addCategoryName(vjDBG_DRAW_MGRstr,vjDBG_DRAW_MGR); |
|---|
| 159 |
addCategoryName(vjDBG_DISP_MGRstr,vjDBG_DISP_MGR); |
|---|
| 160 |
addCategoryName(vjDBG_ENV_MGRstr, vjDBG_ENV_MGR); |
|---|
| 161 |
addCategoryName(vjDBG_PERFORMANCEstr, vjDBG_PERFORMANCE); |
|---|
| 162 |
addCategoryName(vjDBG_CONFIGstr, vjDBG_CONFIG); |
|---|
| 163 |
|
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
void vjDebug::getAllowedCatsFromEnv() |
|---|
| 167 |
{ |
|---|
| 168 |
|
|---|
| 169 |
char* dbg_cats_env = getenv("VJ_DEBUG_CATEGORIES"); |
|---|
| 170 |
|
|---|
| 171 |
if(dbg_cats_env != NULL) |
|---|
| 172 |
{ |
|---|
| 173 |
std::cout << "vjDEBUG::Found VJ_DEBUG_CATEGORIES: Listing allowed categories. (If blank, then none allowed.\n" << std::flush; |
|---|
| 174 |
std::string dbg_cats(dbg_cats_env); |
|---|
| 175 |
|
|---|
| 176 |
std::map< std::string, int >::iterator i; |
|---|
| 177 |
for(i=mCategoryNames.begin();i != mCategoryNames.end();i++) |
|---|
| 178 |
{ |
|---|
| 179 |
std::string cat_name = (*i).first; |
|---|
| 180 |
if (dbg_cats.find(cat_name) != std::string::npos ) |
|---|
| 181 |
{ |
|---|
| 182 |
std::cout << "vjDEBUG::getAllowedCatsFromEnv: Allowing: " |
|---|
| 183 |
<< (*i).first.c_str() << " val:" << (*i).second |
|---|
| 184 |
<< std::endl << std::flush; |
|---|
| 185 |
addAllowedCategory((*i).second); |
|---|
| 186 |
} |
|---|
| 187 |
} |
|---|
| 188 |
} |
|---|
| 189 |
else |
|---|
| 190 |
{ |
|---|
| 191 |
std::cout << "vjDEBUG::VJ_DEBUG_CATEGORIES not found:\n" |
|---|
| 192 |
<< " Setting to: vjDBG_ALL!" << std::endl << std::flush; |
|---|
| 193 |
addAllowedCategory(vjDBG_ALL); |
|---|
| 194 |
} |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
} |
|---|
| 198 |
|
|---|
| 199 |
void vjDebug::growAllowedCategoryVector(int newSize) |
|---|
| 200 |
{ |
|---|
| 201 |
while((int)mAllowedCategories.size() < newSize) |
|---|
| 202 |
mAllowedCategories.push_back(false); |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|