mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
logger
add cli option for log level
This commit is contained in:
+9
-1
@@ -8,6 +8,7 @@
|
||||
#include <QCommandLineParser>
|
||||
#include <QProcess>
|
||||
#include <QUrl>
|
||||
#include "magic_enum/magic_enum.hpp"
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
#include <emscripten.h>
|
||||
@@ -26,7 +27,6 @@ void init_logger()
|
||||
spdlog::set_default_logger(logger);
|
||||
spdlog::set_pattern("[%H:%M:%S %z] [%^---%L---%$] %s:%# %!: %v");
|
||||
spdlog::flush_every(std::chrono::seconds(3));
|
||||
spdlog::set_level(spdlog::level::trace);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -56,9 +56,16 @@ int main(int argc, char *argv[])
|
||||
QCoreApplication::translate("main", "default"), QLatin1String(""));
|
||||
parser.addOption(default_sim_option);
|
||||
|
||||
QCommandLineOption log_option(QStringList() << "l"
|
||||
<< "log",
|
||||
QCoreApplication::translate("main", "Log level for the unisim server [default: trace]."),
|
||||
QCoreApplication::translate("main", "log"), QLatin1String("trace"));
|
||||
parser.addOption(log_option);
|
||||
|
||||
parser.process(a);
|
||||
// Initialize the logger
|
||||
init_logger();
|
||||
spdlog::set_level(magic_enum::enum_cast<spdlog::level::level_enum>(parser.value(log_option).toStdString()).value_or(spdlog::level::off));
|
||||
|
||||
QUrl url;
|
||||
url.setScheme("ws");
|
||||
@@ -94,6 +101,7 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
url.setPort(parser.value(port_option).toInt());
|
||||
QString default_sim = parser.value(default_sim_option);
|
||||
SPDLOG_INFO("Connecting client on {}", url.toString().toStdString());
|
||||
MainWindow w(url, default_sim);
|
||||
w.show();
|
||||
return a.exec();
|
||||
|
||||
+7
-1
@@ -6,6 +6,7 @@
|
||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
#include "magic_enum/magic_enum.hpp"
|
||||
#include "git_version.h"
|
||||
#include "simulators.hpp"
|
||||
|
||||
@@ -21,7 +22,6 @@ void init_logger()
|
||||
spdlog::set_default_logger(logger);
|
||||
spdlog::set_pattern("[%H:%M:%S %z] [%^---%L---%$] %s:%# %!: %v");
|
||||
spdlog::flush_every(std::chrono::seconds(3));
|
||||
spdlog::set_level(spdlog::level::trace);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -38,6 +38,10 @@ int main(int argc, char *argv[])
|
||||
<< "port",
|
||||
QCoreApplication::translate("main", "Port for the unisim server [default: 9002]."),
|
||||
QCoreApplication::translate("main", "port"), QLatin1String("9002"));
|
||||
QCommandLineOption log_option(QStringList() << "l"
|
||||
<< "log",
|
||||
QCoreApplication::translate("main", "Log level for the unisim server [default: trace]."),
|
||||
QCoreApplication::translate("main", "log"), QLatin1String("trace"));
|
||||
QCommandLineOption can_port0_option(QStringList() << "c" << "c0",
|
||||
QCoreApplication::translate("main", "CAN device 0."),
|
||||
QCoreApplication::translate("main", "can device 0."));
|
||||
@@ -54,6 +58,7 @@ int main(int argc, char *argv[])
|
||||
QCommandLineOption uart_port3_option(QStringList() << "u3", QCoreApplication::translate("main", "uart device 3."),
|
||||
QCoreApplication::translate("main", "uart device 3."));
|
||||
parser.addOption(port_option);
|
||||
parser.addOption(log_option);
|
||||
parser.addOption(can_port0_option);
|
||||
parser.addOption(can_port1_option);
|
||||
parser.addOption(can_port2_option);
|
||||
@@ -71,6 +76,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Initialize the logger
|
||||
init_logger();
|
||||
spdlog::set_level(magic_enum::enum_cast<spdlog::level::level_enum>(parser.value(log_option).toStdString()).value_or(spdlog::level::off));
|
||||
|
||||
// The server starts in this thread
|
||||
SPDLOG_INFO("Starting server");
|
||||
|
||||
Reference in New Issue
Block a user