Difference between revisions of "Logging"

From Spartacats
Jump to: navigation, search
(Logging)
(Logging)
Line 13: Line 13:
 
NOTE: Function logging is at the Trace level <br/>
 
NOTE: Function logging is at the Trace level <br/>
 
<br/>
 
<br/>
 +
 
'''Functions'''<br/>
 
'''Functions'''<br/>
 
int  ''LogTrace'' (const char *fmt,...) <br/>
 
int  ''LogTrace'' (const char *fmt,...) <br/>
Line 36: Line 37:
 
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'''<br/>
 
'''Initialize'''<br/>
Line 56: Line 58:
 
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:''' <br/>
 
'''Example:''' <br/>
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'''<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:54, 22 April 2013

Logging

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