Browse Source

Added options to RenX.ExtraLogging:

* FilePrefix
* ConsolePrefix
* NewDayFormat
* PrintToConsole
pull/3/head
JustinAJ 10 years ago
parent
commit
cc584c02a9
  1. 49
      RenX.ExtraLogging/RenX_ExtraLogging.cpp
  2. 7
      RenX.ExtraLogging/RenX_ExtraLogging.h

49
RenX.ExtraLogging/RenX_ExtraLogging.cpp

@ -19,9 +19,11 @@
#include "Jupiter/INIFile.h"
#include "RenX_ExtraLogging.h"
#include "RenX_Server.h"
#include "RenX_Tags.h"
RenX_ExtraLoggingPlugin::RenX_ExtraLoggingPlugin()
{
RenX_ExtraLoggingPlugin::day = localtime(std::addressof<const time_t>(time(nullptr)))->tm_yday;
RenX_ExtraLoggingPlugin::init();
}
@ -40,25 +42,60 @@ int RenX_ExtraLoggingPlugin::OnRehash()
bool RenX_ExtraLoggingPlugin::init()
{
RenX_ExtraLoggingPlugin::printToConsole = Jupiter::IRC::Client::Config->getBool(STRING_LITERAL_AS_REFERENCE("RenX.ExtraLogging"), STRING_LITERAL_AS_REFERENCE("PrintToConsole"), true);
const Jupiter::CStringS logFile = Jupiter::IRC::Client::Config->get(STRING_LITERAL_AS_REFERENCE("RenX.ExtraLogging"), STRING_LITERAL_AS_REFERENCE("LogFile"));
if (logFile.isEmpty() == false)
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()));
RenX_ExtraLoggingPlugin::consolePrefix = Jupiter::IRC::Client::Config->get(this->getName(), STRING_LITERAL_AS_REFERENCE("ConsolePrefix"), RenX_ExtraLoggingPlugin::filePrefix);
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");
else
RenX_ExtraLoggingPlugin::file = nullptr;
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)
{
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);
}
if (RenX_ExtraLoggingPlugin::file != nullptr)
{
const Jupiter::ReadableString &prefix = server->getPrefix();
if (prefix.size() != 0)
if (RenX_ExtraLoggingPlugin::filePrefix.isNotEmpty())
{
prefix.print(RenX_ExtraLoggingPlugin::file);
Jupiter::StringS fPrefix = RenX_ExtraLoggingPlugin::filePrefix;
RenX::processTags(fPrefix, server);
fPrefix.print(RenX_ExtraLoggingPlugin::file);
fputc(' ', RenX_ExtraLoggingPlugin::file);
}
raw.println(RenX_ExtraLoggingPlugin::file);

7
RenX.ExtraLogging/RenX_ExtraLogging.h

@ -19,6 +19,7 @@
#define _RENX_EXTRALOGGING_H_HEADER
#include "Jupiter/Plugin.h"
#include "Jupiter/String.h"
#include "RenX_Plugin.h"
class RenX_ExtraLoggingPlugin : public RenX::Plugin
@ -29,6 +30,7 @@ public: // RenX::Plugin
public: // Jupiter::Plugin
const Jupiter::ReadableString &getName() override { return name; }
int OnRehash() override;
int think() override;
public: // RenX_ExtraLoggingPlugin
@ -39,8 +41,13 @@ public: // RenX_ExtraLoggingPlugin
private:
STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.ExtraLogging");
Jupiter::StringS filePrefix;
Jupiter::StringS consolePrefix;
Jupiter::StringS newDayFmt;
bool printToConsole;
FILE *file;
int day;
};
#endif // _RENX_EXTRALOGGING_H_HEADER
Loading…
Cancel
Save