Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef ULOGGER_H
00021 #define ULOGGER_H
00022
00023 #include "find_object/FindObjectExp.h"
00024
00025 #include "find_object/utilite/UMutex.h"
00026 #include "find_object/utilite/UDestroyer.h"
00027
00028 #include <stdio.h>
00029 #include <time.h>
00030 #include <string>
00031 #include <vector>
00032
00033 #include <stdarg.h>
00034
00035 #if _MSC_VER
00036 #undef min
00037 #undef max
00038 #endif
00039
00049
00050
00051
00052 #define ULOGGER_LOG(level, ...) ULogger::write(level, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
00053
00054 #define ULOGGER_DEBUG(...) ULOGGER_LOG(ULogger::kDebug, __VA_ARGS__)
00055 #define ULOGGER_INFO(...) ULOGGER_LOG(ULogger::kInfo, __VA_ARGS__)
00056 #define ULOGGER_WARN(...) ULOGGER_LOG(ULogger::kWarning, __VA_ARGS__)
00057 #define ULOGGER_ERROR(...) ULOGGER_LOG(ULogger::kError, __VA_ARGS__)
00058 #define ULOGGER_FATAL(...) ULOGGER_LOG(ULogger::kFatal, __VA_ARGS__)
00059
00060 #define UDEBUG(...) ULOGGER_DEBUG(__VA_ARGS__)
00061 #define UINFO(...) ULOGGER_INFO(__VA_ARGS__)
00062 #define UWARN(...) ULOGGER_WARN(__VA_ARGS__)
00063 #define UERROR(...) ULOGGER_ERROR(__VA_ARGS__)
00064 #define UFATAL(...) ULOGGER_FATAL(__VA_ARGS__)
00065
00066 #define UASSERT(condition) if(!(condition)) ULogger::write(ULogger::kFatal, __FILE__, __LINE__, __FUNCTION__, "Condition (%s) not met!", #condition)
00067 #define UASSERT_MSG(condition, msg_str) if(!(condition)) ULogger::write(ULogger::kFatal, __FILE__, __LINE__, __FUNCTION__, "Condition (%s) not met! [%s]", #condition, msg_str)
00068
00198 class FINDOBJECT_EXP ULogger
00199 {
00200
00201 public:
00205 static const std::string kDefaultLogFileName;
00206
00213 enum Type{kTypeNoLog, kTypeConsole, kTypeFile};
00214
00221 enum Level{kDebug, kInfo, kWarning, kError, kFatal};
00222
00234 static void setType(Type type, const std::string &fileName = kDefaultLogFileName, bool append = true);
00235 static Type type() {return type_;}
00236
00237
00242 static void setPrintTime(bool printTime) {printTime_ = printTime;}
00243 static bool isPrintTime() {return printTime_;}
00244
00249 static void setPrintLevel(bool printLevel) {printLevel_ = printLevel;}
00250 static bool isPrintLevel() {return printLevel_;}
00251
00256 static void setPrintEndline(bool printEndline) {printEndline_ = printEndline;}
00257 static bool isPrintEndLine() {return printEndline_;}
00258
00264 static void setPrintColored(bool printColored) {printColored_ = printColored;}
00265 static bool isPrintColored() {return printColored_;}
00266
00271 static void setPrintWhere(bool printWhere) {printWhere_ = printWhere;}
00272 static bool isPrintWhere() {return printWhere_;}
00273
00278 static void setPrintWhereFullPath(bool printWhereFullPath) {printWhereFullPath_ = printWhereFullPath;}
00279 static bool isPrintWhereFullPath() {return printWhereFullPath_;}
00280
00287 static void setBuffered(bool buffered);
00288 static bool isBuffered() {return buffered_;}
00289
00301 static void setLevel(ULogger::Level level) {level_ = level;}
00302 static ULogger::Level level() {return level_;}
00303
00310 static void setExitLevel(ULogger::Level exitLevel) {exitLevel_ = exitLevel;}
00311 static ULogger::Level exitLevel() {return exitLevel_;}
00312
00319 static void setEventLevel(ULogger::Level eventSentLevel) {eventLevel_ = eventSentLevel;}
00320 static ULogger::Level eventLevel() {return eventLevel_;}
00321
00325 static void reset();
00326
00331 static void flush();
00332
00339 static void write(const char* msg, ...);
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350 static void write(ULogger::Level level,
00351 const char * file,
00352 int line,
00353 const char *function,
00354 const char* msg,
00355 ...);
00356
00362 static int getTime(std::string &timeStr);
00363
00364 protected:
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374 static ULogger* getInstance();
00375
00376
00377
00378
00379
00380
00381
00382 ULogger() {}
00383
00384
00385
00386
00387
00388 virtual ~ULogger();
00389
00390
00391
00392
00393 void _flush();
00394
00395
00396
00397
00398
00399
00400
00401
00402 friend class UDestroyer<ULogger>;
00403
00404
00405
00406
00407 static std::string logFileName_;
00408
00409
00410
00411
00412 static bool append_;
00413
00414 private:
00415
00416
00417
00418
00419
00420
00421 static ULogger* createInstance();
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431 virtual void _write(const char* msg, va_list arg) {}
00432 virtual void _writeStr(const char* msg) {}
00433
00434 private:
00435
00436
00437
00438 static ULogger* instance_;
00439
00440
00441
00442
00443 static UDestroyer<ULogger> destroyer_;
00444
00445
00446
00447
00448
00449 static bool printTime_;
00450
00451
00452
00453
00454
00455 static bool printLevel_;
00456
00457
00458
00459
00460
00461 static bool printEndline_;
00462
00463
00464
00465
00466
00467 static bool printColored_;
00468
00469
00470
00471
00472
00473 static bool printWhere_;
00474
00475
00476
00477
00478
00479
00480
00481 static bool printWhereFullPath_;
00482
00483
00484
00485
00486
00487
00488
00489 static bool limitWhereLength_;
00490
00491
00492
00493
00494 static Type type_;
00495
00496
00497
00498
00499 static Level level_;
00500
00501
00502
00503
00504
00505 static Level exitLevel_;
00506
00507
00508
00509
00510 static Level eventLevel_;
00511
00512 static const char * levelName_[5];
00513
00514
00515
00516
00517 static UMutex loggerMutex_;
00518
00519
00520
00521
00522
00523 static bool buffered_;
00524
00525 static std::string bufferedMsgs_;
00526
00527
00528
00529
00530
00531
00532
00533 static bool exitingState_;
00534 };
00535
00536 #endif // ULOGGER_H