From 4e515ae8a0f46ce6eafd246a3c08b8684f954b3c Mon Sep 17 00:00:00 2001 From: mrbesen Date: Tue, 26 Apr 2022 19:36:15 +0200 Subject: [PATCH] debuglog --- include/arg.h | 7 +++++++ lolautoaccept.pro | 2 ++ src/arg.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/main.cpp | 15 +++++++++++---- 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 include/arg.h create mode 100644 src/arg.cpp diff --git a/include/arg.h b/include/arg.h new file mode 100644 index 0000000..b0a0cff --- /dev/null +++ b/include/arg.h @@ -0,0 +1,7 @@ +#pragma once + +struct Args { + int debugLog = 0; // cast to bool later +}; + +Args parseArgs(int argc, char** argv); diff --git a/lolautoaccept.pro b/lolautoaccept.pro index e496825..f2d787c 100644 --- a/lolautoaccept.pro +++ b/lolautoaccept.pro @@ -23,6 +23,7 @@ defineReplace(prependAll) { } SOURCES += \ + src/arg.cpp \ src/config.cpp \ src/datadragon.cpp \ src/datadragonimagecache.cpp \ @@ -46,6 +47,7 @@ SOURCES += \ # mainwindow.cpp HEADERS += \ + include/arg.h \ include/config.h \ include/datadragon.h \ include/datadragonimagecache.h \ diff --git a/src/arg.cpp b/src/arg.cpp new file mode 100644 index 0000000..69bd0f6 --- /dev/null +++ b/src/arg.cpp @@ -0,0 +1,37 @@ +#include "arg.h" + +#include +#include + +Args parseArgs(int argc, char** argv) { + Args a; + + while (1) { + static struct option long_options[] = { + {"debug-log", no_argument, &a.debugLog, 1}, + {0, 0, 0, 0} + }; + /* getopt_long stores the option index here. */ + int option_index = 0; + + int c = getopt_long (argc, argv, "", long_options, &option_index); + + /* Detect the end of the options. */ + if (c == -1) break; + + switch (c) { + case 0: + /* If this option set a flag, do nothing else now. */ + break; + + case '?': + /* getopt_long already printed an error message. */ + break; + + default: + abort(); + } + } + + return a; +} diff --git a/src/main.cpp b/src/main.cpp index 3294a1c..c38a079 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include +#include "arg.h" #include "mainwindow.h" #include "lolautoaccept.h" @@ -29,19 +30,25 @@ static std::string getBaseString(char** argv) { int main(int argc, char** argv) { Log::init(); Log::setConsoleLogLevel(Log::Level::INFO); - // Log::addLogfile("log.txt", Log::Level::TRACE); #if __unix__ Log::setColoredOutput(true); #endif - Log::info << "Hello, World!"; - Log::note << "Using Locale: " << QLocale().name().toStdString(); - if(argc == 0) { Log::fatal << "arg[0] is not set"; return 1; } + Args args = parseArgs(argc, argv); + if(args.debugLog) { + Log::setConsoleLogLevel(Log::Level::TRACE); + Log::addLogfile("log.txt", Log::Level::TRACE); + Log::debug << "debug Log enabled"; + } + + Log::info << "Hello, World!"; + Log::note << "Using Locale: " << QLocale().name().toStdString(); + std::string base = getBaseString(argv); Log::info << "appbase: " << base; Matcher::setPathBase(base);