A
download log.cpp
Language: C++
LOC: 57
Project Info
TableHockey3D(tablehockey)
Server: SourceForge
Type: cvs
...ey\CVSROOT\tablehockey\src\
   Application.cpp
   Application.h
   Camera.cpp
   Camera.h
   Cube.cpp
   Cube.h
   Data.cpp
   Data.h
   Disk.cpp
   Disk.h
   FloatingText.cpp
   FloatingText.h
   Floor.cpp
   Floor.h
   Input.cpp
   Input.h
   Light.cpp
   Light.h
   log.cpp
   log.h
   main.cpp
   mmgr.cpp
   mmgr.h
   Model.cpp
   Model.h
   nommgr.h
   Puck.cpp
   Puck.h
   Pyramid.cpp
   Pyramid.h
   scene.cpp
   scene.h
   SmartPtr.h
   Sound.cpp
   Sound.h
   TableHockey.dsp
   TableHockey.dsw
   TestScene.cpp
   TestScene.h
   text.cpp
   text.h
   TextHelp.cpp
   TextHelp.h
   texture.cpp
   texture.h
   TexturedCube.cpp
   TexturedCube.h
   timer.cpp
   timer.h
   View.cpp
   View.h

/*=============================================================================
	log.cpp: Basic OpenGL Framework logging function definitions

    Revision history:
	* Created by Zack Smith
	* Inspired by code written by NeHe (http://nehe.gamedev.net/)
	* Updated October 10, 2000
=============================================================================*/

#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include "log.h"

CLog::CLog(const char *szPath, const char* szMode)
{
	// if nothing was put use the default
	if(szPath == NULL)
	{
		CreateDirectory("logs", NULL);
		m_szPath = "logs/log.txt";
	}
	else
		m_szPath = szPath;

	m_fLog = fopen(m_szPath.c_str(), "w+"); // destroy anything existing
	if(m_fLog)
	{
		fprintf(m_fLog, "Logging System Initialized \n");
		fclose(m_fLog);
	} else
		MessageBox(NULL,"Error Starting Logging System","ERROR",MB_OK);
		
	m_fLog = '\0';
}

CLog::~CLog()
{
	Log("\nShutting Down Logging System");
	Close();

	OutputDebugString("CLog destructor\n");
}

void CLog::Open()
{
	// if it isnt already opened, open the file for adding on to
	if(!m_fLog)
	{
		m_fLog = fopen(m_szPath.c_str(),"a");
	}
}

void CLog::Close()
{
	// if the file is open, close it
	if(m_fLog)
	{
		fclose(m_fLog);
		m_fLog = '\0';
	}
}

void CLog::Log(char *szText, ...)
{
	// open the file
	Open();
	if(!m_fLog) // error somewhere
		return;
	va_list arglist;
	char Text[1024]; // more than 1024 causes a buffer overrun
	memset(Text, '\0', sizeof(Text)); // clear out the memory

	va_start(arglist,szText);
	vsprintf(Text,szText,arglist);
	va_end(arglist);
	fprintf(m_fLog,"\n%s",Text); // copy to the file
	Close(); // and close the file
}


About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us