Logger tweaks
Commit amended for code style and minor cleanup by Adam Honse <calcprogrammer1@gmail.com>
This commit is contained in:
parent
0089852395
commit
f1d6c2953d
6 changed files with 387 additions and 125 deletions
108
cli.cpp
108
cli.cpp
|
|
@ -10,6 +10,7 @@
|
|||
#include "i2c_smbus.h"
|
||||
#include "NetworkClient.h"
|
||||
#include "NetworkServer.h"
|
||||
#include "LogManager.h"
|
||||
|
||||
/*-------------------------------------------------------------*\
|
||||
| Quirk for MSVC; which doesn't support this case-insensitive |
|
||||
|
|
@ -370,7 +371,7 @@ void OptionHelp()
|
|||
help_text += "-s, --size [0-N] Sets the new size of the specified device zone.\n";
|
||||
help_text += " Must be specified after specifying a zone.\n";
|
||||
help_text += " If the specified size is out of range, or the zone does not offer resizing capability, the size will not be changed\n";
|
||||
help_text += "-v, --version Display version and software build information\n";
|
||||
help_text += "-V, --version Display version and software build information\n";
|
||||
help_text += "-p, --profile filename.orp Load the profile from filename.orp\n";
|
||||
help_text += "-sp, --save-profile filename.orp Save the given settings to profile filename.orp\n";
|
||||
help_text += "--i2c-tools Shows the I2C/SMBus Tools page in the GUI. Implies --gui, even if not specified.\n";
|
||||
|
|
@ -380,6 +381,10 @@ void OptionHelp()
|
|||
help_text += "--config path Use a custom path instead of the global configuration directory.\n";
|
||||
help_text += "--nodetect Do not try to detect hardware at startup.\n";
|
||||
help_text += "--noautoconnect Do not try to autoconnect to a local server at startup.\n";
|
||||
help_text += "--loglevel Set the log level (0: critical to 6: debug).\n";
|
||||
help_text += "--print-source Print the source code file and line number for each log entry.\n";
|
||||
help_text += "-v, --verbose Print log messages to stdout.\n";
|
||||
help_text += "-vv, --very-verbose Print debug messages and log messages to stdout.\n";
|
||||
|
||||
std::cout << help_text << std::endl;
|
||||
}
|
||||
|
|
@ -951,6 +956,8 @@ unsigned int cli_pre_detection(int argc, char *argv[])
|
|||
std::string option = argv[arg_index];
|
||||
std::string argument = "";
|
||||
|
||||
LOG_DEBUG("Parsing CLI option: %s", option.c_str());
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Handle options that take an argument |
|
||||
\*---------------------------------------------------------*/
|
||||
|
|
@ -1087,6 +1094,75 @@ unsigned int cli_pre_detection(int argc, char *argv[])
|
|||
arg_index++;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| --loglevel |
|
||||
\*---------------------------------------------------------*/
|
||||
else if(option == "--loglevel")
|
||||
{
|
||||
if (argument != "")
|
||||
{
|
||||
try
|
||||
{
|
||||
int level = std::stoi(argument);
|
||||
if (level >= 0 && level <= LL_DEBUG)
|
||||
{
|
||||
LogManager::get()->setLoglevel(level);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Error: Loglevel out of range: " << level << " (0-6)" << std::endl;
|
||||
print_help = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(std::invalid_argument& e)
|
||||
{
|
||||
if(!strcasecmp(argument.c_str(), "critical"))
|
||||
{
|
||||
LogManager::get()->setLoglevel(LL_CRITICAL);
|
||||
}
|
||||
else if(!strcasecmp(argument.c_str(), "error"))
|
||||
{
|
||||
LogManager::get()->setLoglevel(LL_ERROR);
|
||||
}
|
||||
else if(!strcasecmp(argument.c_str(), "message"))
|
||||
{
|
||||
LogManager::get()->setLoglevel(LL_MESSAGE);
|
||||
}
|
||||
else if(!strcasecmp(argument.c_str(), "warning"))
|
||||
{
|
||||
LogManager::get()->setLoglevel(LL_WARNING);
|
||||
}
|
||||
else if(!strcasecmp(argument.c_str(), "notice"))
|
||||
{
|
||||
LogManager::get()->setLoglevel(LL_NOTICE);
|
||||
}
|
||||
else if(!strcasecmp(argument.c_str(), "verbose"))
|
||||
{
|
||||
LogManager::get()->setLoglevel(LL_VERBOSE);
|
||||
}
|
||||
else if(!strcasecmp(argument.c_str(), "debug"))
|
||||
{
|
||||
LogManager::get()->setLoglevel(LL_DEBUG);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Error: invalid loglevel" << std::endl;
|
||||
print_help = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Error: Missing argument for --server-port" << std::endl;
|
||||
print_help = true;
|
||||
break;
|
||||
}
|
||||
cfg_args++;
|
||||
arg_index++;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| --gui (no arguments) |
|
||||
\*---------------------------------------------------------*/
|
||||
|
|
@ -1104,7 +1180,7 @@ unsigned int cli_pre_detection(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| --startminimized |
|
||||
| --startminimized (no arguments) |
|
||||
\*---------------------------------------------------------*/
|
||||
else if(option == "--startminimized")
|
||||
{
|
||||
|
|
@ -1121,14 +1197,38 @@ unsigned int cli_pre_detection(int argc, char *argv[])
|
|||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| -v / --version (no arguments) |
|
||||
| -V / --version (no arguments) |
|
||||
\*---------------------------------------------------------*/
|
||||
else if(option == "--version" || option == "-v")
|
||||
else if(option == "--version" || option == "-V")
|
||||
{
|
||||
OptionVersion();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| -v / --verbose (no arguments) |
|
||||
\*---------------------------------------------------------*/
|
||||
else if(option == "--verbose" || option == "-v")
|
||||
{
|
||||
LogManager::get()->setVerbosity(LL_VERBOSE);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| -vv / --very-verbose (no arguments) |
|
||||
\*---------------------------------------------------------*/
|
||||
else if(option == "--very-verbose" || option == "-vv")
|
||||
{
|
||||
LogManager::get()->setVerbosity(LL_DEBUG);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| --print-source (no arguments) |
|
||||
\*---------------------------------------------------------*/
|
||||
else if(option == "--print-source")
|
||||
{
|
||||
LogManager::get()->setPrintSource(true);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------*\
|
||||
| Any unrecognized arguments trigger the post-detection CLI |
|
||||
\*---------------------------------------------------------*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue