|
@ -19,9 +19,11 @@ |
|
|
#include "Jupiter/INIFile.h" |
|
|
#include "Jupiter/INIFile.h" |
|
|
#include "RenX_ExtraLogging.h" |
|
|
#include "RenX_ExtraLogging.h" |
|
|
#include "RenX_Server.h" |
|
|
#include "RenX_Server.h" |
|
|
|
|
|
#include "RenX_Tags.h" |
|
|
|
|
|
|
|
|
RenX_ExtraLoggingPlugin::RenX_ExtraLoggingPlugin() |
|
|
RenX_ExtraLoggingPlugin::RenX_ExtraLoggingPlugin() |
|
|
{ |
|
|
{ |
|
|
|
|
|
RenX_ExtraLoggingPlugin::day = localtime(std::addressof<const time_t>(time(nullptr)))->tm_yday; |
|
|
RenX_ExtraLoggingPlugin::init(); |
|
|
RenX_ExtraLoggingPlugin::init(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -40,25 +42,60 @@ int RenX_ExtraLoggingPlugin::OnRehash() |
|
|
|
|
|
|
|
|
bool RenX_ExtraLoggingPlugin::init() |
|
|
bool RenX_ExtraLoggingPlugin::init() |
|
|
{ |
|
|
{ |
|
|
RenX_ExtraLoggingPlugin::printToConsole = Jupiter::IRC::Client::Config->getBool(STRING_LITERAL_AS_REFERENCE("RenX.ExtraLogging"), STRING_LITERAL_AS_REFERENCE("PrintToConsole"), true); |
|
|
RenX_ExtraLoggingPlugin::filePrefix = Jupiter::IRC::Client::Config->get(this->getName(), STRING_LITERAL_AS_REFERENCE("FilePrefix"), Jupiter::StringS::Format("[%.*s] %.*s", RenX::tags->timeTag.size(), RenX::tags->timeTag.ptr(), RenX::tags->serverPrefixTag.size(), RenX::tags->serverPrefixTag.ptr())); |
|
|
const Jupiter::CStringS logFile = Jupiter::IRC::Client::Config->get(STRING_LITERAL_AS_REFERENCE("RenX.ExtraLogging"), STRING_LITERAL_AS_REFERENCE("LogFile")); |
|
|
RenX_ExtraLoggingPlugin::consolePrefix = Jupiter::IRC::Client::Config->get(this->getName(), STRING_LITERAL_AS_REFERENCE("ConsolePrefix"), RenX_ExtraLoggingPlugin::filePrefix); |
|
|
if (logFile.isEmpty() == false) |
|
|
RenX_ExtraLoggingPlugin::newDayFmt = Jupiter::IRC::Client::Config->get(this->getName(), STRING_LITERAL_AS_REFERENCE("NewDayFormat"), Jupiter::StringS::Format("Time: %.*s", RenX::tags->dateTag.size(), RenX::tags->dateTag.ptr())); |
|
|
|
|
|
RenX_ExtraLoggingPlugin::printToConsole = Jupiter::IRC::Client::Config->getBool(this->getName(), STRING_LITERAL_AS_REFERENCE("PrintToConsole"), true); |
|
|
|
|
|
const Jupiter::CStringS logFile = Jupiter::IRC::Client::Config->get(this->getName(), STRING_LITERAL_AS_REFERENCE("LogFile")); |
|
|
|
|
|
|
|
|
|
|
|
RenX::sanitizeTags(RenX_ExtraLoggingPlugin::filePrefix); |
|
|
|
|
|
RenX::sanitizeTags(RenX_ExtraLoggingPlugin::consolePrefix); |
|
|
|
|
|
RenX::sanitizeTags(RenX_ExtraLoggingPlugin::newDayFmt); |
|
|
|
|
|
|
|
|
|
|
|
if (logFile.isNotEmpty()) |
|
|
RenX_ExtraLoggingPlugin::file = fopen(logFile.c_str(), "a+b"); |
|
|
RenX_ExtraLoggingPlugin::file = fopen(logFile.c_str(), "a+b"); |
|
|
else |
|
|
else |
|
|
RenX_ExtraLoggingPlugin::file = nullptr; |
|
|
RenX_ExtraLoggingPlugin::file = nullptr; |
|
|
|
|
|
|
|
|
return RenX_ExtraLoggingPlugin::file != nullptr || RenX_ExtraLoggingPlugin::printToConsole; |
|
|
return RenX_ExtraLoggingPlugin::file != nullptr || RenX_ExtraLoggingPlugin::printToConsole; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int RenX_ExtraLoggingPlugin::think() |
|
|
|
|
|
{ |
|
|
|
|
|
if (RenX_ExtraLoggingPlugin::file != nullptr && RenX_ExtraLoggingPlugin::newDayFmt.isNotEmpty()) |
|
|
|
|
|
{ |
|
|
|
|
|
int currentDay = localtime(std::addressof<const time_t>(time(nullptr)))->tm_yday; |
|
|
|
|
|
if (currentDay != RenX_ExtraLoggingPlugin::day) |
|
|
|
|
|
{ |
|
|
|
|
|
Jupiter::String line = RenX_ExtraLoggingPlugin::newDayFmt; |
|
|
|
|
|
RenX::processTags(line); |
|
|
|
|
|
line.println(RenX_ExtraLoggingPlugin::file); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void RenX_ExtraLoggingPlugin::RenX_OnRaw(RenX::Server *server, const Jupiter::ReadableString &raw) |
|
|
void RenX_ExtraLoggingPlugin::RenX_OnRaw(RenX::Server *server, const Jupiter::ReadableString &raw) |
|
|
{ |
|
|
{ |
|
|
if (RenX_ExtraLoggingPlugin::printToConsole) |
|
|
if (RenX_ExtraLoggingPlugin::printToConsole) |
|
|
|
|
|
{ |
|
|
|
|
|
if (RenX_ExtraLoggingPlugin::filePrefix.isNotEmpty()) |
|
|
|
|
|
{ |
|
|
|
|
|
Jupiter::StringS cPrefix = RenX_ExtraLoggingPlugin::filePrefix; |
|
|
|
|
|
RenX::processTags(cPrefix, server); |
|
|
|
|
|
cPrefix.print(stdout); |
|
|
|
|
|
fputc(' ', stdout); |
|
|
|
|
|
} |
|
|
raw.println(stdout); |
|
|
raw.println(stdout); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (RenX_ExtraLoggingPlugin::file != nullptr) |
|
|
if (RenX_ExtraLoggingPlugin::file != nullptr) |
|
|
{ |
|
|
{ |
|
|
const Jupiter::ReadableString &prefix = server->getPrefix(); |
|
|
if (RenX_ExtraLoggingPlugin::filePrefix.isNotEmpty()) |
|
|
if (prefix.size() != 0) |
|
|
|
|
|
{ |
|
|
{ |
|
|
prefix.print(RenX_ExtraLoggingPlugin::file); |
|
|
Jupiter::StringS fPrefix = RenX_ExtraLoggingPlugin::filePrefix; |
|
|
|
|
|
RenX::processTags(fPrefix, server); |
|
|
|
|
|
fPrefix.print(RenX_ExtraLoggingPlugin::file); |
|
|
fputc(' ', RenX_ExtraLoggingPlugin::file); |
|
|
fputc(' ', RenX_ExtraLoggingPlugin::file); |
|
|
} |
|
|
} |
|
|
raw.println(RenX_ExtraLoggingPlugin::file); |
|
|
raw.println(RenX_ExtraLoggingPlugin::file); |
|
|