Added the file log receiver and also added the dumpMessages() function to the ILogger class.

This commit is contained in:
Raynaldo Rivera 2010-02-14 17:08:16 +00:00
parent b44bf8a1b2
commit 0c0a8d12ac
6 changed files with 217 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
// This file is part of the "cAudio Engine"
// For conditions of distribution and use, see copyright notice in cAudio.h
#ifndef CFILELOGRECEIVER_H_INCLUDED
#define CFILELOGERCEIVER_H_INCLUDED
#include "../include/ILogReceiver.h"
#include <string>
#include <list>
namespace cAudio
{
class cFileLogReceiver : public ILogReceiver
{
public:
cFileLogReceiver();
~cFileLogReceiver();
bool OnLogMessage(const char* sender, const char* message, LogLevel level, float time);
void dumpMessages();
private:
std::list<std::string> logs;
std::list<int> levels;
};
};
#endif //!CFILELOGRECEIVER_H_INCLUDED

View File

@ -40,6 +40,8 @@ namespace cAudio
virtual bool isLogReceiverRegistered(const char* name);
//!Returns a registered log receiver
virtual ILogReceiver* getLogReceiver(const char* name);
//!Dumps the log messages to a file
virtual void dumpMessages();
protected:
void broadcastMessage( LogLevel level, const char* sender, const char* msg, va_list args );

165
Source/cFileLogReceiver.cpp Normal file
View File

@ -0,0 +1,165 @@
// Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
// This file is part of the "cAudio Engine"
// For conditions of distribution and use, see copyright notice in cAudio.h
#include "../Headers/cFileLogReceiver.h"
#include <iostream>
#include <fstream>
namespace cAudio
{
cFileLogReceiver::cFileLogReceiver()
{
}
cFileLogReceiver::~cFileLogReceiver()
{
}
bool cFileLogReceiver::OnLogMessage(const char* sender, const char* message, LogLevel level, float time)
{
levels.push_back(level);
logs.push_back(message);
return true;
}
void cFileLogReceiver::dumpMessages()
{
std::list<std::string>::iterator it = logs.begin();
std::list<int>::iterator it2 = levels.begin();
std::ofstream outf;
if( !outf.is_open() )
{
// Reset log file
outf.setf( std::ios::fixed );
outf.precision( 3 );
outf.open( "cAudioEngineLog.html", std::ios::out );
if( !outf ){
return;
}
outf<<"<html>\n";
outf<<"<head>\n";
outf<<"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
outf<<"<title>cAudio Log</title>\n";
outf<<"<style type=\"text/css\">\n";
outf<<"body, html {\n";
outf<<"background: #000000;\n";
outf<<"width: 1000px;\n";
outf<<"font-family: Arial;\n";
outf<<"font-size: 16px;\n";
outf<<"color: #C0C0C0;\n";
outf<<"}\n";
outf<<"h1 {\n";
outf<<"color : #FFFFFF;\n";
outf<<"border-bottom : 1px dotted #888888;\n";
outf<<"}\n";
outf<<"pre {\n";
outf<<"font-family : arial;\n";
outf<<"margin : 0;\n";
outf<<"}\n";
outf<<".box {\n";
outf<<"border : 1px dotted #818286;\n";
outf<<"padding : 5px;\n";
outf<<"margin: 5px;\n";
outf<<"width: 950px;\n";
outf<<"background-color : #292929;\n";
outf<<"}\n";
outf<<".err {\n";
outf<<"color: #EE1100;\n";
outf<<"font-weight: bold\n";
outf<<"}\n";
outf<<".warn {\n";
outf<<"color: #FFCC00;\n";
outf<<"font-weight: bold\n";
outf<<"}\n";
outf<<".crit {\n";
outf<<"color: #BB0077;\n";
outf<<"font-weight: bold\n";
outf<<"}\n";
outf<<".info {\n";
outf<<"color: #C0C0C0;\n";
outf<<"}\n";
outf<<".debug {\n";
outf<<"color: #CCA0A0;\n";
outf<<"}\n";
outf<<"</style>\n";
outf<<"</head>\n\n";
outf<<"<body>\n";
outf<<"<h1>cAudio Log</h1>\n";
outf<<"<h3>" << "2.0.0" << "</h3>\n";
outf<<"<div class=\"box\">\n";
outf<<"<table>\n";
outf.flush();
}
for(it;it != logs.end(); it++)
{
outf<<"<tr>\n";
outf<<"<td width=\"100\">";
outf<<"Log: ";
outf <<"</td>\n";
outf<<"<td class=\"";
switch( *it2 )
{
case ELL_DEBUG:
outf<<"debug";
break;
case ELL_INFO:
outf<<"info";
break;
case ELL_WARNING:
outf<<"warn";
break;
case ELL_ERROR:
outf<<"err";
break;
case ELL_CRITICAL:
outf<<"crit";
break;
case ELL_COUNT:
outf<<"debug";
break;
default:
outf<<"debug";
}
outf<<"\"><pre>\n";
outf<<*it;
outf<<"\n</pre></td>\n";
outf<<"</tr>\n";
outf.flush();
if(it2 != levels.end())
{
it2++;
}
}
}
};

View File

@ -5,6 +5,7 @@
#include <time.h>
#include "../Headers/cLogger.h"
#include "../Headers/cConsoleLogReceiver.h"
#include "../Headers/cFileLogReceiver.h"
#include "../Headers/cUtils.h"
namespace cAudio
@ -12,6 +13,7 @@ namespace cAudio
static cLogger Logger;
static bool FirstTimeLogInit(false);
static cConsoleLogReceiver ConsoleLog;
static cFileLogReceiver FileLog;
cLogger::cLogger() : StartTime(0), MinLogLevel(ELL_INFO)
{
@ -140,12 +142,18 @@ namespace cAudio
return NULL;
}
void cLogger::dumpMessages()
{
((cFileLogReceiver*)Logger.getLogReceiver("File"))->dumpMessages();
}
CAUDIO_API ILogger* getLogger()
{
if(!FirstTimeLogInit)
{
FirstTimeLogInit = true;
Logger.registerLogReceiver(&ConsoleLog, "Console");
Logger.registerLogReceiver(&FileLog,"File");
}
return &Logger;
}

View File

@ -207,6 +207,10 @@
RelativePath=".\Headers\cEFXFunctions.h"
>
</File>
<File
RelativePath=".\Headers\cFileLogReceiver.h"
>
</File>
<File
RelativePath=".\Headers\cFileSource.h"
>
@ -307,6 +311,10 @@
RelativePath=".\Source\cEffect.cpp"
>
</File>
<File
RelativePath=".\Source\cFileLogReceiver.cpp"
>
</File>
<File
RelativePath=".\Source\cFileSource.cpp"
>

View File

@ -36,6 +36,9 @@ namespace cAudio
virtual bool isLogReceiverRegistered(const char* name) = 0;
//!Returns a registered log receiver
virtual ILogReceiver* getLogReceiver(const char* name) = 0;
//!Dumps the log messages to a file
virtual void dumpMessages() = 0;
protected:
private:
};