Click here to Skip to main content
15,885,216 members
Articles / Web Development / HTML

HTML Logger - Portable and Thread-safe

Rate me:
Please Sign up or sign in to vote.
4.73/5 (16 votes)
3 Dec 20021 min read 65.9K   1.2K   34   6
An article on using HTML formatted log in your applications

Sample Image - HTMLLogger.gif

Introduction

I needed to create an HTML logger that would be portable across Win32 and VXWorks OSs. This code was written in a weekend, so don't judge it severely.

What the Code Does

This code will help you create colored, clear to read HTML logs from any C++ applications. The HTML log generated will be easy to present to a user: you just need to give a browser the generated file URL and refresh the browser once the log changes.

This code does not use MFC or any other library. In order to provide thread safety, there are a couple of classes (namely: CLock, CGuard) that helps make the code safe.

Furthermore, there are additional helper classes that hide nasty details:

  1. CGenFile - hides the file access details
  2. CLogFont - generally an implementation of HTML font tag
  3. CLogColor - an implementation of HTML color
  4. CSmartString - a string class.

Using the Code

Instantiate CHtmlLogger in your code, create the log, create as many HTML tables (reports) as you wish.

C++
CHtmlLogger Log;
Log.Create( "FirstHMLLog.htm" );

//Create table with 3 columns
Log.CreateTable( 3, "First HTML log" );

//Fill the columns
Log.SetColumn( 0, "Heading1" );
Log.SetColumn( 1, "Heading2" );
Log.SetColumn( 2, "Heading3" );

//Add the line specifying the line type (header in this case)
Log.AddLine( 0, CHtmlLogger::LT_Header );

Kindergarten stuff, right? The return values validation was removed for clarity. You should look at the sample provided to see the full API. The sample will create a sample log you see in the picture.

Enjoy!

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Web Developer
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralPerfect, really helpful. Just a small correction Pin
Ziv G9-Mar-08 4:23
Ziv G9-Mar-08 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.