| 1 | /* |
|---|
| 2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include "Common.h" |
|---|
| 22 | #include "Log.h" |
|---|
| 23 | #include "Policies/SingletonImp.h" |
|---|
| 24 | #include "Config/ConfigEnv.h" |
|---|
| 25 | #include "Util.h" |
|---|
| 26 | |
|---|
| 27 | #include <stdarg.h> |
|---|
| 28 | |
|---|
| 29 | INSTANTIATE_SINGLETON_1( Log ); |
|---|
| 30 | |
|---|
| 31 | enum LogType |
|---|
| 32 | { |
|---|
| 33 | LogNormal = 0, |
|---|
| 34 | LogDetails, |
|---|
| 35 | LogDebug, |
|---|
| 36 | LogError |
|---|
| 37 | }; |
|---|
| 38 | |
|---|
| 39 | const int LogType_count = int(LogError) +1; |
|---|
| 40 | |
|---|
| 41 | void Log::InitColors(std::string str) |
|---|
| 42 | { |
|---|
| 43 | if(str.empty()) |
|---|
| 44 | { |
|---|
| 45 | m_colored = false; |
|---|
| 46 | return; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | int color[4]; |
|---|
| 50 | |
|---|
| 51 | std::istringstream ss(str); |
|---|
| 52 | |
|---|
| 53 | for(int i = 0; i < LogType_count; ++i) |
|---|
| 54 | { |
|---|
| 55 | ss >> color[i]; |
|---|
| 56 | |
|---|
| 57 | if(!ss) |
|---|
| 58 | return; |
|---|
| 59 | |
|---|
| 60 | if(color[i] < 0 || color[i] >= Color_count) |
|---|
| 61 | return; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | for(int i = 0; i < LogType_count; ++i) |
|---|
| 65 | m_colors[i] = Color(color[i]); |
|---|
| 66 | |
|---|
| 67 | m_colored = true; |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | void Log::SetColor(bool stdout_stream, Color color) |
|---|
| 71 | { |
|---|
| 72 | #if PLATFORM == PLATFORM_WINDOWS |
|---|
| 73 | |
|---|
| 74 | static WORD WinColorFG[Color_count] = |
|---|
| 75 | { |
|---|
| 76 | 0, // BLACK |
|---|
| 77 | FOREGROUND_RED, // RED |
|---|
| 78 | FOREGROUND_GREEN, // GREEN |
|---|
| 79 | FOREGROUND_RED | FOREGROUND_GREEN, // BROWN |
|---|
| 80 | FOREGROUND_BLUE, // BLUE |
|---|
| 81 | FOREGROUND_RED | FOREGROUND_BLUE,// MAGENTA |
|---|
| 82 | FOREGROUND_GREEN | FOREGROUND_BLUE, // CYAN |
|---|
| 83 | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,// WHITE |
|---|
| 84 | // YELLOW |
|---|
| 85 | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY, |
|---|
| 86 | // RED_BOLD |
|---|
| 87 | FOREGROUND_RED | FOREGROUND_INTENSITY, |
|---|
| 88 | // GREEN_BOLD |
|---|
| 89 | FOREGROUND_GREEN | FOREGROUND_INTENSITY, |
|---|
| 90 | FOREGROUND_BLUE | FOREGROUND_INTENSITY, // BLUE_BOLD |
|---|
| 91 | // MAGENTA_BOLD |
|---|
| 92 | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY, |
|---|
| 93 | // CYAN_BOLD |
|---|
| 94 | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY, |
|---|
| 95 | // WHITE_BOLD |
|---|
| 96 | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY |
|---|
| 97 | }; |
|---|
| 98 | |
|---|
| 99 | HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE ); |
|---|
| 100 | SetConsoleTextAttribute(hConsole, WinColorFG[color]); |
|---|
| 101 | #else |
|---|
| 102 | |
|---|
| 103 | enum ANSITextAttr |
|---|
| 104 | { |
|---|
| 105 | TA_NORMAL=0, |
|---|
| 106 | TA_BOLD=1, |
|---|
| 107 | TA_BLINK=5, |
|---|
| 108 | TA_REVERSE=7 |
|---|
| 109 | }; |
|---|
| 110 | |
|---|
| 111 | enum ANSIFgTextAttr |
|---|
| 112 | { |
|---|
| 113 | FG_BLACK=30, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE, |
|---|
| 114 | FG_MAGENTA, FG_CYAN, FG_WHITE, FG_YELLOW |
|---|
| 115 | }; |
|---|
| 116 | |
|---|
| 117 | enum ANSIBgTextAttr |
|---|
| 118 | { |
|---|
| 119 | BG_BLACK=40, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE, |
|---|
| 120 | BG_MAGENTA, BG_CYAN, BG_WHITE |
|---|
| 121 | }; |
|---|
| 122 | |
|---|
| 123 | static uint8 UnixColorFG[Color_count] = |
|---|
| 124 | { |
|---|
| 125 | FG_BLACK, // BLACK |
|---|
| 126 | FG_RED, // RED |
|---|
| 127 | FG_GREEN, // GREEN |
|---|
| 128 | FG_BROWN, // BROWN |
|---|
| 129 | FG_BLUE, // BLUE |
|---|
| 130 | FG_MAGENTA, // MAGENTA |
|---|
| 131 | FG_CYAN, // CYAN |
|---|
| 132 | FG_WHITE, // WHITE |
|---|
| 133 | FG_YELLOW, // YELLOW |
|---|
| 134 | FG_RED, // LRED |
|---|
| 135 | FG_GREEN, // LGREEN |
|---|
| 136 | FG_BLUE, // LBLUE |
|---|
| 137 | FG_MAGENTA, // LMAGENTA |
|---|
| 138 | FG_CYAN, // LCYAN |
|---|
| 139 | FG_WHITE // LWHITE |
|---|
| 140 | }; |
|---|
| 141 | |
|---|
| 142 | fprintf((stdout_stream? stdout : stderr), "\x1b[%d%sm",UnixColorFG[color],(color>=YELLOW&&color<Color_count ?";1":"")); |
|---|
| 143 | #endif |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | void Log::ResetColor(bool stdout_stream) |
|---|
| 147 | { |
|---|
| 148 | #if PLATFORM == PLATFORM_WINDOWS |
|---|
| 149 | HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE ); |
|---|
| 150 | SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED ); |
|---|
| 151 | #else |
|---|
| 152 | fprintf(( stdout_stream ? stdout : stderr ), "\x1b[0m"); |
|---|
| 153 | #endif |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | void Log::SetLogLevel(char *Level) |
|---|
| 157 | { |
|---|
| 158 | int32 NewLevel =atoi((char*)Level); |
|---|
| 159 | if ( NewLevel <0 ) |
|---|
| 160 | NewLevel = 0; |
|---|
| 161 | m_logLevel = NewLevel; |
|---|
| 162 | |
|---|
| 163 | printf( "LogLevel is %u\n",m_logLevel ); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | void Log::SetLogFileLevel(char *Level) |
|---|
| 167 | { |
|---|
| 168 | int32 NewLevel =atoi((char*)Level); |
|---|
| 169 | if ( NewLevel <0 ) |
|---|
| 170 | NewLevel = 0; |
|---|
| 171 | m_logFileLevel = NewLevel; |
|---|
| 172 | |
|---|
| 173 | printf( "LogFileLevel is %u\n",m_logFileLevel ); |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | void Log::Initialize() |
|---|
| 177 | { |
|---|
| 178 | std::string logsDir = sConfig.GetStringDefault("LogsDir",""); |
|---|
| 179 | |
|---|
| 180 | if(!logsDir.empty()) |
|---|
| 181 | { |
|---|
| 182 | if((logsDir.at(logsDir.length()-1)!='/') && (logsDir.at(logsDir.length()-1)!='\\')) |
|---|
| 183 | logsDir.append("/"); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | std::string logfn=sConfig.GetStringDefault("LogFile", ""); |
|---|
| 187 | if(!logfn.empty()) |
|---|
| 188 | { |
|---|
| 189 | if(sConfig.GetBoolDefault("LogTimestamp",false)) |
|---|
| 190 | { |
|---|
| 191 | std::string logTimestamp = GetTimestampStr(); |
|---|
| 192 | logTimestamp.insert(0,"_"); |
|---|
| 193 | size_t dot_pos = logfn.find_last_of("."); |
|---|
| 194 | if(dot_pos!=logfn.npos) |
|---|
| 195 | logfn.insert(dot_pos,logTimestamp); |
|---|
| 196 | else |
|---|
| 197 | logfn += logTimestamp; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | logfile = fopen((logsDir+logfn).c_str(), "w"); |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | std::string gmlogname = sConfig.GetStringDefault("GMLogFile", ""); |
|---|
| 204 | if(!gmlogname.empty()) |
|---|
| 205 | { |
|---|
| 206 | if(sConfig.GetBoolDefault("GmLogTimestamp",false)) |
|---|
| 207 | { |
|---|
| 208 | std::string gmLogTimestamp = GetTimestampStr(); |
|---|
| 209 | gmLogTimestamp.insert(0,"_"); |
|---|
| 210 | size_t dot_pos = gmlogname.find_last_of("."); |
|---|
| 211 | if(dot_pos!=gmlogname.npos) |
|---|
| 212 | gmlogname.insert(dot_pos,gmLogTimestamp); |
|---|
| 213 | else |
|---|
| 214 | gmlogname += gmLogTimestamp; |
|---|
| 215 | } |
|---|
| 216 | gmLogfile = fopen((logsDir+gmlogname).c_str(), "a"); |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | std::string charlogname = sConfig.GetStringDefault("CharLogFile", ""); |
|---|
| 220 | if(!charlogname.empty()) |
|---|
| 221 | { |
|---|
| 222 | if(sConfig.GetBoolDefault("CharLogTimestamp",false)) |
|---|
| 223 | { |
|---|
| 224 | std::string charLogTimestamp = GetTimestampStr(); |
|---|
| 225 | charLogTimestamp.insert(0,"_"); |
|---|
| 226 | size_t dot_pos = charlogname.find_last_of("."); |
|---|
| 227 | if(dot_pos!=charlogname.npos) |
|---|
| 228 | charlogname.insert(dot_pos,charLogTimestamp); |
|---|
| 229 | else |
|---|
| 230 | charlogname += charLogTimestamp; |
|---|
| 231 | } |
|---|
| 232 | charLogfile = fopen((logsDir+charlogname).c_str(), "a"); |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | std::string dberlogname = sConfig.GetStringDefault("DBErrorLogFile", ""); |
|---|
| 236 | if(!dberlogname.empty()) |
|---|
| 237 | { |
|---|
| 238 | dberLogfile = fopen((logsDir+dberlogname).c_str(), "a"); |
|---|
| 239 | } |
|---|
| 240 | std::string ralogname = sConfig.GetStringDefault("RaLogFile", ""); |
|---|
| 241 | if(!ralogname.empty()) |
|---|
| 242 | { |
|---|
| 243 | raLogfile = fopen((logsDir+ralogname).c_str(), "a"); |
|---|
| 244 | } |
|---|
| 245 | m_includeTime = sConfig.GetBoolDefault("LogTime", false); |
|---|
| 246 | m_logLevel = sConfig.GetIntDefault("LogLevel", 0); |
|---|
| 247 | m_logFileLevel = sConfig.GetIntDefault("LogFileLevel", 0); |
|---|
| 248 | InitColors(sConfig.GetStringDefault("LogColors", "")); |
|---|
| 249 | |
|---|
| 250 | m_logFilter = 0; |
|---|
| 251 | |
|---|
| 252 | if(sConfig.GetBoolDefault("LogFilter_TransportMoves", true)) |
|---|
| 253 | m_logFilter |= LOG_FILTER_TRANSPORT_MOVES; |
|---|
| 254 | if(sConfig.GetBoolDefault("LogFilter_CreatureMoves", true)) |
|---|
| 255 | m_logFilter |= LOG_FILTER_CREATURE_MOVES; |
|---|
| 256 | if(sConfig.GetBoolDefault("LogFilter_VisibilityChanges", true)) |
|---|
| 257 | m_logFilter |= LOG_FILTER_VISIBILITY_CHANGES; |
|---|
| 258 | |
|---|
| 259 | m_charLog_Dump = sConfig.GetBoolDefault("CharLogDump", false); |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | void Log::outTimestamp(FILE* file) |
|---|
| 263 | { |
|---|
| 264 | time_t t = time(NULL); |
|---|
| 265 | tm* aTm = localtime(&t); |
|---|
| 266 | // YYYY year |
|---|
| 267 | // MM month (2 digits 01-12) |
|---|
| 268 | // DD day (2 digits 01-31) |
|---|
| 269 | // HH hour (2 digits 00-23) |
|---|
| 270 | // MM minutes (2 digits 00-59) |
|---|
| 271 | // SS seconds (2 digits 00-59) |
|---|
| 272 | fprintf(file,"%-4d-%02d-%02d %02d:%02d:%02d ",aTm->tm_year+1900,aTm->tm_mon+1,aTm->tm_mday,aTm->tm_hour,aTm->tm_min,aTm->tm_sec); |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | void Log::outTime() |
|---|
| 276 | { |
|---|
| 277 | time_t t = time(NULL); |
|---|
| 278 | tm* aTm = localtime(&t); |
|---|
| 279 | // YYYY year |
|---|
| 280 | // MM month (2 digits 01-12) |
|---|
| 281 | // DD day (2 digits 01-31) |
|---|
| 282 | // HH hour (2 digits 00-23) |
|---|
| 283 | // MM minutes (2 digits 00-59) |
|---|
| 284 | // SS seconds (2 digits 00-59) |
|---|
| 285 | printf("%02d:%02d:%02d ",aTm->tm_hour,aTm->tm_min,aTm->tm_sec); |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | std::string Log::GetTimestampStr() |
|---|
| 289 | { |
|---|
| 290 | time_t t = time(NULL); |
|---|
| 291 | tm* aTm = localtime(&t); |
|---|
| 292 | // YYYY year |
|---|
| 293 | // MM month (2 digits 01-12) |
|---|
| 294 | // DD day (2 digits 01-31) |
|---|
| 295 | // HH hour (2 digits 00-23) |
|---|
| 296 | // MM minutes (2 digits 00-59) |
|---|
| 297 | // SS seconds (2 digits 00-59) |
|---|
| 298 | char buf[20]; |
|---|
| 299 | snprintf(buf,20,"%04d-%02d-%02d_%02d-%02d-%02d",aTm->tm_year+1900,aTm->tm_mon+1,aTm->tm_mday,aTm->tm_hour,aTm->tm_min,aTm->tm_sec); |
|---|
| 300 | return std::string(buf); |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | void Log::outTitle( const char * str) |
|---|
| 304 | { |
|---|
| 305 | if( !str ) |
|---|
| 306 | return; |
|---|
| 307 | |
|---|
| 308 | if(m_colored) |
|---|
| 309 | SetColor(true,WHITE); |
|---|
| 310 | |
|---|
| 311 | // not expected utf8 and then send as-is |
|---|
| 312 | printf( str ); |
|---|
| 313 | |
|---|
| 314 | if(m_colored) |
|---|
| 315 | ResetColor(true); |
|---|
| 316 | |
|---|
| 317 | printf( "\n" ); |
|---|
| 318 | if(logfile) |
|---|
| 319 | { |
|---|
| 320 | fprintf(logfile, str); |
|---|
| 321 | fprintf(logfile, "\n" ); |
|---|
| 322 | fflush(logfile); |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | fflush(stdout); |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | void Log::outString() |
|---|
| 329 | { |
|---|
| 330 | if(m_includeTime) |
|---|
| 331 | outTime(); |
|---|
| 332 | printf( "\n" ); |
|---|
| 333 | if(logfile) |
|---|
| 334 | { |
|---|
| 335 | outTimestamp(logfile); |
|---|
| 336 | fprintf(logfile, "\n" ); |
|---|
| 337 | fflush(logfile); |
|---|
| 338 | } |
|---|
| 339 | fflush(stdout); |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | void Log::outString( const char * str, ... ) |
|---|
| 343 | { |
|---|
| 344 | if( !str ) |
|---|
| 345 | return; |
|---|
| 346 | |
|---|
| 347 | if(m_colored) |
|---|
| 348 | SetColor(true,m_colors[LogNormal]); |
|---|
| 349 | |
|---|
| 350 | if(m_includeTime) |
|---|
| 351 | outTime(); |
|---|
| 352 | |
|---|
| 353 | UTF8PRINTF(stdout,str,); |
|---|
| 354 | |
|---|
| 355 | if(m_colored) |
|---|
| 356 | ResetColor(true); |
|---|
| 357 | |
|---|
| 358 | printf( "\n" ); |
|---|
| 359 | if(logfile) |
|---|
| 360 | { |
|---|
| 361 | outTimestamp(logfile); |
|---|
| 362 | |
|---|
| 363 | va_list ap; |
|---|
| 364 | va_start(ap, str); |
|---|
| 365 | vfprintf(logfile, str, ap); |
|---|
| 366 | fprintf(logfile, "\n" ); |
|---|
| 367 | va_end(ap); |
|---|
| 368 | |
|---|
| 369 | fflush(logfile); |
|---|
| 370 | } |
|---|
| 371 | fflush(stdout); |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | void Log::outError( const char * err, ... ) |
|---|
| 375 | { |
|---|
| 376 | if( !err ) |
|---|
| 377 | return; |
|---|
| 378 | |
|---|
| 379 | if(m_colored) |
|---|
| 380 | SetColor(false,m_colors[LogError]); |
|---|
| 381 | |
|---|
| 382 | if(m_includeTime) |
|---|
| 383 | outTime(); |
|---|
| 384 | |
|---|
| 385 | UTF8PRINTF(stderr,err,); |
|---|
| 386 | |
|---|
| 387 | if(m_colored) |
|---|
| 388 | ResetColor(false); |
|---|
| 389 | |
|---|
| 390 | fprintf( stderr, "\n" ); |
|---|
| 391 | if(logfile) |
|---|
| 392 | { |
|---|
| 393 | outTimestamp(logfile); |
|---|
| 394 | fprintf(logfile, "ERROR:" ); |
|---|
| 395 | |
|---|
| 396 | va_list ap; |
|---|
| 397 | va_start(ap, err); |
|---|
| 398 | vfprintf(logfile, err, ap); |
|---|
| 399 | va_end(ap); |
|---|
| 400 | |
|---|
| 401 | fprintf(logfile, "\n" ); |
|---|
| 402 | fflush(logfile); |
|---|
| 403 | } |
|---|
| 404 | fflush(stderr); |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | void Log::outErrorDb( const char * err, ... ) |
|---|
| 408 | { |
|---|
| 409 | if( !err ) |
|---|
| 410 | return; |
|---|
| 411 | |
|---|
| 412 | if(m_colored) |
|---|
| 413 | SetColor(false,m_colors[LogError]); |
|---|
| 414 | |
|---|
| 415 | if(m_includeTime) |
|---|
| 416 | outTime(); |
|---|
| 417 | |
|---|
| 418 | UTF8PRINTF(stderr,err,); |
|---|
| 419 | |
|---|
| 420 | if(m_colored) |
|---|
| 421 | ResetColor(false); |
|---|
| 422 | |
|---|
| 423 | fprintf( stderr, "\n" ); |
|---|
| 424 | |
|---|
| 425 | if(logfile) |
|---|
| 426 | { |
|---|
| 427 | outTimestamp(logfile); |
|---|
| 428 | fprintf(logfile, "ERROR:" ); |
|---|
| 429 | |
|---|
| 430 | va_list ap; |
|---|
| 431 | va_start(ap, err); |
|---|
| 432 | vfprintf(logfile, err, ap); |
|---|
| 433 | va_end(ap); |
|---|
| 434 | |
|---|
| 435 | fprintf(logfile, "\n" ); |
|---|
| 436 | fflush(logfile); |
|---|
| 437 | } |
|---|
| 438 | |
|---|
| 439 | if(dberLogfile) |
|---|
| 440 | { |
|---|
| 441 | outTimestamp(dberLogfile); |
|---|
| 442 | |
|---|
| 443 | va_list ap; |
|---|
| 444 | va_start(ap, err); |
|---|
| 445 | vfprintf(dberLogfile, err, ap); |
|---|
| 446 | va_end(ap); |
|---|
| 447 | |
|---|
| 448 | fprintf(dberLogfile, "\n" ); |
|---|
| 449 | fflush(dberLogfile); |
|---|
| 450 | } |
|---|
| 451 | fflush(stderr); |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | void Log::outBasic( const char * str, ... ) |
|---|
| 455 | { |
|---|
| 456 | if( !str ) |
|---|
| 457 | return; |
|---|
| 458 | |
|---|
| 459 | if( m_logLevel > 0 ) |
|---|
| 460 | { |
|---|
| 461 | if(m_colored) |
|---|
| 462 | SetColor(true,m_colors[LogDetails]); |
|---|
| 463 | |
|---|
| 464 | if(m_includeTime) |
|---|
| 465 | outTime(); |
|---|
| 466 | |
|---|
| 467 | UTF8PRINTF(stdout,str,); |
|---|
| 468 | |
|---|
| 469 | if(m_colored) |
|---|
| 470 | ResetColor(true); |
|---|
| 471 | |
|---|
| 472 | printf( "\n" ); |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | if(logfile && m_logFileLevel > 0) |
|---|
| 476 | { |
|---|
| 477 | va_list ap; |
|---|
| 478 | outTimestamp(logfile); |
|---|
| 479 | va_start(ap, str); |
|---|
| 480 | vfprintf(logfile, str, ap); |
|---|
| 481 | fprintf(logfile, "\n" ); |
|---|
| 482 | va_end(ap); |
|---|
| 483 | fflush(logfile); |
|---|
| 484 | } |
|---|
| 485 | fflush(stdout); |
|---|
| 486 | } |
|---|
| 487 | |
|---|
| 488 | void Log::outDetail( const char * str, ... ) |
|---|
| 489 | { |
|---|
| 490 | if( !str ) |
|---|
| 491 | return; |
|---|
| 492 | |
|---|
| 493 | if( m_logLevel > 1 ) |
|---|
| 494 | { |
|---|
| 495 | |
|---|
| 496 | if(m_colored) |
|---|
| 497 | SetColor(true,m_colors[LogDetails]); |
|---|
| 498 | |
|---|
| 499 | if(m_includeTime) |
|---|
| 500 | outTime(); |
|---|
| 501 | |
|---|
| 502 | UTF8PRINTF(stdout,str,); |
|---|
| 503 | |
|---|
| 504 | if(m_colored) |
|---|
| 505 | ResetColor(true); |
|---|
| 506 | |
|---|
| 507 | printf( "\n" ); |
|---|
| 508 | } |
|---|
| 509 | if(logfile && m_logFileLevel > 1) |
|---|
| 510 | { |
|---|
| 511 | va_list ap; |
|---|
| 512 | outTimestamp(logfile); |
|---|
| 513 | va_start(ap, str); |
|---|
| 514 | vfprintf(logfile, str, ap); |
|---|
| 515 | fprintf(logfile, "\n" ); |
|---|
| 516 | va_end(ap); |
|---|
| 517 | fflush(logfile); |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | fflush(stdout); |
|---|
| 521 | } |
|---|
| 522 | |
|---|
| 523 | void Log::outDebugInLine( const char * str, ... ) |
|---|
| 524 | { |
|---|
| 525 | if( !str ) |
|---|
| 526 | return; |
|---|
| 527 | if( m_logLevel > 2 ) |
|---|
| 528 | { |
|---|
| 529 | if(m_colored) |
|---|
| 530 | SetColor(true,m_colors[LogDebug]); |
|---|
| 531 | |
|---|
| 532 | UTF8PRINTF(stdout,str,); |
|---|
| 533 | |
|---|
| 534 | if(m_colored) |
|---|
| 535 | ResetColor(true); |
|---|
| 536 | } |
|---|
| 537 | if(logfile && m_logFileLevel > 2) |
|---|
| 538 | { |
|---|
| 539 | va_list ap; |
|---|
| 540 | va_start(ap, str); |
|---|
| 541 | vfprintf(logfile, str, ap); |
|---|
| 542 | va_end(ap); |
|---|
| 543 | } |
|---|
| 544 | } |
|---|
| 545 | |
|---|
| 546 | void Log::outDebug( const char * str, ... ) |
|---|
| 547 | { |
|---|
| 548 | if( !str ) |
|---|
| 549 | return; |
|---|
| 550 | if( m_logLevel > 2 ) |
|---|
| 551 | { |
|---|
| 552 | if(m_colored) |
|---|
| 553 | SetColor(true,m_colors[LogDebug]); |
|---|
| 554 | |
|---|
| 555 | if(m_includeTime) |
|---|
| 556 | outTime(); |
|---|
| 557 | |
|---|
| 558 | UTF8PRINTF(stdout,str,); |
|---|
| 559 | |
|---|
| 560 | if(m_colored) |
|---|
| 561 | ResetColor(true); |
|---|
| 562 | |
|---|
| 563 | printf( "\n" ); |
|---|
| 564 | } |
|---|
| 565 | if(logfile && m_logFileLevel > 2) |
|---|
| 566 | { |
|---|
| 567 | outTimestamp(logfile); |
|---|
| 568 | |
|---|
| 569 | va_list ap; |
|---|
| 570 | va_start(ap, str); |
|---|
| 571 | vfprintf(logfile, str, ap); |
|---|
| 572 | va_end(ap); |
|---|
| 573 | |
|---|
| 574 | fprintf(logfile, "\n" ); |
|---|
| 575 | fflush(logfile); |
|---|
| 576 | } |
|---|
| 577 | fflush(stdout); |
|---|
| 578 | } |
|---|
| 579 | |
|---|
| 580 | void Log::outCommand( const char * str, ... ) |
|---|
| 581 | { |
|---|
| 582 | if( !str ) |
|---|
| 583 | return; |
|---|
| 584 | |
|---|
| 585 | if( m_logLevel > 1 ) |
|---|
| 586 | { |
|---|
| 587 | if(m_colored) |
|---|
| 588 | SetColor(true,m_colors[LogDetails]); |
|---|
| 589 | |
|---|
| 590 | if(m_includeTime) |
|---|
| 591 | outTime(); |
|---|
| 592 | |
|---|
| 593 | UTF8PRINTF(stdout,str,); |
|---|
| 594 | |
|---|
| 595 | if(m_colored) |
|---|
| 596 | ResetColor(true); |
|---|
| 597 | |
|---|
| 598 | printf( "\n" ); |
|---|
| 599 | } |
|---|
| 600 | if(logfile && m_logFileLevel > 1) |
|---|
| 601 | { |
|---|
| 602 | va_list ap; |
|---|
| 603 | outTimestamp(logfile); |
|---|
| 604 | va_start(ap, str); |
|---|
| 605 | vfprintf(logfile, str, ap); |
|---|
| 606 | fprintf(logfile, "\n" ); |
|---|
| 607 | va_end(ap); |
|---|
| 608 | fflush(logfile); |
|---|
| 609 | } |
|---|
| 610 | if(gmLogfile) |
|---|
| 611 | { |
|---|
| 612 | va_list ap; |
|---|
| 613 | outTimestamp(gmLogfile); |
|---|
| 614 | va_start(ap, str); |
|---|
| 615 | vfprintf(gmLogfile, str, ap); |
|---|
| 616 | fprintf(gmLogfile, "\n" ); |
|---|
| 617 | va_end(ap); |
|---|
| 618 | fflush(gmLogfile); |
|---|
| 619 | } |
|---|
| 620 | fflush(stdout); |
|---|
| 621 | } |
|---|
| 622 | |
|---|
| 623 | void Log::outChar(const char * str, ... ) |
|---|
| 624 | { |
|---|
| 625 | |
|---|
| 626 | if (!str) |
|---|
| 627 | return; |
|---|
| 628 | |
|---|
| 629 | if(charLogfile) |
|---|
| 630 | { |
|---|
| 631 | va_list ap; |
|---|
| 632 | outTimestamp(charLogfile); |
|---|
| 633 | va_start(ap, str); |
|---|
| 634 | vfprintf(charLogfile, str, ap); |
|---|
| 635 | fprintf(charLogfile, "\n" ); |
|---|
| 636 | va_end(ap); |
|---|
| 637 | fflush(charLogfile); |
|---|
| 638 | } |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | void Log::outCharDump( const char * str, uint32 account_id, uint32 guid, const char * name ) |
|---|
| 642 | { |
|---|
| 643 | if(charLogfile) |
|---|
| 644 | { |
|---|
| 645 | fprintf(charLogfile, "== START DUMP == (account: %u guid: %u name: %s )\n%s\n== END DUMP ==\n",account_id,guid,name,str ); |
|---|
| 646 | fflush(charLogfile); |
|---|
| 647 | } |
|---|
| 648 | } |
|---|
| 649 | |
|---|
| 650 | void Log::outMenu( const char * str, ... ) |
|---|
| 651 | { |
|---|
| 652 | if( !str ) |
|---|
| 653 | return; |
|---|
| 654 | |
|---|
| 655 | SetColor(true,m_colors[LogNormal]); |
|---|
| 656 | |
|---|
| 657 | if(m_includeTime) |
|---|
| 658 | outTime(); |
|---|
| 659 | |
|---|
| 660 | UTF8PRINTF(stdout,str,); |
|---|
| 661 | |
|---|
| 662 | ResetColor(true); |
|---|
| 663 | |
|---|
| 664 | if(logfile) |
|---|
| 665 | { |
|---|
| 666 | outTimestamp(logfile); |
|---|
| 667 | |
|---|
| 668 | va_list ap; |
|---|
| 669 | va_start(ap, str); |
|---|
| 670 | vfprintf(logfile, str, ap); |
|---|
| 671 | va_end(ap); |
|---|
| 672 | |
|---|
| 673 | fprintf(logfile, "\n" ); |
|---|
| 674 | fflush(logfile); |
|---|
| 675 | } |
|---|
| 676 | fflush(stdout); |
|---|
| 677 | } |
|---|
| 678 | |
|---|
| 679 | void Log::outRALog( const char * str, ... ) |
|---|
| 680 | { |
|---|
| 681 | if( !str ) |
|---|
| 682 | return; |
|---|
| 683 | va_list ap; |
|---|
| 684 | if (raLogfile) |
|---|
| 685 | { |
|---|
| 686 | outTimestamp(raLogfile); |
|---|
| 687 | va_start(ap, str); |
|---|
| 688 | vfprintf(raLogfile, str, ap); |
|---|
| 689 | fprintf(raLogfile, "\n" ); |
|---|
| 690 | va_end(ap); |
|---|
| 691 | fflush(raLogfile); |
|---|
| 692 | } |
|---|
| 693 | fflush(stdout); |
|---|
| 694 | } |
|---|
| 695 | |
|---|
| 696 | void outstring_log(const char * str, ...) |
|---|
| 697 | { |
|---|
| 698 | if( !str ) |
|---|
| 699 | return; |
|---|
| 700 | |
|---|
| 701 | char buf[256]; |
|---|
| 702 | va_list ap; |
|---|
| 703 | va_start(ap, str); |
|---|
| 704 | vsnprintf(buf,256, str, ap); |
|---|
| 705 | va_end(ap); |
|---|
| 706 | |
|---|
| 707 | Trinity::Singleton<Log>::Instance().outString(buf); |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | void detail_log(const char * str, ...) |
|---|
| 711 | { |
|---|
| 712 | if( !str ) |
|---|
| 713 | return; |
|---|
| 714 | |
|---|
| 715 | char buf[256]; |
|---|
| 716 | va_list ap; |
|---|
| 717 | va_start(ap, str); |
|---|
| 718 | vsnprintf(buf,256, str, ap); |
|---|
| 719 | va_end(ap); |
|---|
| 720 | |
|---|
| 721 | Trinity::Singleton<Log>::Instance().outDetail(buf); |
|---|
| 722 | } |
|---|
| 723 | |
|---|
| 724 | void debug_log(const char * str, ...) |
|---|
| 725 | { |
|---|
| 726 | if( !str ) |
|---|
| 727 | return; |
|---|
| 728 | |
|---|
| 729 | char buf[256]; |
|---|
| 730 | va_list ap; |
|---|
| 731 | va_start(ap, str); |
|---|
| 732 | vsnprintf(buf,256, str, ap); |
|---|
| 733 | va_end(ap); |
|---|
| 734 | |
|---|
| 735 | Trinity::Singleton<Log>::Instance().outDebug(buf); |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | void error_log(const char * str, ...) |
|---|
| 739 | { |
|---|
| 740 | if( !str ) |
|---|
| 741 | return; |
|---|
| 742 | |
|---|
| 743 | char buf[256]; |
|---|
| 744 | va_list ap; |
|---|
| 745 | va_start(ap, str); |
|---|
| 746 | vsnprintf(buf,256, str, ap); |
|---|
| 747 | va_end(ap); |
|---|
| 748 | |
|---|
| 749 | Trinity::Singleton<Log>::Instance().outError(buf); |
|---|
| 750 | } |
|---|
| 751 | |
|---|
| 752 | void error_db_log(const char * str, ...) |
|---|
| 753 | { |
|---|
| 754 | if( !str ) |
|---|
| 755 | return; |
|---|
| 756 | |
|---|
| 757 | char buf[256]; |
|---|
| 758 | va_list ap; |
|---|
| 759 | va_start(ap, str); |
|---|
| 760 | vsnprintf(buf,256, str, ap); |
|---|
| 761 | va_end(ap); |
|---|
| 762 | |
|---|
| 763 | Trinity::Singleton<Log>::Instance().outErrorDb(buf); |
|---|
| 764 | } |
|---|