HTML Logger, Portable and Thread-Safe

Environment: VC++ 6.0, XP

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 when the log changes.

This code does not use MFC or any other library. To provide thread safety, there are a couple of classes (namely CLock and CGuard) that help 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 the HTML font tag.
  3. CLogColor—an implementation of the HTML color.
  4. CSmartString—a string class.

Using the Code

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

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

  //Create a table with three 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 the sample log you see in the picture.

Enjoy...

Downloads

Download demo project - 32 Kb


Comments

  • A better way.

    Posted by Legacy on 12/17/2002 12:00am

    Originally posted by: Guess Who

    Whenever I create a server application or middleware or anything which has a log that I am interested in; I use an http server. This way you can display the data in real-time by just directing your browser to a certain ip address and port.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Download the Information Governance Survey Benchmark Report to gain insights that can help you further establish business value in your Records and Information Management (RIM) program and across your entire organization. Discover how your peers in the industry are dealing with this evolving information lifecycle management environment and uncover key insights such as: 87% of organizations surveyed have a RIM program in place 8% measure compliance 64% cannot get employees to "let go" of information for …

  • Hurricane Sandy was one of the most destructive natural disasters that the United States has ever experienced. Read this success story to learn how Datto protected its partners and their customers with proactive business continuity planning, heroic employee efforts, and the right mix of technology and support. With storm surges over 12 feet, winds that exceeded 90 mph, and a diameter spanning more than 900 miles, Sandy resulted in power outages to approximately 7.5 million people, and caused an estimated $50 …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds