Difference between revisions of "Logging"
(→Logging) |
(→Initialize) |
||
(11 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | == | + | ===Levels=== |
− | |||
There are 6 levels in logging: | There are 6 levels in logging: | ||
# Fatal | # Fatal | ||
Line 13: | Line 12: | ||
NOTE: Function logging is at the Trace level <br/> | NOTE: Function logging is at the Trace level <br/> | ||
<br/> | <br/> | ||
− | + | ||
+ | ===Functions=== | ||
int ''LogTrace'' (const char *fmt,...) <br/> | int ''LogTrace'' (const char *fmt,...) <br/> | ||
int ''LogDebug'' (const char *fmt,...) <br/> | int ''LogDebug'' (const char *fmt,...) <br/> | ||
Line 28: | Line 28: | ||
<br/> | <br/> | ||
− | + | ===Include=== | |
The beginning of each file should have: <br/> | The beginning of each file should have: <br/> | ||
− | #include ".. | + | #include "../LibLogger/liblogger.h" |
− | #include ".. | + | #include "../LibLogger/file_logger.h" |
As well, any file where the log is initialized needs to include: <br/> | As well, any file where the log is initialized needs to include: <br/> | ||
#include <memory.h> | #include <memory.h> | ||
+ | <br/> | ||
− | + | ===Initialize=== | |
The following code is used to initialize the logger: | The following code is used to initialize the logger: | ||
tFileLoggerInitParams fileInitParams; | tFileLoggerInitParams fileInitParams; | ||
− | + | ZeroMemory(&fileInitParams, sizeof(tFileLoggerInitParams)); | |
− | fileInitParams.fileName = "Logs/LOGNAME.log"; | + | fileInitParams.fileName = L"Logs/LOGNAME.log"; |
fileInitParams.fileOpenMode = AppendMode; | fileInitParams.fileOpenMode = AppendMode; | ||
− | InitLogger(LogToFile,&fileInitParams); | + | InitLogger(LogToFile, &fileInitParams); |
<br/> | <br/> | ||
The logs will be stored in the folder "Resources/Logs" <br/> | The logs will be stored in the folder "Resources/Logs" <br/> | ||
Line 49: | Line 50: | ||
<br/> | <br/> | ||
− | + | ===Deinitializing=== | |
DeInitLogger() | DeInitLogger() | ||
<br/> | <br/> | ||
− | + | ===Control Logging=== | |
You can attach a Module Name to logs by associating files under a module name in a header file. This allows you to also control the level of logs that show up if any at all. <br/> | You can attach a Module Name to logs by associating files under a module name in a header file. This allows you to also control the level of logs that show up if any at all. <br/> | ||
More information can be found [http://liblogger.sourceforge.net/PAGE_MODULE_NAME.html here]. <br/> | More information can be found [http://liblogger.sourceforge.net/PAGE_MODULE_NAME.html here]. <br/> | ||
+ | <br/> | ||
− | + | ===Example=== | |
− | ''' | + | '''file.cpp:''' |
− | |||
int main(int argc, char** argv) | int main(int argc, char** argv) | ||
{ | { | ||
− | FuncLogEntry("main"); | + | FuncLogEntry(L"main"); |
− | LogDebug(" Debug message... "); | + | LogDebug(L" Debug message... "); |
− | LogInfo (" int val = %d ", 9); | + | LogInfo (L" int val = %d ", 9); |
// ...... | // ...... | ||
− | LogFatal(" Fatal error has occured, ptr %#x ", 0XABCD ); | + | LogFatal(L" Fatal error has occured, ptr %#x ", 0XABCD ); |
// .... other log functions. ........ | // .... other log functions. ........ | ||
− | FuncLogEntry("main", 10); | + | FuncLogEntry(L"main", 10); |
+ | DeInitLogger(); | ||
return 0; | return 0; | ||
} | } | ||
<br/> | <br/> | ||
− | Log output: | + | '''Log output:''' |
----- Logging Started on 04/20/13 17:27:40 ----- | ----- Logging Started on 04/20/13 17:27:40 ----- | ||
{ main | { main | ||
Line 79: | Line 81: | ||
[F]:c:\users\me\documents\ucsd 12-13\liblogger-0.2\liblogger\src\testapp\file.cpp:main:7: Fatal error has occured, ptr OXABCD | [F]:c:\users\me\documents\ucsd 12-13\liblogger-0.2\liblogger\src\testapp\file.cpp:main:7: Fatal error has occured, ptr OXABCD | ||
main : 10 } | main : 10 } | ||
+ | <br/> | ||
− | <br/> | + | ===More Information=== |
+ | LibLogger Main Page: http://liblogger.sourceforge.net/main.html <br/> | ||
LibLogger Tutorial: http://liblogger.sourceforge.net/page_tutorial.html | LibLogger Tutorial: http://liblogger.sourceforge.net/page_tutorial.html |
Latest revision as of 11:56, 30 April 2013
Contents
Levels
There are 6 levels in logging:
- Fatal
- Error
- Warning
- Info
- Debug
- Trace
- Function
Messages should be set to the correct level as logging levels can be turned on and off from a header file.
NOTE: Function logging is at the Trace level
Functions
int LogTrace (const char *fmt,...)
int LogDebug (const char *fmt,...)
int LogInfo (const char *fmt,...)
int LogWarn (const char *fmt,...)
int LogError (const char *fmt,...)
int LogFatal (const char *fmt,...)
int FuncLogEntry (const char *funcName)
int FuncLogExit (const char *funcName, const int lineNumber)
For each logging function, you simply put what you would normally for printf().
For FuncLog, put the name of the function and for FuncLogExit, lineNumber is the line number the function exited on.
In the log, the name of the function will show up along with '{' for the reader to know all messages after are from within the function until '}' is seen.
Include
The beginning of each file should have:
#include "../LibLogger/liblogger.h" #include "../LibLogger/file_logger.h"
As well, any file where the log is initialized needs to include:
#include <memory.h>
Initialize
The following code is used to initialize the logger:
tFileLoggerInitParams fileInitParams; ZeroMemory(&fileInitParams, sizeof(tFileLoggerInitParams)); fileInitParams.fileName = L"Logs/LOGNAME.log"; fileInitParams.fileOpenMode = AppendMode; InitLogger(LogToFile, &fileInitParams);
The logs will be stored in the folder "Resources/Logs"
If you would like to see a new set of logs each time (overwrite all previous logs) omit the line with 'AppendMode'.
Deinitializing
DeInitLogger()
Control Logging
You can attach a Module Name to logs by associating files under a module name in a header file. This allows you to also control the level of logs that show up if any at all.
More information can be found here.
Example
file.cpp:
int main(int argc, char** argv) { FuncLogEntry(L"main"); LogDebug(L" Debug message... "); LogInfo (L" int val = %d ", 9); // ...... LogFatal(L" Fatal error has occured, ptr %#x ", 0XABCD ); // .... other log functions. ........ FuncLogEntry(L"main", 10); DeInitLogger(); return 0; }
Log output:
----- Logging Started on 04/20/13 17:27:40 ----- { main [D]:c:\users\me\documents\ucsd 12-13\liblogger-0.2\liblogger\src\testapp\file.cpp:main:4: Debug message... [I]:c:\users\me\documents\ucsd 12-13\liblogger-0.2\liblogger\src\testapp\file.cpp:main:5: int val = 9 [F]:c:\users\me\documents\ucsd 12-13\liblogger-0.2\liblogger\src\testapp\file.cpp:main:7: Fatal error has occured, ptr OXABCD main : 10 }
More Information
LibLogger Main Page: http://liblogger.sourceforge.net/main.html
LibLogger Tutorial: http://liblogger.sourceforge.net/page_tutorial.html