1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: dbg_Logger.h 4 5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Rev: 46347 $ 14 *---------------------------------------------------------------------------*/ 15 16 /* Please see man pages for details 17 18 19 20 */ 21 22 #ifndef NN_DBG_DBG_LOGGER_H_ 23 #define NN_DBG_DBG_LOGGER_H_ 24 25 #ifdef __cplusplus 26 27 #include <nn/types.h> 28 #include <nn/dbg/dbg_DebugString.h> 29 #include <nn/config.h> 30 31 #define NN_LOG_LEVEL_DEBUG 0 32 #define NN_LOG_LEVEL_INFO 1 33 #define NN_LOG_LEVEL_WARN 2 34 #define NN_LOG_LEVEL_ERROR 3 35 #define NN_LOG_LEVEL_FATAL 4 36 #define NN_LOG_LEVEL_FORCE 5 37 #define NN_LOG_LEVEL_DISABLE 6 38 39 #define NN_LOG_LEVEL_DEFAULT NN_LOG_LEVEL_WARN 40 41 #ifndef NN_LOG_LEVEL 42 #define NN_LOG_LEVEL NN_LOG_LEVEL_DEFAULT 43 #endif 44 45 #ifdef NN_SWITCH_DISABLE_DEBUG_PRINT 46 #undef NN_LOG_LEVEL 47 #define NN_LOG_LEVEL NN_LOG_LEVEL_DISABLE 48 #endif 49 50 #if NN_LOG_LEVEL <= NN_LOG_LEVEL_DEBUG 51 #define NN_LOG_DEBUG_ENABLE 52 #endif 53 54 #if NN_LOG_LEVEL <= NN_LOG_LEVEL_INFO 55 #define NN_LOG_INFO_ENABLE 56 #endif 57 58 #if NN_LOG_LEVEL <= NN_LOG_LEVEL_WARN 59 #define NN_LOG_WARN_ENABLE 60 #endif 61 62 #if NN_LOG_LEVEL <= NN_LOG_LEVEL_ERROR 63 #define NN_LOG_ERROR_ENABLE 64 #endif 65 66 #if NN_LOG_LEVEL <= NN_LOG_LEVEL_FATAL 67 #define NN_LOG_FATAL_ENABLE 68 #endif 69 70 #ifndef NN_LOG_BASE 71 #define NN_LOG_BASE(level, ...) \ 72 ::nn::dbg::detail::Logger::PrintLog(::nn::dbg::detail::Logger::LEVEL_ ## level, \ 73 NN_FUNCTION, NN_FILE_NAME, __LINE__, __VA_ARGS__) 74 #endif 75 76 /* 77 78 79 80 81 82 */ 83 #define NN_LOG_NAMESPACE(x) ::nn::dbg::detail::Logger::SetNameSpace(x) 84 85 /* 86 87 88 89 90 91 */ 92 #define NN_LOG_SIGNATURE(x) ::nn::dbg::detail::Logger::SetSignature(x) 93 94 /* 95 96 97 98 99 100 */ 101 #define NN_LOG_LONGPATH(x) ::nn::dbg::detail::Logger::SetLongpath(x) 102 103 #define NN_LOG_SET_UPPER_LOG_LEVEL(x) ::nn::dbg::detail::Logger::SetUpperLevel(x) 104 #define NN_LOG_SET_LOWER_LOG_LEVEL(x) ::nn::dbg::detail::Logger::SetLowerLevel(x) 105 #define NN_LOG_SET_LOG_LEVEL(x) NN_LOG_SET_LOWER_LOG_LEVEL(x) 106 107 /* 108 109 110 111 */ 112 #ifdef NN_LOG_DEBUG_ENABLE 113 #define NN_LOG_DEBUG(...) NN_LOG_BASE(DEBUG, __VA_ARGS__) 114 #else 115 #define NN_LOG_DEBUG(...) ((void)0) 116 #endif 117 118 /* 119 120 121 122 */ 123 #ifdef NN_LOG_INFO_ENABLE 124 #define NN_LOG_INFO(...) NN_LOG_BASE(INFO, __VA_ARGS__) 125 #else 126 #define NN_LOG_INFO(...) ((void)0) 127 #endif 128 129 /* 130 131 132 133 */ 134 #ifdef NN_LOG_WARN_ENABLE 135 #define NN_LOG_WARN(...) NN_LOG_BASE(WARN, __VA_ARGS__) 136 #else 137 #define NN_LOG_WARN(...) ((void)0) 138 #endif 139 140 /* 141 142 143 144 */ 145 #ifdef NN_LOG_ERROR_ENABLE 146 #define NN_LOG_ERROR(...) NN_LOG_BASE(ERROR, __VA_ARGS__) 147 #else 148 #define NN_LOG_ERROR(...) ((void)0) 149 #endif 150 151 /* 152 153 154 155 */ 156 #ifdef NN_LOG_FATAL_ENABLE 157 #define NN_LOG_FATAL(...) NN_LOG_BASE(FATAL, __VA_ARGS__) 158 #else 159 #define NN_LOG_FATAL(...) ((void)0) 160 #endif 161 162 /* 163 164 165 166 */ 167 #ifndef NN_SWITCH_DISABLE_DEBUG_PRINT 168 #define NN_LOG_FORCE(...) NN_LOG_BASE(FORCE, __VA_ARGS__) 169 #else 170 #define NN_LOG_FORCE(...) ((void)0) 171 #endif 172 173 namespace nn { namespace dbg { namespace detail { 174 175 class Logger 176 { 177 private: 178 static u32 s_UpperLevel; // 179 static u32 s_LowerLevel; // 180 static u8 s_ShowFlag; // 181 static bool s_Initialized; // 182 static const u8 ENABLE_NAMESPACE = 1; // 183 static const u8 ENABLE_SIGNATURE = 2; // 184 static const u8 ENABLE_LONGPATH = 4; // 185 #ifdef NN_SYSTEM_KERNEL 186 static const u32 BUF_SIZE = NN_DBG_TPRINTF_BUFFER_LENGTH; 187 #else 188 static const u32 BUF_SIZE = NN_DBG_PRINTF_BUFFER_LENGTH; 189 #endif 190 191 public: 192 static const u32 LEVEL_DEBUG = NN_LOG_LEVEL_DEBUG; // 193 static const u32 LEVEL_INFO = NN_LOG_LEVEL_INFO; // 194 static const u32 LEVEL_WARN = NN_LOG_LEVEL_WARN; // 195 static const u32 LEVEL_ERROR = NN_LOG_LEVEL_ERROR; // 196 static const u32 LEVEL_FATAL = NN_LOG_LEVEL_FATAL; // 197 static const u32 LEVEL_FORCE = NN_LOG_LEVEL_FORCE; // 198 199 /* 200 201 202 203 204 205 206 207 */ 208 static void PrintLog(const u32 level, const char8* funcName, const char8* fileName, 209 const int line, const char8* fmt, ...); 210 211 /* 212 213 214 215 216 217 218 219 220 221 */ 222 static size_t MakeFuncName(const char8* src, char8* dest, size_t length); 223 224 /* 225 226 227 228 */ SetUpperLevel(u32 level)229 static void SetUpperLevel(u32 level) { s_UpperLevel = level; s_Initialized = true; } 230 231 /* 232 233 234 235 */ SetLowerLevel(u32 level)236 static void SetLowerLevel(u32 level) { s_LowerLevel = level; s_Initialized = true; } 237 238 /* 239 240 241 242 */ SetLevel(u32 level)243 static void SetLevel(u32 level) { SetLowerLevel(level); } 244 245 /* 246 247 248 249 250 251 252 253 */ SetFlag(u8 type,bool value)254 static void SetFlag(u8 type, bool value) 255 { 256 if(value) 257 { 258 s_ShowFlag |= type; 259 } 260 else 261 { 262 s_ShowFlag &= (0xff ^ type); 263 } 264 } 265 266 /* 267 268 269 270 */ SetNameSpace(bool f)271 static void SetNameSpace(bool f) { SetFlag(ENABLE_NAMESPACE, f); } 272 273 /* 274 275 276 277 */ SetSignature(bool f)278 static void SetSignature(bool f) { SetFlag(ENABLE_SIGNATURE, f); } 279 280 /* 281 282 283 284 */ SetLongpath(bool f)285 static void SetLongpath(bool f) { SetFlag(ENABLE_LONGPATH , f); } 286 287 288 static char8* s_LevelStrings[]; // 289 }; 290 291 }}} 292 293 294 #endif // __cplusplus 295 296 #endif 297