From 077df35a4d0ed518b6781708d0c0458714c441eb Mon Sep 17 00:00:00 2001 From: phl0 Date: Tue, 18 Jul 2017 15:31:23 +0200 Subject: [PATCH] Add cli parameter to disable file logging completely --- .gitignore | 4 +++- YSFParrot/YSFParrot.cpp | 32 +++++++++++++++++++++++--------- YSFParrot/YSFParrot.h | 3 ++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 44bad9c..525f188 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ Debug Release x64 -MMDVMHost *.o *.opendb *.bak @@ -14,3 +13,6 @@ MMDVMHost *.user *.VC.db .vs +YSFGateway/YSFGateway +YSFParrot/YSFParrot +YSFReflector/YSFReflector diff --git a/YSFParrot/YSFParrot.cpp b/YSFParrot/YSFParrot.cpp index 7939215..fe7717d 100644 --- a/YSFParrot/YSFParrot.cpp +++ b/YSFParrot/YSFParrot.cpp @@ -32,16 +32,22 @@ int main(int argc, char** argv) { if (argc == 1) { - ::fprintf(stderr, "Usage: YSFParrot [-d|--debug] \n"); + ::fprintf(stderr, "Usage: YSFParrot [-d|--debug] [-n|--nolog] \n"); return 1; } - unsigned int n = 1U; + int n = 1U; bool debug = false; - if (::strcmp(argv[1], "-d") == 0 || ::strcmp(argv[1], "--debug") == 0) { - debug = true; - n = 2U; + bool log = true; + + for (; n < argc-1; n++) { + if (::strcmp(argv[n], "-d") == 0 || ::strcmp(argv[n], "--debug") == 0) { + debug = true; + } + if (::strcmp(argv[n], "-n") == 0 || ::strcmp(argv[n], "--nolog") == 0) { + log = false; + } } unsigned int port = ::atoi(argv[n]); @@ -50,15 +56,16 @@ int main(int argc, char** argv) return 1; } - CYSFParrot parrot(port, debug); + CYSFParrot parrot(port, debug, log); parrot.run(); return 0; } -CYSFParrot::CYSFParrot(unsigned int port, bool debug) : +CYSFParrot::CYSFParrot(unsigned int port, bool debug, bool log) : m_port(port), -m_debug(debug) +m_debug(debug), +m_log(log) { } @@ -68,12 +75,19 @@ CYSFParrot::~CYSFParrot() void CYSFParrot::run() { - bool ret = ::LogInitialise(".", "YSFParrot", m_debug ? 1U : 2U, m_debug ? 1U : 2U); + int fileLevel = 0U; + if (m_log) { + fileLevel = m_debug ? 1U : 2U; + } + bool ret = ::LogInitialise(".", "YSFParrot", fileLevel, m_debug ? 1U : 2U); if (!ret) { ::fprintf(stderr, "YSFParrot: unable to open the log file\n"); return; } + LogInfo("Debug: %s", m_debug ? "Enabled" : "Disabled"); + LogInfo("Logging to file: %s", m_log ? "Enabled" : "Disabled"); + CParrot parrot(180U); CNetwork network(m_port); diff --git a/YSFParrot/YSFParrot.h b/YSFParrot/YSFParrot.h index eb11476..03f2b47 100644 --- a/YSFParrot/YSFParrot.h +++ b/YSFParrot/YSFParrot.h @@ -22,7 +22,7 @@ class CYSFParrot { public: - CYSFParrot(unsigned int port, bool debug); + CYSFParrot(unsigned int port, bool debug, bool log); ~CYSFParrot(); void run(); @@ -30,6 +30,7 @@ public: private: unsigned int m_port; bool m_debug; + bool m_log; }; #endif