2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2009-03-18 17:17:58 +00: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 08:57:34 +00:00
|
|
|
#ifndef _LOGMANAGER_H_
|
|
|
|
#define _LOGMANAGER_H_
|
2009-03-18 17:17:58 +00:00
|
|
|
|
|
|
|
#include "Log.h"
|
|
|
|
#include "StringUtil.h"
|
2010-01-19 19:28:27 +00:00
|
|
|
|
2009-03-18 17:17:58 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define MAX_MESSAGES 8000
|
|
|
|
#define MAX_MSGLEN 512
|
|
|
|
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
// pure virtual interface (well, except the destructor which we just leave empty).
|
|
|
|
class LogListener {
|
2009-03-18 17:17:58 +00:00
|
|
|
public:
|
2009-03-20 19:12:04 +00:00
|
|
|
virtual ~LogListener() {}
|
2009-03-18 17:17:58 +00:00
|
|
|
virtual void Log(LogTypes::LOG_LEVELS, const char *msg) = 0;
|
2009-03-20 19:12:04 +00:00
|
|
|
virtual const char *getName() const = 0;
|
2009-03-18 17:17:58 +00:00
|
|
|
};
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
class FileLogListener : public LogListener {
|
2009-03-18 17:17:58 +00:00
|
|
|
public:
|
|
|
|
FileLogListener(const char *filename);
|
|
|
|
~FileLogListener();
|
|
|
|
|
2010-02-02 21:56:29 +00:00
|
|
|
void Reload();
|
|
|
|
|
2009-03-18 17:17:58 +00:00
|
|
|
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 19:12:04 +00:00
|
|
|
|
|
|
|
const char *getName() const { return "file"; }
|
|
|
|
|
2009-03-18 17:17:58 +00:00
|
|
|
private:
|
|
|
|
char *m_filename;
|
|
|
|
FILE *m_logfile;
|
|
|
|
bool m_enable;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LogContainer {
|
|
|
|
public:
|
2009-03-20 20:52:37 +00:00
|
|
|
LogContainer(const char* shortName, const char* fullName, bool enable = false);
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
const char *getShortName() const { return m_shortName; }
|
|
|
|
const char *getFullName() const { return m_fullName; }
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
bool isListener(LogListener *listener) const;
|
|
|
|
void addListener(LogListener *listener);
|
|
|
|
void removeListener(LogListener *listener);
|
2009-03-18 17:17:58 +00:00
|
|
|
|
|
|
|
void trigger(LogTypes::LOG_LEVELS, const char *msg);
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
bool isEnable() const { return m_enable; }
|
2009-03-18 17:17:58 +00:00
|
|
|
void setEnable(bool enable) {
|
|
|
|
m_enable = enable;
|
|
|
|
}
|
|
|
|
|
2009-03-20 20:52:37 +00:00
|
|
|
LogTypes::LOG_LEVELS getLevel() const {
|
2009-03-18 17:17:58 +00: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 19:12:04 +00:00
|
|
|
std::vector<LogListener *> listeners;
|
2009-03-18 17:17:58 +00:00
|
|
|
};
|
|
|
|
|
2010-01-19 19:28:27 +00:00
|
|
|
class ConsoleListener;
|
|
|
|
|
|
|
|
// Avoid <windows.h> include through Thread.h
|
|
|
|
namespace Common {
|
|
|
|
class CriticalSection;
|
|
|
|
}
|
|
|
|
|
2009-03-18 17:17:58 +00:00
|
|
|
class LogManager
|
|
|
|
{
|
|
|
|
private:
|
2009-09-04 11:34:21 +00:00
|
|
|
LogContainer* m_Log[LogTypes::NUMBER_OF_LOGS];
|
2010-01-19 19:28:27 +00:00
|
|
|
Common::CriticalSection *logMutex;
|
2009-03-18 17:17:58 +00:00
|
|
|
FileLogListener *m_fileLog;
|
|
|
|
ConsoleListener *m_consoleLog;
|
2009-03-20 19:12:04 +00:00
|
|
|
static LogManager *m_logManager; // Singleton. Ugh.
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2010-01-19 19:28:27 +00:00
|
|
|
LogManager();
|
|
|
|
~LogManager();
|
2010-02-19 18:50:01 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(LogManager);
|
|
|
|
public:
|
2010-01-19 19:28:27 +00:00
|
|
|
|
2009-03-20 20:52:37 +00:00
|
|
|
static u32 GetMaxLevel() { return MAX_LOGLEVEL; }
|
2009-03-18 17:17:58 +00:00
|
|
|
|
|
|
|
void Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
2010-01-03 08:48:48 +00:00
|
|
|
const char *file, int line, const char *fmt, va_list args);
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
void setLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level) {
|
2009-03-18 17:17:58 +00:00
|
|
|
m_Log[type]->setLevel(level);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setEnable(LogTypes::LOG_TYPE type, bool enable) {
|
|
|
|
m_Log[type]->setEnable(enable);
|
|
|
|
}
|
|
|
|
|
2009-09-04 11:34:21 +00:00
|
|
|
bool isEnable(LogTypes::LOG_TYPE type) {
|
|
|
|
return m_Log[type]->isEnable();
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
const char *getShortName(LogTypes::LOG_TYPE type) const {
|
2009-03-18 17:17:58 +00:00
|
|
|
return m_Log[type]->getShortName();
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
const char *getFullName(LogTypes::LOG_TYPE type) const {
|
2009-03-18 17:17:58 +00:00
|
|
|
return m_Log[type]->getFullName();
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
bool isListener(LogTypes::LOG_TYPE type, LogListener *listener) const {
|
2009-03-18 17:17:58 +00:00
|
|
|
return m_Log[type]->isListener(listener);
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
void addListener(LogTypes::LOG_TYPE type, LogListener *listener) {
|
2009-03-18 17:17:58 +00:00
|
|
|
m_Log[type]->addListener(listener);
|
|
|
|
}
|
|
|
|
|
2009-03-20 19:12:04 +00:00
|
|
|
void removeListener(LogTypes::LOG_TYPE type, LogListener *listener);
|
2009-03-18 17:17:58 +00: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-16 04:34:41 +00:00
|
|
|
|
|
|
|
static void Init();
|
|
|
|
static void Shutdown();
|
2009-03-18 17:17:58 +00:00
|
|
|
};
|
|
|
|
|
2009-03-28 08:57:34 +00:00
|
|
|
#endif // _LOGMANAGER_H_
|