RULE_BOOL(Logging, EnableConsoleLogging, true) /* Turns on or off ALL logging to console */

RULE_BOOL(Logging, EnableFileLogging, true)	/* Turns on or off ALL forms of file logging */
This commit is contained in:
Akkadius 2015-01-10 23:26:10 -06:00
parent 2159a56b17
commit 108d3110b6
3 changed files with 60 additions and 11 deletions

View File

@ -25,7 +25,7 @@
#include <fstream>
#include <string>
#include <iomanip>
#include <time.h>
std::ofstream process_log;
@ -35,6 +35,8 @@ std::ofstream process_log;
#include <iostream>
#include <dos.h>
#include <windows.h>
#else
#include <sys/stat.h>
#endif
namespace Console {
@ -65,7 +67,18 @@ static const char* TypeNames[EQEmuLogSys::MaxLogID] = {
"Debug",
"Quest",
"Command",
"Crash"
"Crash",
"Save",
"UCS",
"Query Server",
"Socket Server",
"Spawns",
"AI",
"Pathing",
"Quests",
"Spells",
"Zone",
};
static Console::Color LogColors[EQEmuLogSys::MaxLogID] = {
Console::Color::Yellow, // "Status",
@ -86,7 +99,7 @@ EQEmuLogSys::~EQEmuLogSys(){
void EQEmuLogSys::StartZoneLogs(const std::string log_name)
{
_mkdir("logs/zone");
EQEmuLogSys::MakeDirectory("logs/zone");
std::cout << "Starting Zone Logs..." << std::endl;
process_log.open(StringFormat("logs/zone/%s.txt", log_name.c_str()), std::ios_base::app | std::ios_base::out);
}
@ -115,6 +128,22 @@ void EQEmuLogSys::LogDebug(DebugLevel debug_level, std::string message, ...)
EQEmuLogSys::Log(EQEmuLogSys::LogType::Debug, output_message);
}
void EQEmuLogSys::SetCurrentTimeStamp(char* time_stamp){
time_t raw_time;
struct tm * time_info;
time(&raw_time);
time_info = localtime(&raw_time);
strftime(time_stamp, 80, "[%d-%m-%Y :: %H:%M:%S]", time_info);
}
void EQEmuLogSys::MakeDirectory(std::string directory_name){
#ifdef _WINDOWS
_mkdir(directory_name.c_str());
#else
mkdir(directory_name.c_str());
#endif
}
void EQEmuLogSys::Log(uint16 log_type, const std::string message, ...)
{
if (log_type > EQEmuLogSys::MaxLogID){
@ -122,20 +151,25 @@ void EQEmuLogSys::Log(uint16 log_type, const std::string message, ...)
}
if (!RuleB(Logging, LogFileCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; }
if (!RuleB(Logging, EnableFileLogging)){
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, output_message);
char time_stamp[80];
EQEmuLogSys::SetCurrentTimeStamp(time_stamp);
if (process_log){
process_log << std::put_time(&tm, "[%d-%m-%Y :: %H:%M:%S] ") << StringFormat("[%s] ", TypeNames[log_type]).c_str() << output_message << std::endl;
process_log << time_stamp << " " << 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 " << "\n";
}
}
@ -144,6 +178,9 @@ void EQEmuLogSys::ConsoleMessage(uint16 log_type, const std::string message)
if (log_type > EQEmuLogSys::MaxLogID){
return;
}
if (!RuleB(Logging, EnableConsoleLogging)){
return;
}
if (!RuleB(Logging, ConsoleLogCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; }
#ifdef _WINDOWS
@ -155,10 +192,15 @@ void EQEmuLogSys::ConsoleMessage(uint16 log_type, const std::string message)
info.FontWeight = FW_NORMAL;
wcscpy(info.FaceName, L"Lucida Console");
SetCurrentConsoleFontEx(console_handle, NULL, &info);
SetConsoleTextAttribute(console_handle, LogColors[log_type]);
if (LogColors[log_type]){
SetConsoleTextAttribute(console_handle, LogColors[log_type]);
}
else{
SetConsoleTextAttribute(console_handle, Console::Color::White);
}
#endif
std::cout << "[N::" << TypeNames[log_type] << "] " << message << std::endl;
std::cout << "[N::" << TypeNames[log_type] << "] " << message << "\n";
#ifdef _WINDOWS
/* Always set back to white*/

View File

@ -45,12 +45,14 @@ public:
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 Log(uint16 log_type, const std::string message, ...);
void LogDebug(DebugLevel debug_level, std::string message, ...);
void LogDebugType(DebugLevel debug_level, uint16 log_type, std::string message, ...);
void Log(uint16 log_type, const std::string message, ...);
void MakeDirectory(std::string directory_name);
void SetCurrentTimeStamp(char* time_stamp);
void StartZoneLogs(const std::string log_name);

View File

@ -599,7 +599,12 @@ RULE_CATEGORY_END()
RULE_CATEGORY(Logging)
RULE_BOOL(Logging, ConsoleLogCommands, false) /* Turns on or off console logs */
RULE_BOOL(Logging, LogFileCommands, false)
RULE_INT(Logging, DebugLogLevel, 0) /* Sets Debug Level, -1 = OFF, 0 = Low Level, 1 = Info, 2 = Extreme */
RULE_BOOL(Logging, EnableConsoleLogging, true) /* Turns on or off ALL logging to console */
RULE_BOOL(Logging, EnableFileLogging, true) /* Turns on or off ALL forms of file logging */
RULE_CATEGORY_END()