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/
|
|
|
|
|
2013-04-15 20:28:55 +00:00
|
|
|
// Official Git repository and contact information can be found at
|
2009-03-18 17:17:58 +00:00
|
|
|
// 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"
|
2011-03-05 06:11:26 +00:00
|
|
|
#include "Thread.h"
|
2011-03-11 10:21:46 +00:00
|
|
|
#include "FileUtil.h"
|
2010-01-19 19:28:27 +00:00
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
#include <set>
|
2009-03-18 17:17:58 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
#define MAX_MESSAGES 8000
|
2010-04-10 15:41:44 +00:00
|
|
|
#define MAX_MSGLEN 1024
|
2009-03-18 17:17:58 +00:00
|
|
|
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
// pure virtual interface
|
|
|
|
class LogListener
|
|
|
|
{
|
2009-03-18 17:17:58 +00:00
|
|
|
public:
|
2009-03-20 19:12:04 +00:00
|
|
|
virtual ~LogListener() {}
|
2011-04-01 07:43:02 +00:00
|
|
|
|
2010-12-14 17:52:01 +00:00
|
|
|
virtual void Log(LogTypes::LOG_LEVELS, const char *msg) = 0;
|
2009-03-18 17:17:58 +00:00
|
|
|
};
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
class FileLogListener : public LogListener
|
|
|
|
{
|
2009-03-18 17:17:58 +00:00
|
|
|
public:
|
2011-03-11 10:21:46 +00:00
|
|
|
FileLogListener(const char *filename);
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2010-12-14 17:52:01 +00:00
|
|
|
void Log(LogTypes::LOG_LEVELS, const char *msg);
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2013-03-29 14:31:15 +00:00
|
|
|
bool IsValid() { return (bool)m_logfile; }
|
2011-04-01 07:43:02 +00:00
|
|
|
bool IsEnabled() const { return m_enable; }
|
|
|
|
void SetEnable(bool enable) { m_enable = enable; }
|
2009-03-20 19:12:04 +00:00
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
const char* GetName() const { return "file"; }
|
2009-03-20 19:12:04 +00:00
|
|
|
|
2009-03-18 17:17:58 +00:00
|
|
|
private:
|
2011-04-01 07:43:02 +00:00
|
|
|
std::mutex m_log_lock;
|
2011-03-11 10:21:46 +00:00
|
|
|
std::ofstream m_logfile;
|
2009-03-18 17:17:58 +00:00
|
|
|
bool m_enable;
|
|
|
|
};
|
|
|
|
|
2011-12-23 17:55:17 +00:00
|
|
|
class DebuggerLogListener : public LogListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void Log(LogTypes::LOG_LEVELS, const char *msg);
|
|
|
|
};
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
class LogContainer
|
|
|
|
{
|
2009-03-18 17:17:58 +00:00
|
|
|
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
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
const char* GetShortName() const { return m_shortName; }
|
|
|
|
const char* GetFullName() const { return m_fullName; }
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
void AddListener(LogListener* listener);
|
|
|
|
void RemoveListener(LogListener* listener);
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
void Trigger(LogTypes::LOG_LEVELS, const char *msg);
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
bool IsEnabled() const { return m_enable; }
|
|
|
|
void SetEnable(bool enable) { m_enable = enable; }
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
LogTypes::LOG_LEVELS GetLevel() const { return m_level; }
|
2009-03-18 17:17:58 +00:00
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
void SetLevel(LogTypes::LOG_LEVELS level) { m_level = level; }
|
|
|
|
|
|
|
|
bool HasListeners() const { return !m_listeners.empty(); }
|
2009-03-18 17:17:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
char m_fullName[128];
|
|
|
|
char m_shortName[32];
|
|
|
|
bool m_enable;
|
2010-12-14 17:52:01 +00:00
|
|
|
LogTypes::LOG_LEVELS m_level;
|
2011-04-01 07:43:02 +00:00
|
|
|
std::mutex m_listeners_lock;
|
|
|
|
std::set<LogListener*> m_listeners;
|
2009-03-18 17:17:58 +00:00
|
|
|
};
|
|
|
|
|
2010-01-19 19:28:27 +00:00
|
|
|
class ConsoleListener;
|
|
|
|
|
2010-11-15 05:29:10 +00:00
|
|
|
class LogManager : NonCopyable
|
2009-03-18 17:17:58 +00:00
|
|
|
{
|
|
|
|
private:
|
2010-12-14 17:52:01 +00:00
|
|
|
LogContainer* m_Log[LogTypes::NUMBER_OF_LOGS];
|
2009-03-18 17:17:58 +00:00
|
|
|
FileLogListener *m_fileLog;
|
|
|
|
ConsoleListener *m_consoleLog;
|
2011-12-23 17:55:17 +00:00
|
|
|
DebuggerLogListener *m_debuggerLog;
|
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
|
|
|
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
|
|
|
|
2010-12-14 17:52:01 +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
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
void SetLogLevel(LogTypes::LOG_TYPE type, LogTypes::LOG_LEVELS level)
|
|
|
|
{
|
|
|
|
m_Log[type]->SetLevel(level);
|
2009-03-18 17:17:58 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
void SetEnable(LogTypes::LOG_TYPE type, bool enable)
|
|
|
|
{
|
|
|
|
m_Log[type]->SetEnable(enable);
|
2009-03-18 17:17:58 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
bool IsEnabled(LogTypes::LOG_TYPE type) const
|
|
|
|
{
|
|
|
|
return m_Log[type]->IsEnabled();
|
2009-09-04 11:34:21 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
const char* GetShortName(LogTypes::LOG_TYPE type) const
|
|
|
|
{
|
|
|
|
return m_Log[type]->GetShortName();
|
2009-03-18 17:17:58 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
const char* GetFullName(LogTypes::LOG_TYPE type) const
|
|
|
|
{
|
|
|
|
return m_Log[type]->GetFullName();
|
2009-03-18 17:17:58 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
void AddListener(LogTypes::LOG_TYPE type, LogListener *listener)
|
|
|
|
{
|
|
|
|
m_Log[type]->AddListener(listener);
|
2009-03-18 17:17:58 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
void RemoveListener(LogTypes::LOG_TYPE type, LogListener *listener)
|
|
|
|
{
|
|
|
|
m_Log[type]->RemoveListener(listener);
|
2009-03-18 17:17:58 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
FileLogListener *GetFileListener() const
|
|
|
|
{
|
2009-03-18 17:17:58 +00:00
|
|
|
return m_fileLog;
|
|
|
|
}
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
ConsoleListener *GetConsoleListener() const
|
|
|
|
{
|
2009-03-18 17:17:58 +00:00
|
|
|
return m_consoleLog;
|
|
|
|
}
|
|
|
|
|
2011-12-23 17:55:17 +00:00
|
|
|
DebuggerLogListener *GetDebuggerListener() const
|
|
|
|
{
|
|
|
|
return m_debuggerLog;
|
|
|
|
}
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
static LogManager* GetInstance()
|
|
|
|
{
|
2009-03-18 17:17:58 +00:00
|
|
|
return m_logManager;
|
|
|
|
}
|
|
|
|
|
2011-04-01 07:43:02 +00:00
|
|
|
static void SetInstance(LogManager *logManager)
|
|
|
|
{
|
2009-03-18 17:17:58 +00:00
|
|
|
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_
|