log_sys to logger

enum DebugLevel {
		General = 0,	/* 0 - Low-Level general debugging, useful info on single line */
		Moderate,		/* 1 - Informational based, used in functions, when particular things load */
		Detail,			/* 2 - Use this for extreme detail in logging, usually in extreme debugging in the stack or interprocess communication */
	};
void EQEmuLogSys::LogDebug(DebugLevel debug_level, std::string message, ...)
This commit is contained in:
Akkadius 2015-01-10 14:40:47 -06:00
parent b8ed29c600
commit 84741e4cb1
4 changed files with 40 additions and 16 deletions

View File

@ -90,21 +90,35 @@ void EQEmuLogSys::StartZoneLogs(const std::string log_name)
process_log.open(StringFormat("logs/zone/%s.txt", log_name.c_str()), std::ios_base::app | std::ios_base::out);
}
void EQEmuLogSys::Log(uint16 log_type, const std::string message)
void EQEmuLogSys::LogDebug(DebugLevel debug_level, std::string message, ...){
va_list args;
va_start(args, message);
std::string output_message = vStringFormat(message.c_str(), args);
va_end(args);
EQEmuLogSys::Log(EQEmuLogSys::LogType::Debug, output_message);
}
void EQEmuLogSys::Log(uint16 log_type, const std::string message, ...)
{
if (log_type > EQEmuLogSys::MaxLogID){
return;
}
if (!RuleB(Logging, LogFileCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; }
va_list args;
va_start(args, message);
std::string output_message = vStringFormat(message.c_str(), args);
va_end(args);
auto t = std::time(nullptr);
auto tm = *std::localtime(&t);
EQEmuLogSys::ConsoleMessage(log_type, message);
if (process_log){
process_log << std::put_time(&tm, "[%d-%m-%Y :: %H:%M:%S] ") << StringFormat("[%s] ", TypeNames[log_type]).c_str() << message << std::endl;
process_log << std::put_time(&tm, "[%d-%m-%Y :: %H:%M:%S] ") << StringFormat("[%s] ", TypeNames[log_type]).c_str() << output_message << std::endl;
}
else{
std::cout << "[DEBUG] " << " :: There currently is no log file open for this process " << std::endl;
std::cout << "[DEBUG] " << ":: There currently is no log file open for this process " << std::endl;
}
}
@ -113,23 +127,21 @@ void EQEmuLogSys::ConsoleMessage(uint16 log_type, const std::string message)
if (log_type > EQEmuLogSys::MaxLogID){
return;
}
if (!RuleB(Logging, ConsoleLogCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; }
#ifdef _WINDOWS
HANDLE console_handle;
console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFOEX info = { 0 };
info.cbSize = sizeof(info);
info.dwFontSize.Y = 12; // leave X as zero
info.FontWeight = FW_NORMAL;
wcscpy(info.FaceName, L"Lucida Console");
SetCurrentConsoleFontEx(console_handle, NULL, &info);
SetConsoleTextAttribute(console_handle, LogColors[log_type]);
SetCurrentConsoleFontEx(console_handle, NULL, &info);
SetConsoleTextAttribute(console_handle, LogColors[log_type]);
#endif
std::cout << "[(N)" << TypeNames[log_type] << "] " << message << std::endl;
std::cout << "[N::" << TypeNames[log_type] << "] " << message << std::endl;
#ifdef _WINDOWS
/* Always set back to white*/

View File

@ -40,17 +40,25 @@ public:
MaxLogID /* Max, used in functions to get the max log ID */
};
void StartZoneLogs(const std::string log_name);
void Log(uint16 log_type, const std::string message);
enum DebugLevel {
General = 0, /* 0 - Low-Level general debugging, useful info on single line */
Moderate, /* 1 - Informational based, used in functions, when particular things load */
Detail, /* 2 - Use this for extreme detail in logging, usually in extreme debugging in the stack or interprocess communication */
};
void CloseZoneLogs();
void ConsoleMessage(uint16 log_type, const std::string message);
void LogDebug(DebugLevel debug_level, std::string message, ...);
void Log(uint16 log_type, const std::string message, ...);
void StartZoneLogs(const std::string log_name);
private:
bool zone_general_init = false;
};
extern EQEmuLogSys log_sys;
extern EQEmuLogSys logger;

View File

@ -103,7 +103,7 @@ TitleManager title_manager;
QueryServ *QServ = 0;
TaskManager *taskmanager = 0;
QuestParserCollection *parse = 0;
EQEmuLogSys log_sys;
EQEmuLogSys logger;
const SPDat_Spell_Struct* spells;
void LoadSpells(EQEmu::MemoryMappedFile **mmf);
@ -146,6 +146,8 @@ int main(int argc, char** argv) {
worldserver.SetLauncherName("NONE");
}
_log(ZONE__INIT, "Loading server configuration..");
if (!ZoneConfig::LoadConfig()) {
_log(ZONE__INIT_ERR, "Loading server configuration failed.");
@ -174,6 +176,8 @@ int main(int argc, char** argv) {
GuildBanks = nullptr;
logger.LogDebug(EQEmuLogSys::DebugLevel::General, "This is a crazy test message, database is %s and username is %s", Config->DatabaseDB.c_str(), Config->DatabaseUsername.c_str());
#ifdef _EQDEBUG
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

View File

@ -152,7 +152,7 @@ bool Zone::Bootup(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
/* Set Logging */
log_sys.StartZoneLogs(StringFormat("%s_ver-%u_instid-%u_port-%u", zone->GetShortName(), zone->GetInstanceVersion(), zone->GetInstanceID(), ZoneConfig::get()->ZonePort));
logger.StartZoneLogs(StringFormat("%s_ver-%u_instid-%u_port-%u", zone->GetShortName(), zone->GetInstanceVersion(), zone->GetInstanceID(), ZoneConfig::get()->ZonePort));
return true;
}
@ -720,7 +720,7 @@ void Zone::Shutdown(bool quite)
parse->ReloadQuests(true);
UpdateWindowTitle();
log_sys.CloseZoneLogs();
logger.CloseZoneLogs();
}
void Zone::LoadZoneDoors(const char* zone, int16 version)