Use the standard Singleton for CLogger, to fix problems with unordered shutdown

This was SVN commit r2383.
This commit is contained in:
Ykkrosh 2005-06-13 19:31:48 +00:00
parent 83849d027a
commit dd3c8f6fb5
3 changed files with 16 additions and 25 deletions

View File

@ -1103,6 +1103,8 @@ static void Shutdown()
h_mgr_shutdown();
mem_shutdown();
delete &g_Logger;
}
static void Init(int argc, char* argv[], bool setup_gfx = true)
@ -1112,6 +1114,7 @@ static void Init(int argc, char* argv[], bool setup_gfx = true)
// If you ever want to catch a particular allocation:
//_CrtSetBreakAlloc(187);
new CLogger;
// set 24 bit (float) FPU precision for faster divides / sqrts
#ifdef _M_IX86
@ -1181,6 +1184,7 @@ static void Init(int argc, char* argv[], bool setup_gfx = true)
#ifdef _WIN32
sle(11340106);
// ???
#endif
if (setup_gfx)

View File

@ -24,16 +24,8 @@ const char* html_footer = "</BODY>\n</HTML>\n";
#define MEMORY_BUFFER_SIZE 240
CLogger * CLogger::GetInstance()
{
static CLogger m_Instance;
return &m_Instance;
}
CLogger::CLogger()
{
m_NumberOfMessages = 0;
m_NumberOfErrors = 0;
m_NumberOfWarnings = 0;
@ -58,7 +50,7 @@ CLogger::CLogger()
CLogger::~CLogger ()
{
char buffer[60];
char buffer[128];
sprintf(buffer," with %d message(s), %d error(s) and %d warning(s).", \
m_NumberOfMessages,m_NumberOfErrors,m_NumberOfWarnings);
@ -255,9 +247,9 @@ int CLogger::Interestedness(const char* category)
return 1;
int level;
// Something failed, so the default value might be a good alternative
// Try to retrieve the value as an integer
if (! v->GetInt(level))
return 1;
return 1; // something failed, so the default value might be a good alternative
return level;
}

View File

@ -2,14 +2,14 @@
#define _ps_CLogger_H
#include <fstream>
#include <stdio.h>
#include <stdarg.h>
#include <string>
#include <vector>
#include <set>
#define LOG (CLogger::GetInstance()->Log)
#define LOG_ONCE (CLogger::GetInstance()->LogOnce)
#include "Singleton.h"
#define g_Logger CLogger::GetSingleton()
#define LOG (CLogger::GetSingleton().Log)
#define LOG_ONCE (CLogger::GetSingleton().LogOnce)
enum ELogMethod
{
@ -19,13 +19,12 @@ enum ELogMethod
WARNING
};
class CLogger
class CLogger : public Singleton<CLogger>
{
public:
//Function used to get instance of CLogger
static CLogger *GetInstance();
virtual ~CLogger();
CLogger();
~CLogger();
//Functions to write different message types
void WriteMessage(const char *message, int interestedness);
@ -39,13 +38,9 @@ public:
//Function to log stuff to memory buffer
void QuickLog(const char *fmt, ...);
private:
CLogger();
CLogger(const CLogger& init);
CLogger& operator=(const CLogger& rhs);
void LogUsingMethod(ELogMethod method, const char* category, const char* message);
//the three filestreams