mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-14 15:41:30 +00:00
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:
parent
2159a56b17
commit
108d3110b6
@ -25,7 +25,7 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
std::ofstream process_log;
|
std::ofstream process_log;
|
||||||
|
|
||||||
@ -35,6 +35,8 @@ std::ofstream process_log;
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <dos.h>
|
#include <dos.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Console {
|
namespace Console {
|
||||||
@ -65,7 +67,18 @@ static const char* TypeNames[EQEmuLogSys::MaxLogID] = {
|
|||||||
"Debug",
|
"Debug",
|
||||||
"Quest",
|
"Quest",
|
||||||
"Command",
|
"Command",
|
||||||
"Crash"
|
"Crash",
|
||||||
|
"Save",
|
||||||
|
"UCS",
|
||||||
|
"Query Server",
|
||||||
|
"Socket Server",
|
||||||
|
"Spawns",
|
||||||
|
"AI",
|
||||||
|
"Pathing",
|
||||||
|
"Quests",
|
||||||
|
"Spells",
|
||||||
|
"Zone",
|
||||||
|
|
||||||
};
|
};
|
||||||
static Console::Color LogColors[EQEmuLogSys::MaxLogID] = {
|
static Console::Color LogColors[EQEmuLogSys::MaxLogID] = {
|
||||||
Console::Color::Yellow, // "Status",
|
Console::Color::Yellow, // "Status",
|
||||||
@ -86,7 +99,7 @@ EQEmuLogSys::~EQEmuLogSys(){
|
|||||||
|
|
||||||
void EQEmuLogSys::StartZoneLogs(const std::string log_name)
|
void EQEmuLogSys::StartZoneLogs(const std::string log_name)
|
||||||
{
|
{
|
||||||
_mkdir("logs/zone");
|
EQEmuLogSys::MakeDirectory("logs/zone");
|
||||||
std::cout << "Starting Zone Logs..." << std::endl;
|
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);
|
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);
|
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, ...)
|
void EQEmuLogSys::Log(uint16 log_type, const std::string message, ...)
|
||||||
{
|
{
|
||||||
if (log_type > EQEmuLogSys::MaxLogID){
|
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, LogFileCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; }
|
||||||
|
|
||||||
|
if (!RuleB(Logging, EnableFileLogging)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, message);
|
va_start(args, message);
|
||||||
std::string output_message = vStringFormat(message.c_str(), args);
|
std::string output_message = vStringFormat(message.c_str(), args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
auto t = std::time(nullptr);
|
|
||||||
auto tm = *std::localtime(&t);
|
|
||||||
EQEmuLogSys::ConsoleMessage(log_type, output_message);
|
EQEmuLogSys::ConsoleMessage(log_type, output_message);
|
||||||
|
|
||||||
|
char time_stamp[80];
|
||||||
|
EQEmuLogSys::SetCurrentTimeStamp(time_stamp);
|
||||||
|
|
||||||
if (process_log){
|
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{
|
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){
|
if (log_type > EQEmuLogSys::MaxLogID){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!RuleB(Logging, EnableConsoleLogging)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!RuleB(Logging, ConsoleLogCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; }
|
if (!RuleB(Logging, ConsoleLogCommands) && log_type == EQEmuLogSys::LogType::Commands){ return; }
|
||||||
|
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
@ -155,10 +192,15 @@ void EQEmuLogSys::ConsoleMessage(uint16 log_type, const std::string message)
|
|||||||
info.FontWeight = FW_NORMAL;
|
info.FontWeight = FW_NORMAL;
|
||||||
wcscpy(info.FaceName, L"Lucida Console");
|
wcscpy(info.FaceName, L"Lucida Console");
|
||||||
SetCurrentConsoleFontEx(console_handle, NULL, &info);
|
SetCurrentConsoleFontEx(console_handle, NULL, &info);
|
||||||
|
if (LogColors[log_type]){
|
||||||
SetConsoleTextAttribute(console_handle, LogColors[log_type]);
|
SetConsoleTextAttribute(console_handle, LogColors[log_type]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
SetConsoleTextAttribute(console_handle, Console::Color::White);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::cout << "[N::" << TypeNames[log_type] << "] " << message << std::endl;
|
std::cout << "[N::" << TypeNames[log_type] << "] " << message << "\n";
|
||||||
|
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
/* Always set back to white*/
|
/* Always set back to white*/
|
||||||
|
|||||||
@ -48,9 +48,11 @@ public:
|
|||||||
|
|
||||||
void CloseZoneLogs();
|
void CloseZoneLogs();
|
||||||
void ConsoleMessage(uint16 log_type, const std::string message);
|
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 LogDebug(DebugLevel debug_level, std::string message, ...);
|
||||||
void LogDebugType(DebugLevel debug_level, uint16 log_type, 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);
|
void StartZoneLogs(const std::string log_name);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -599,7 +599,12 @@ RULE_CATEGORY_END()
|
|||||||
RULE_CATEGORY(Logging)
|
RULE_CATEGORY(Logging)
|
||||||
RULE_BOOL(Logging, ConsoleLogCommands, false) /* Turns on or off console logs */
|
RULE_BOOL(Logging, ConsoleLogCommands, false) /* Turns on or off console logs */
|
||||||
RULE_BOOL(Logging, LogFileCommands, false)
|
RULE_BOOL(Logging, LogFileCommands, false)
|
||||||
|
|
||||||
RULE_INT(Logging, DebugLogLevel, 0) /* Sets Debug Level, -1 = OFF, 0 = Low Level, 1 = Info, 2 = Extreme */
|
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()
|
RULE_CATEGORY_END()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user