Difference between revisions of "Logging"

From Spartacats
Jump to: navigation, search
(Logging)
(Logging)
Line 1: Line 1:
== Logging ==
+
===Levels===
'''Levels'''<br/>
 
 
There are 6 levels in logging:
 
There are 6 levels in logging:
 
# Fatal
 
# Fatal
Line 14: Line 13:
 
<br/>
 
<br/>
  
'''Functions'''<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 29: Line 28:
 
<br/>
 
<br/>
  
'''Include'''<br/>
+
===Include===
 
The beginning of each file should have: <br/>
 
The beginning of each file should have: <br/>
  
Line 39: Line 38:
 
<br/>
 
<br/>
  
'''Initialize'''<br/>
+
===Initialize===
 
The following code is used to initialize the logger:  
 
The following code is used to initialize the logger:  
 
     tFileLoggerInitParams fileInitParams;
 
     tFileLoggerInitParams fileInitParams;
Line 51: Line 50:
 
<br/>
 
<br/>
  
'''Deinitializing''' <br/>
+
===Deinitializing===
 
     DeInitLogger()
 
     DeInitLogger()
 
<br/>
 
<br/>
  
'''Control Logging''' <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/>
 
<br/>
  
'''Example:''' <br/>
+
===Example===
file.cpp:
+
'''file.cpp:'''
 
         int main(int argc, char** argv)
 
         int main(int argc, char** argv)
 
         {
 
         {
Line 74: Line 73:
 
         }
 
         }
 
<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 83: Line 82:
 
<br/>
 
<br/>
  
'''More Information'''<br/>
+
===More Information===
 
LibLogger Main Page: http://liblogger.sourceforge.net/main.html <br/>
 
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

Revision as of 23:57, 22 April 2013

Levels

There are 6 levels in logging:

  1. Fatal
  2. Error
  3. Warning
  4. Info
  5. Debug
  6. 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 "../Shared/LibLogger/liblogger.h"
    #include "../Shared/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;
    memset(&fileInitParams,0,sizeof(tFileLoggerInitParams)); 
    fileInitParams.fileName = "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("main");
               LogDebug(" Debug message... ");
               LogInfo (" int val = %d ", 9);
               // ......
               LogFatal(" Fatal error has occured, ptr %#x ", 0XABCD );
               // .... other log functions. ........
               FuncLogEntry("main", 10);
               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