#include <ULogger.h>
Public Types | |
enum | Level { kDebug, kInfo, kWarning, kError, kFatal } |
enum | Type { kTypeNoLog, kTypeConsole, kTypeFile } |
Static Public Member Functions | |
static ULogger::Level | eventLevel () |
static void | flush () |
static std::map< std::string, unsigned long > | getRegisteredThreads () |
static int | getTime (std::string &timeStr) |
static const std::set< unsigned long > & | getTreadIdFilter () |
static bool | isBuffered () |
static bool | isPrintColored () |
static bool | isPrintEndLine () |
static bool | isPrintLevel () |
static bool | isPrintThreadId () |
static bool | isPrintTime () |
static bool | isPrintWhere () |
static bool | isPrintWhereFullPath () |
static ULogger::Level | level () |
static void | registerCurrentThread (const std::string &name) |
static void | reset () |
static void | setBuffered (bool buffered) |
static void | setEventLevel (ULogger::Level eventSentLevel) |
static void | setLevel (ULogger::Level level) |
static void | setPrintColored (bool printColored) |
static void | setPrintEndline (bool printEndline) |
static void | setPrintLevel (bool printLevel) |
static void | setPrintThreadId (bool printThreadId) |
static void | setPrintTime (bool printTime) |
static void | setPrintWhere (bool printWhere) |
static void | setPrintWhereFullPath (bool printWhereFullPath) |
static void | setTreadIdFilter (const std::set< unsigned long > &ids) |
static void | setTreadIdFilter (const std::vector< std::string > &ids) |
static void | setType (Type type, const std::string &fileName=kDefaultLogFileName, bool append=true) |
static Type | type () |
static void | unregisterCurrentThread () |
static void | write (const char *msg,...) |
static void | write (ULogger::Level level, const char *file, int line, const char *function, const char *msg,...) |
Static Public Attributes | |
static const std::string | kDefaultLogFileName = "./ULog.txt" |
Protected Member Functions | |
void | _flush () |
ULogger () | |
virtual | ~ULogger () |
Static Protected Member Functions | |
static ULogger * | getInstance () |
Static Protected Attributes | |
static bool | append_ = true |
static std::string | logFileName_ |
Private Member Functions | |
virtual void | _write (const char *msg, va_list arg) |
virtual void | _writeStr (const char *msg) |
Static Private Member Functions | |
static ULogger * | createInstance () |
Static Private Attributes | |
static bool | buffered_ = false |
static std::string | bufferedMsgs_ |
static UDestroyer< ULogger > | destroyer_ |
static Level | eventLevel_ = kFatal |
static ULogger * | instance_ = 0 |
static Level | level_ = kInfo |
static const char * | levelName_ [5] = {"DEBUG", " INFO", " WARN", "ERROR", "FATAL"} |
static bool | limitWhereLength_ = false |
static UMutex | loggerMutex_ |
static bool | printColored_ = true |
static bool | printEndline_ = true |
static bool | printLevel_ = true |
static bool | printThreadID_ = false |
static bool | printTime_ = true |
static bool | printWhere_ = true |
static bool | printWhereFullPath_ = false |
static std::map< std::string, unsigned long > | registeredThreads_ |
static std::set< unsigned long > | threadIdFilter_ |
static Type | type_ = ULogger::kTypeNoLog |
Friends | |
class | UDestroyer< ULogger > |
This class is used to log messages with time on a console, in a file and/or with an event. At the start of the application, call ULogger::setType() with the type of the logger you want (see ULogger::Type, the type of the output can be changed at the run-time.). To use it, simply call the convenient macros UDEBUG(), UINFO(), UWARN(), UERROR(), UFATAL() depending of the severity of the message. You can disable some messages by setting the logger level ULogger::setLevel() to severity you want, defined by ULogger::Level. A fatal message will make the application to exit, printing the message on console (whatever the logger type) and posting a ULogEvent (synchronously... see UEventsManager::post()) before exiting.
The display of the logged messages can be modified:
When using a file logger (kTypeLogger), it can be useful in some application to buffer messages before writing them to hard drive (avoiding hard drive latencies). You can set ULogger::setBuffered() to true to do that. When the buffered messages will be written to file on appllciation exit (ULogger destructor) or when ULogger::flush() is called.
If you want the application to exit on a lower severity level than kFatal, you can set ULogger::setExitLevel() to any ULogger::Type you want.
Example:
Output:
Another useful form of the ULogger is to use it with the UTimer class. Here an example:
enum ULogger::Level |
enum ULogger::Type |
|
protectedvirtual |
Definition at line 665 of file ULogger.cpp.
|
protected |
Definition at line 294 of file ULogger.cpp.
|
inlineprivatevirtual |
Reimplemented in UFileLogger, and UConsoleLogger.
|
inlineprivatevirtual |
Reimplemented in UFileLogger, and UConsoleLogger.
|
staticprivate |
Definition at line 650 of file ULogger.cpp.
|
inlinestatic |
|
static |
|
staticprotected |
Definition at line 641 of file ULogger.cpp.
|
static |
Definition at line 247 of file ULogger.cpp.
|
static |
Get the time in the format "2008-7-13 12:23:44".
timeStr | string were the time will be copied. |
Definition at line 593 of file ULogger.cpp.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
static |
Threads can register to this list. If name is empty, it will clear the thread in the list. Should be called from the thread itself.
Definition at line 218 of file ULogger.cpp.
|
static |
Reset to default parameters.
Definition at line 255 of file ULogger.cpp.
|
static |
Set is the logger buffers messages, default false. When true, the messages are buffered until the application is closed or ULogger::flush() is called.
buffered | true to buffer messages, otherwise set to false. |
Definition at line 271 of file ULogger.cpp.
|
inlinestatic |
An ULogEvent is sent on each message logged at the specified level. Note : On message with level >= exitLevel, the event is sent synchronously (see UEventsManager::post()).
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Print the full path: default true. ULogger::setPrintWhere() must be true to have path printed.
printWhereFullPath | true to print the full path, otherwise set to false. |
|
inlinestatic |
|
static |
Definition at line 204 of file ULogger.cpp.
|
static |
Set the type of the logger. When using kTypeFile, the parameter "fileName" would be changed (default is "./ULog.txt"), and optionally "append" if we want the logger to append messages to file or to overwrite the file.
type | the ULogger::Type of the logger. |
fileName | file name used with a file logger type. |
append | if true, the file isn't overwritten, otherwise it is. |
TODO : Can it be useful to have 2 or more types at the same time ? Print in console and file at the same time.
Definition at line 176 of file ULogger.cpp.
|
static |
Definition at line 226 of file ULogger.cpp.
|
static |
Write a message directly to logger without level handling.
msg | the message to write. |
... | the variable arguments |
Definition at line 300 of file ULogger.cpp.
|
static |
Definition at line 360 of file ULogger.cpp.
|
friend |
|
staticprivate |
|
staticprivate |
|
static |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |