Minor tweaking to new logsys

This commit is contained in:
Michael Cook (mackal) 2015-01-23 15:48:20 -05:00
parent 451983ffc9
commit 06ff4823d3
3 changed files with 75 additions and 79 deletions

View File

@ -28,6 +28,7 @@
#include <string> #include <string>
#include <iomanip> #include <iomanip>
#include <time.h> #include <time.h>
#include <sys/stat.h>
std::ofstream process_log; std::ofstream process_log;
@ -75,13 +76,15 @@ namespace Console {
}; };
} }
EQEmuLogSys::EQEmuLogSys(){ EQEmuLogSys::EQEmuLogSys()
on_log_gmsay_hook = [](uint16 log_type, std::string&) {}; {
on_log_gmsay_hook = [](uint16 log_type, const std::string&) {};
bool file_logs_enabled = false; bool file_logs_enabled = false;
int log_platform = 0; int log_platform = 0;
} }
EQEmuLogSys::~EQEmuLogSys(){ EQEmuLogSys::~EQEmuLogSys()
{
} }
void EQEmuLogSys::LoadLogSettingsDefaults() void EQEmuLogSys::LoadLogSettingsDefaults()
@ -90,11 +93,7 @@ void EQEmuLogSys::LoadLogSettingsDefaults()
log_platform = GetExecutablePlatformInt(); log_platform = GetExecutablePlatformInt();
/* Zero out Array */ /* Zero out Array */
for (int i = 0; i < Logs::LogCategory::MaxCategoryID; i++){ memset(log_settings, 0, sizeof(LogSettings) * Logs::LogCategory::MaxCategoryID);
log_settings[i].log_to_console = 0;
log_settings[i].log_to_file = 0;
log_settings[i].log_to_gmsay = 0;
}
/* Set Defaults */ /* Set Defaults */
log_settings[Logs::World_Server].log_to_console = Logs::General; log_settings[Logs::World_Server].log_to_console = Logs::General;
@ -107,35 +106,29 @@ void EQEmuLogSys::LoadLogSettingsDefaults()
/* Declare process file names for log writing /* Declare process file names for log writing
If there is no process_file_name declared, no log file will be written, simply If there is no process_file_name declared, no log file will be written, simply
*/ */
if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformWorld){ if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformWorld)
platform_file_name = "world"; platform_file_name = "world";
} else if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformQueryServ)
if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformQueryServ){
platform_file_name = "query_server"; platform_file_name = "query_server";
} else if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformZone)
if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformZone){
platform_file_name = "zone"; platform_file_name = "zone";
} else if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformUCS)
if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformUCS){
platform_file_name = "ucs"; platform_file_name = "ucs";
} else if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformLogin)
if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformLogin){
platform_file_name = "login"; platform_file_name = "login";
} else if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformLogin)
if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformLogin){
platform_file_name = "launcher"; platform_file_name = "launcher";
}
} }
std::string EQEmuLogSys::FormatOutMessageString(uint16 log_category, std::string in_message){ std::string EQEmuLogSys::FormatOutMessageString(uint16 log_category, const std::string &in_message)
std::string category_string = ""; {
if (log_category > 0 && Logs::LogCategoryName[log_category]){ std::string category_string;
if (log_category > 0 && Logs::LogCategoryName[log_category])
category_string = StringFormat("[%s] ", Logs::LogCategoryName[log_category]); category_string = StringFormat("[%s] ", Logs::LogCategoryName[log_category]);
}
return StringFormat("%s%s", category_string.c_str(), in_message.c_str()); return StringFormat("%s%s", category_string.c_str(), in_message.c_str());
} }
void EQEmuLogSys::ProcessGMSay(uint16 debug_level, uint16 log_category, std::string message) void EQEmuLogSys::ProcessGMSay(uint16 debug_level, uint16 log_category, const std::string &message)
{ {
/* Check if category enabled for process */ /* Check if category enabled for process */
if (log_settings[log_category].log_to_gmsay == 0) if (log_settings[log_category].log_to_gmsay == 0)
@ -150,14 +143,13 @@ void EQEmuLogSys::ProcessGMSay(uint16 debug_level, uint16 log_category, std::str
return; return;
/* Check to see if the process that actually ran this is zone */ /* Check to see if the process that actually ran this is zone */
if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformZone){ if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformZone)
on_log_gmsay_hook(log_category, message); on_log_gmsay_hook(log_category, message);
}
} }
void EQEmuLogSys::ProcessLogWrite(uint16 debug_level, uint16 log_category, std::string message) void EQEmuLogSys::ProcessLogWrite(uint16 debug_level, uint16 log_category, const std::string &message)
{ {
if (log_category == Logs::Crash){ if (log_category == Logs::Crash) {
char time_stamp[80]; char time_stamp[80];
EQEmuLogSys::SetCurrentTimeStamp(time_stamp); EQEmuLogSys::SetCurrentTimeStamp(time_stamp);
std::ofstream crash_log; std::ofstream crash_log;
@ -178,9 +170,8 @@ void EQEmuLogSys::ProcessLogWrite(uint16 debug_level, uint16 log_category, std::
char time_stamp[80]; char time_stamp[80];
EQEmuLogSys::SetCurrentTimeStamp(time_stamp); EQEmuLogSys::SetCurrentTimeStamp(time_stamp);
if (process_log){ if (process_log)
process_log << time_stamp << " " << message << std::endl; process_log << time_stamp << " " << message << std::endl;
}
} }
uint16 EQEmuLogSys::GetWindowsConsoleColorFromCategory(uint16 log_category){ uint16 EQEmuLogSys::GetWindowsConsoleColorFromCategory(uint16 log_category){
@ -249,7 +240,7 @@ uint16 EQEmuLogSys::GetGMSayColorFromCategory(uint16 log_category){
} }
} }
void EQEmuLogSys::ProcessConsoleMessage(uint16 debug_level, uint16 log_category, std::string message) void EQEmuLogSys::ProcessConsoleMessage(uint16 debug_level, uint16 log_category, const std::string &message)
{ {
/* Check if category enabled for process */ /* Check if category enabled for process */
if (log_settings[log_category].log_to_console == 0) if (log_settings[log_category].log_to_console == 0)
@ -290,7 +281,8 @@ void EQEmuLogSys::Out(Logs::DebugLevel debug_level, uint16 log_category, std::st
EQEmuLogSys::ProcessLogWrite(debug_level, log_category, output_message); EQEmuLogSys::ProcessLogWrite(debug_level, log_category, output_message);
} }
void EQEmuLogSys::SetCurrentTimeStamp(char* time_stamp){ void EQEmuLogSys::SetCurrentTimeStamp(char* time_stamp)
{
time_t raw_time; time_t raw_time;
struct tm * time_info; struct tm * time_info;
time(&raw_time); time(&raw_time);
@ -298,10 +290,17 @@ void EQEmuLogSys::SetCurrentTimeStamp(char* time_stamp){
strftime(time_stamp, 80, "[%m-%d-%Y :: %H:%M:%S]", time_info); strftime(time_stamp, 80, "[%m-%d-%Y :: %H:%M:%S]", time_info);
} }
void EQEmuLogSys::MakeDirectory(std::string directory_name){ void EQEmuLogSys::MakeDirectory(const std::string &directory_name)
{
#ifdef _WINDOWS #ifdef _WINDOWS
struct _stat st;
if (_stat(directory_name.c_str(), &st) == 0) // exists
return;
_mkdir(directory_name.c_str()); _mkdir(directory_name.c_str());
#else #else
struct stat st;
if (stat(directory_name.c_str(), &st) == 0) // exists
return;
mkdir(directory_name.c_str(), 0755); mkdir(directory_name.c_str(), 0755);
#endif #endif
} }
@ -313,7 +312,7 @@ void EQEmuLogSys::CloseFileLogs()
} }
} }
void EQEmuLogSys::StartFileLogs(std::string log_name) void EQEmuLogSys::StartFileLogs(const std::string &log_name)
{ {
EQEmuLogSys::CloseFileLogs(); EQEmuLogSys::CloseFileLogs();
@ -321,23 +320,21 @@ void EQEmuLogSys::StartFileLogs(std::string log_name)
if (file_logs_enabled == false) if (file_logs_enabled == false)
return; return;
if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformZone){ if (EQEmuLogSys::log_platform == EQEmuExePlatform::ExePlatformZone) {
if (log_name != "") if (!log_name.empty())
platform_file_name = log_name; platform_file_name = log_name;
if (platform_file_name == ""){ if (platform_file_name.empty())
return; return;
}
EQEmuLogSys::Out(Logs::General, Logs::Status, "Starting File Log 'logs/%s_%i.log'", platform_file_name.c_str(), getpid()); EQEmuLogSys::Out(Logs::General, Logs::Status, "Starting File Log 'logs/%s_%i.log'", platform_file_name.c_str(), getpid());
EQEmuLogSys::MakeDirectory("logs/zone"); EQEmuLogSys::MakeDirectory("logs/zone");
process_log.open(StringFormat("logs/zone/%s_%i.log", platform_file_name.c_str(), getpid()), std::ios_base::app | std::ios_base::out); process_log.open(StringFormat("logs/zone/%s_%i.log", platform_file_name.c_str(), getpid()), std::ios_base::app | std::ios_base::out);
} } else {
else{ if (platform_file_name.empty())
if (platform_file_name == ""){
return; return;
}
EQEmuLogSys::Out(Logs::General, Logs::Status, "Starting File Log 'logs/%s_%i.txt'", platform_file_name.c_str(), getpid()); EQEmuLogSys::Out(Logs::General, Logs::Status, "Starting File Log 'logs/%s_%i.log'", platform_file_name.c_str(), getpid());
process_log.open(StringFormat("logs/%s_%i.txt", platform_file_name.c_str(), getpid()), std::ios_base::app | std::ios_base::out); process_log.open(StringFormat("logs/%s_%i.log", platform_file_name.c_str(), getpid()), std::ios_base::app | std::ios_base::out);
} }
} }

View File

@ -128,7 +128,7 @@ public:
void CloseFileLogs(); /* Close File Logs wherever necessary, either at zone shutdown or entire process shutdown for everything else. This should be handled on deconstructor but to be safe we use it anyways. */ void CloseFileLogs(); /* Close File Logs wherever necessary, either at zone shutdown or entire process shutdown for everything else. This should be handled on deconstructor but to be safe we use it anyways. */
void LoadLogSettingsDefaults(); /* Initializes log_settings and sets some defaults if DB is not present */ void LoadLogSettingsDefaults(); /* Initializes log_settings and sets some defaults if DB is not present */
void MakeDirectory(std::string directory_name); /* Platform independent way of performing a MakeDirectory based on name */ void MakeDirectory(const std::string &directory_name); /* Platform independent way of performing a MakeDirectory based on name */
/* /*
The one and only Logging function that uses a debug level as a parameter, as well as a log_category The one and only Logging function that uses a debug level as a parameter, as well as a log_category
log_category - defined in Logs::LogCategory::[] log_category - defined in Logs::LogCategory::[]
@ -140,7 +140,7 @@ public:
*/ */
void Out(Logs::DebugLevel debug_level, uint16 log_category, std::string message, ...); void Out(Logs::DebugLevel debug_level, uint16 log_category, std::string message, ...);
void SetCurrentTimeStamp(char* time_stamp); /* Used in file logs to prepend a timestamp entry for logs */ void SetCurrentTimeStamp(char* time_stamp); /* Used in file logs to prepend a timestamp entry for logs */
void StartFileLogs(std::string log_name = ""); /* Used to declare the processes file log and to keep it open for later use */ void StartFileLogs(const std::string &log_name = ""); /* Used to declare the processes file log and to keep it open for later use */
/* /*
LogSettings Struct LogSettings Struct
@ -172,19 +172,18 @@ public:
uint16 GetGMSayColorFromCategory(uint16 log_category); /* GMSay Client Message colors mapped by category */ uint16 GetGMSayColorFromCategory(uint16 log_category); /* GMSay Client Message colors mapped by category */
void OnLogHookCallBackZone(std::function<void(uint16 log_type, std::string&)> f) { on_log_gmsay_hook = f; } void OnLogHookCallBackZone(std::function<void(uint16 log_type, const std::string&)> f) { on_log_gmsay_hook = f; }
private: private:
std::function<void(uint16 log_category, const std::string&)> on_log_gmsay_hook; /* Callback pointer to zone process for hooking logs to zone using GMSay */
std::function<void(uint16 log_category, std::string&)> on_log_gmsay_hook; /* Callback pointer to zone process for hooking logs to zone using GMSay */ std::string FormatOutMessageString(uint16 log_category, const std::string &in_message); /* Formats log messages like '[Category] This is a log message' */
std::string FormatOutMessageString(uint16 log_category, std::string in_message); /* Formats log messages like '[Category] This is a log message' */
std::string GetLinuxConsoleColorFromCategory(uint16 log_category); /* Linux console color messages mapped by category */ std::string GetLinuxConsoleColorFromCategory(uint16 log_category); /* Linux console color messages mapped by category */
uint16 GetWindowsConsoleColorFromCategory(uint16 log_category); /* Windows console color messages mapped by category */ uint16 GetWindowsConsoleColorFromCategory(uint16 log_category); /* Windows console color messages mapped by category */
void ProcessConsoleMessage(uint16 debug_level, uint16 log_category, std::string message); /* ProcessConsoleMessage called via Log.Out */ void ProcessConsoleMessage(uint16 debug_level, uint16 log_category, const std::string &message); /* ProcessConsoleMessage called via Log.Out */
void ProcessGMSay(uint16 debug_level, uint16 log_category, std::string message); /* ProcessGMSay called via Log.Out */ void ProcessGMSay(uint16 debug_level, uint16 log_category, const std::string &message); /* ProcessGMSay called via Log.Out */
void ProcessLogWrite(uint16 debug_level, uint16 log_category, std::string message); /* ProcessLogWrite called via Log.Out */ void ProcessLogWrite(uint16 debug_level, uint16 log_category, const std::string &message); /* ProcessLogWrite called via Log.Out */
}; };
extern EQEmuLogSys Log; extern EQEmuLogSys Log;

View File

@ -258,15 +258,15 @@ public:
LinkedList<NPC_Emote_Struct*> NPCEmoteList; LinkedList<NPC_Emote_Struct*> NPCEmoteList;
void LoadTickItems(); void LoadTickItems();
uint32 GetSpawnKillCount(uint32 in_spawnid); uint32 GetSpawnKillCount(uint32 in_spawnid);
void UpdateHotzone(); void UpdateHotzone();
std::unordered_map<int, item_tick_struct> tick_items; std::unordered_map<int, item_tick_struct> tick_items;
// random object that provides random values for the zone // random object that provides random values for the zone
EQEmu::Random random; EQEmu::Random random;
static void GMSayHookCallBackProcess(uint16 log_category, std::string& message){ entity_list.MessageStatus(0, 80, Log.GetGMSayColorFromCategory(log_category), "%s", message.c_str()); } static void GMSayHookCallBackProcess(uint16 log_category, const std::string& message){ entity_list.MessageStatus(0, 80, Log.GetGMSayColorFromCategory(log_category), "%s", message.c_str()); }
//MODDING HOOKS //MODDING HOOKS
void mod_init(); void mod_init();