www.pudn.com > HTMLLog.zip > HtmlLogger.cpp
//////////////////////////////////////////////////////////////////////
// Portable HTML logger class
// HtmlLogger.cpp: interface for the CHtmlLogger class.
//
// (c) Copyright 2002 FileX software
// Written by: Desyatnikov Stas
//
// "You have achieved a perfect design not when u have nothing more
// to add but when you have nothing more to take away"
//////////////////////////////////////////////////////////////////////
#include "HtmlLogger.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CHtmlLogger::CHtmlLogger()
{
m_iColumns = 0;
m_bForcedColor = false;
m_bEven = true;
m_bNewFile = true;
m_pColumnArr = NULL;
m_uiLineNumber = 0;
m_pLock = 0;
//Set default colors
m_colorEvenLines.SetColor( 0x00FFFFFF );
m_colorOddLines.SetColor( 0x00F0F0F0 );;
//Make it read to emphasize emergencies
m_colorCurentLine.SetColor( 0x00FF0000 );
//Green summary lines
m_colorSummaryLine.SetColor( 0x0080FF80 );
}
CHtmlLogger::~CHtmlLogger()
{
Close();
}
//Create a HTML file, dumps initial HTML headers
bool CHtmlLogger::Create( char* szFile, bool bInterLocked, ELoggerFlags flags, char* szTitle,
CLogColor colorBack, CLogColor colorTxt)
{
if ( m_pLock )
Close();
if ( bInterLocked )
m_pLock = new CSectionLock;
else
m_pLock = new CNULLLock;
if ( !m_pLock )
return false;
CGuard guard( m_pLock );
guard.Lock();
if ( !m_pLock )
return false;
m_szFile.SetString( szFile );
char* szMode = "bw+";
switch( flags )
{
case LF_Create:
szMode = "w+b";
break;
case LF_Append:
szMode = "ab";
if ( CGenFile::IsFile( szFile ) )
m_bNewFile = false;
break;
}
if ( !m_File.Open( szFile, szMode ) )
return false;
//if the requested file exist, then find tag if ( !m_bNewFile ) { return false; //currently not supported } else { char szBuf[ 300 ], szBuf2[ 300 ]; //Write HTML headers if ( !szTitle ) szTitle = "HTML Log"; //Set body background and text colors sprintf( szBuf2, "