Add ability to disable logging

This commit is contained in:
TotallyNotElite 2019-03-24 16:28:45 +01:00
parent acb8e9e210
commit 75fbce033b
5 changed files with 13 additions and 1 deletions

View File

@ -41,6 +41,7 @@ set(EnableTextmodeStdin 0 CACHE BOOL "Textmode Stdin -> Console bridge (EXPERIME
set(EnableWarnings 0 CACHE BOOL "Enable compile warnings")
set(EnableOnlineFeatures 0 CACHE BOOL "Enable online features (WIP)")
set(EnableIRC 1 CACHE BOOL "Enable IRC for messaging and ignore-cathook")
set(EnableLogging 1 CACHE BOOL "Enable logging to /tmp/")
if(NOT EnableVisuals)
set(EnableGUI 0)

View File

@ -18,3 +18,4 @@
#define ENABLE_PROFILER @EnableProfiler@
#define ENABLE_ONLINE @EnableOnlineFeatures@
#define ENABLE_IRC @EnableIRC@
#define ENABLE_LOGGING @EnableLogging@

View File

@ -19,15 +19,18 @@ static settings::Bool log_to_console{ "hack.log-console", "false" };
FILE *logging::handle{ nullptr };
#if ENABLE_LOGGING
void logging::Initialize()
{
// FIXME other method of naming the file?
passwd *pwd = getpwuid(getuid());
logging::handle = fopen(strfmt("/tmp/cathook-%s-%d.log", pwd->pw_name, getpid()).get(), "w");
}
#endif
void logging::Info(const char *fmt, ...)
{
#if ENABLE_LOGGING
if (logging::handle == nullptr)
logging::Initialize();
@ -61,10 +64,13 @@ void logging::Info(const char *fmt, ...)
g_ICvar->ConsoleColorPrintf(Color(*print_r, *print_g, *print_b, 255), "CAT: %s\n", result.get());
}
#endif
#endif
}
void logging::Shutdown()
{
#if ENABLE_LOGGING
fclose(logging::handle);
logging::handle = nullptr;
#endif
}

View File

@ -100,6 +100,7 @@ void hack::ExecuteCommand(const std::string &command)
hack::command_stack().push(command);
}
#if ENABLE_LOGGING
void critical_error_handler(int signum)
{
namespace st = boost::stacktrace;
@ -142,6 +143,7 @@ void critical_error_handler(int signum)
out.close();
::raise(SIGABRT);
}
#endif
static bool blacklist_file(const char *filename)
{
@ -205,8 +207,10 @@ static void InitRandom()
void hack::Initialize()
{
#if ENABLE_LOGGING
::signal(SIGSEGV, &critical_error_handler);
::signal(SIGABRT, &critical_error_handler);
#endif
time_injected = time(nullptr);
/*passwd *pwd = getpwuid(getuid());
char *logname = strfmt("/tmp/cathook-game-stdout-%s-%u.log", pwd->pw_name,

View File

@ -335,7 +335,7 @@ void party_leader_pass()
pc->GetCurrentPartyLeader(steamid);
if (steamid.GetAccountID() == g_ISteamUser->GetSteamID().GetAccountID())
{
std::vector<unsigned> valid_steam_ids = pc->GetPartySteamIDs();
std::vector<unsigned int> valid_steam_ids = pc->GetPartySteamIDs();
bool found = false;
for (auto &peer : irc.getPeers())
{