2009-07-28 15:32:10 -06:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2009-03-28 02:57:34 -06:00
|
|
|
#ifndef _LOGMANAGER_H_
|
|
|
|
#define _LOGMANAGER_H_
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
#include "Log.h"
|
|
|
|
#include "StringUtil.h"
|
2010-01-19 12:28:27 -07:00
|
|
|
|
2009-03-18 11:17:58 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define MAX_MESSAGES 8000
|
|
|
|
#define MAX_MSGLEN 512
|
|
|
|
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
// pure virtual interface (well, except the destructor which we just leave empty).
|
|
|
|
class LogListener {
|
2009-03-18 11:17:58 -06:00
|
|
|
public:
|
2009-03-20 13:12:04 -06:00
|
|
|
virtual ~LogListener() {}
|
2009-03-18 11:17:58 -06:00
|
|
|
virtual void Log(LogTypes::LOG_LEVELS, const char *msg) = 0;
|
2009-03-20 13:12:04 -06:00
|
|
|
virtual const char *getName() const = 0;
|
2009-03-18 11:17:58 -06:00
|
|
|
};
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
class FileLogListener : public LogListener {
|
2009-03-18 11:17:58 -06:00
|
|
|
public:
|
|
|
|
FileLogListener(const char *filename);
|
|
|
|
~FileLogListener();
|
|
|
|
|
|
|
|
void Log(LogTypes::LOG_LEVELS, const char *msg);
|
|
|
|
|
|
|
|
bool isValid() {
|
|
|
|
return (m_logfile != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isEnable() {
|
|
|
|
return m_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setEnable(bool enable) {
|
|
|
|
m_enable = enable;
|
|
|
|
}
|
2009-03-20 13:12:04 -06:00
|
|
|
|
|
|
|
const char *getName() const { return "file"; }
|
|
|
|
|
2009-03-18 11:17:58 -06:00
|
|
|
private:
|
|
|
|
char *m_filename;
|
|
|
|
FILE *m_logfile;
|
|
|
|
bool m_enable;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LogContainer {
|
|
|
|
public:
|
2009-03-20 14:52:37 -06:00
|
|
|
LogContainer(const char* shortName, const char* fullName, bool enable = false);
|
2009-03-18 11:17:58 -06:00
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
const char *getShortName() const { return m_shortName; }
|
|
|
|
const char *getFullName() const { return m_fullName; }
|
2009-03-18 11:17:58 -06:00
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
bool isListener(LogListener *listener) const;
|
|
|
|
void addListener(LogListener *listener);
|
|
|
|
void removeListener(LogListener *listener);
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
void trigger(LogTypes::LOG_LEVELS, const char *msg);
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
bool isEnable() const { return m_enable; }
|
2009-03-18 11:17:58 -06:00
|
|
|
void setEnable(bool enable) {
|
|
|
|
m_enable = enable;
|
|
|
|
}
|
|
|
|
|
2009-03-20 14:52:37 -06:00
|
|
|
LogTypes::LOG_LEVELS getLevel() const {
|
2009-03-18 11:17:58 -06:00
|
|
|
return m_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setLevel(LogTypes::LOG_LEVELS level) {
|
|
|
|
m_level = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
char m_fullName[128];
|
|
|
|
char m_shortName[32];
|
|
|
|
bool m_enable;
|
|
|
|
LogTypes::LOG_LEVELS m_level;
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
std::vector<LogListener *> listeners;
|
2009-03-18 11:17:58 -06:00
|
|
|
};
|
|
|
|
|
2010-01-19 12:28:27 -07:00
|
|
|
class ConsoleListener;
|
|
|
|
|
|
|
|
// Avoid <windows.h> include through Thread.h
|
|
|
|
namespace Common {
|
|
|
|
class CriticalSection;
|
|
|
|
}
|
|
|
|
|
2009-03-18 11:17:58 -06:00
|
|
|
class LogManager
|
|
|
|
{
|
|
|
|
private:
|
2009-09-04 05:34:21 -06:00
|
|
|
LogContainer* m_Log[LogTypes::NUMBER_OF_LOGS];
|
2010-01-19 12:28:27 -07:00
|
|
|
Common::CriticalSection *logMutex;
|
2009-03-18 11:17:58 -06:00
|
|
|
FileLogListener *m_fileLog;
|
|
|
|
ConsoleListener *m_consoleLog;
|
2009-03-20 13:12:04 -06:00
|
|
|
static LogManager *m_logManager; // Singleton. Ugh.
|
2009-03-18 11:17:58 -06:00
|
|
|
|
2010-01-19 12:28:27 -07:00
|
|
|
LogManager();
|
|
|
|
~LogManager();
|
2010-02-19 11:50:01 -07:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(LogManager);
|
|
|
|
public:
|
2010-01-19 12:28:27 -07:00
|
|
|
|
2009-03-20 14:52:37 -06:00
|
|
|
static u32 GetMaxLevel() { return MAX_LOGLEVEL; }
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
2010-01-03 01:48:48 -07:00
|
|
|
const char *file, int line, const char *fmt, va_list args);
|
2009-03-18 11:17:58 -06:00
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
void setLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level) {
|
2009-03-18 11:17:58 -06:00
|
|
|
m_Log[type]->setLevel(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setEnable(LogTypes::LOG_TYPE type, bool enable) {
|
|
|
|
m_Log[type]->setEnable(enable);
|
|
|
|
}
|
|
|
|
|
2009-09-04 05:34:21 -06:00
|
|
|
bool isEnable(LogTypes::LOG_TYPE type) {
|
|
|
|
return m_Log[type]->isEnable();
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
const char *getShortName(LogTypes::LOG_TYPE type) const {
|
2009-03-18 11:17:58 -06:00
|
|
|
return m_Log[type]->getShortName();
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
const char *getFullName(LogTypes::LOG_TYPE type) const {
|
2009-03-18 11:17:58 -06:00
|
|
|
return m_Log[type]->getFullName();
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
bool isListener(LogTypes::LOG_TYPE type, LogListener *listener) const {
|
2009-03-18 11:17:58 -06:00
|
|
|
return m_Log[type]->isListener(listener);
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
void addListener(LogTypes::LOG_TYPE type, LogListener *listener) {
|
2009-03-18 11:17:58 -06:00
|
|
|
m_Log[type]->addListener(listener);
|
|
|
|
}
|
|
|
|
|
2009-03-20 13:12:04 -06:00
|
|
|
void removeListener(LogTypes::LOG_TYPE type, LogListener *listener);
|
2009-03-18 11:17:58 -06:00
|
|
|
|
|
|
|
FileLogListener *getFileListener() {
|
|
|
|
return m_fileLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConsoleListener *getConsoleListener() {
|
|
|
|
return m_consoleLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LogManager* GetInstance() {
|
|
|
|
return m_logManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetInstance(LogManager *logManager) {
|
|
|
|
m_logManager = logManager;
|
|
|
|
}
|
2010-02-15 21:34:41 -07:00
|
|
|
|
|
|
|
static void Init();
|
|
|
|
static void Shutdown();
|
2009-03-18 11:17:58 -06:00
|
|
|
};
|
|
|
|
|
2009-03-28 02:57:34 -06:00
|
|
|
#endif // _LOGMANAGER_H_
|