Browse Source

RenX.ExtraLogging:

* Added configuration option "PrintToConsole"
* Load now fails if it would do nothing (both file and console logging disabled).
* Now properly rehashses
pull/3/head
JustinAJ 10 years ago
parent
commit
3156430be9
  1. 33
      RenX.ExtraLogging/RenX_ExtraLogging.cpp
  2. 10
      RenX.ExtraLogging/RenX_ExtraLogging.h

33
RenX.ExtraLogging/RenX_ExtraLogging.cpp

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2014 Justin James. * Copyright (C) 2014-2015 Justin James.
* *
* This license must be preserved. * This license must be preserved.
* Any applications, libraries, or code which make any use of any * Any applications, libraries, or code which make any use of any
@ -22,10 +22,7 @@
RenX_ExtraLoggingPlugin::RenX_ExtraLoggingPlugin() RenX_ExtraLoggingPlugin::RenX_ExtraLoggingPlugin()
{ {
const Jupiter::CStringS logFile = Jupiter::IRC::Client::Config->get(STRING_LITERAL_AS_REFERENCE("RenX.ExtraLogging"), STRING_LITERAL_AS_REFERENCE("LogFile")); RenX_ExtraLoggingPlugin::init();
if (logFile.isEmpty() == false)
RenX_ExtraLoggingPlugin::file = fopen(logFile.c_str(), "a+b");
else RenX_ExtraLoggingPlugin::file = nullptr;
} }
RenX_ExtraLoggingPlugin::~RenX_ExtraLoggingPlugin() RenX_ExtraLoggingPlugin::~RenX_ExtraLoggingPlugin()
@ -34,8 +31,27 @@ RenX_ExtraLoggingPlugin::~RenX_ExtraLoggingPlugin()
fclose(RenX_ExtraLoggingPlugin::file); fclose(RenX_ExtraLoggingPlugin::file);
} }
int RenX_ExtraLoggingPlugin::OnRehash()
{
if (RenX_ExtraLoggingPlugin::file != nullptr)
fclose(RenX_ExtraLoggingPlugin::file);
return !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);
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::file = fopen(logFile.c_str(), "a+b");
else
RenX_ExtraLoggingPlugin::file = nullptr;
return RenX_ExtraLoggingPlugin::file != nullptr || RenX_ExtraLoggingPlugin::printToConsole;
}
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)
raw.println(stdout); raw.println(stdout);
if (RenX_ExtraLoggingPlugin::file != nullptr) if (RenX_ExtraLoggingPlugin::file != nullptr)
{ {
@ -50,11 +66,14 @@ void RenX_ExtraLoggingPlugin::RenX_OnRaw(RenX::Server *server, const Jupiter::Re
} }
} }
// Plugin instantiation and entry point. // Plugin instantiation and entry point.
RenX_ExtraLoggingPlugin pluginInstance; RenX_ExtraLoggingPlugin pluginInstance;
extern "C" __declspec(dllexport) bool load()
{
return pluginInstance.init();
}
extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin()
{ {
return &pluginInstance; return &pluginInstance;

10
RenX.ExtraLogging/RenX_ExtraLogging.h

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2014 Justin James. * Copyright (C) 2014-2015 Justin James.
* *
* This license must be preserved. * This license must be preserved.
* Any applications, libraries, or code which make any use of any * Any applications, libraries, or code which make any use of any
@ -28,13 +28,19 @@ public: // RenX::Plugin
public: // Jupiter::Plugin public: // Jupiter::Plugin
const Jupiter::ReadableString &getName() override { return name; } const Jupiter::ReadableString &getName() override { return name; }
int OnRehash() override;
public: // RenX_ExtraLoggingPlugin
bool init();
RenX_ExtraLoggingPlugin(); RenX_ExtraLoggingPlugin();
~RenX_ExtraLoggingPlugin(); ~RenX_ExtraLoggingPlugin();
private: private:
STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.ExtraLogging"); STRING_LITERAL_AS_NAMED_REFERENCE(name, "RenX.ExtraLogging");
FILE *file; // Replace with a Jupiter::File after making Jupiter::File. (Also remove constructor/destructor) bool printToConsole;
FILE *file;
}; };
#endif // _RENX_EXTRALOGGING_H_HEADER #endif // _RENX_EXTRALOGGING_H_HEADER
Loading…
Cancel
Save