Skip to content

Commit

Permalink
Get rid of some code duplication by extending AddLogging method with …
Browse files Browse the repository at this point in the history
…verbose and loglevel default overrides ('general' and LOG_INFO if nothing is set).

Note: This does not address the output of '-v help'.
  • Loading branch information
daniel-kristjansson committed Jul 25, 2011
1 parent 4314973 commit 406b361
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 51 deletions.
49 changes: 29 additions & 20 deletions mythtv/libs/libmythbase/mythcommandlineparser.cpp
Expand Up @@ -30,6 +30,7 @@ using namespace std;
#include "mythconfig.h"
#include "mythlogging.h"
#include "mythversion.h"
#include "logging.h"
#include "util.h"

const int kEnd = 0,
Expand Down Expand Up @@ -947,35 +948,43 @@ void MythCommandLineParser::addUPnP(void)
add("--noupnp", "noupnp", false, "Disable use of UPnP.", "");
}

void MythCommandLineParser::addLogging(void)
void MythCommandLineParser::addLogging(
const QString &defaultVerbosity, LogLevel_t defaultLogLevel)
{
defaultLogLevel =
((defaultLogLevel >= LOG_UNKNOWN) || (defaultLogLevel <= LOG_ANY)) ?
LOG_INFO : defaultLogLevel;

QString logLevelStr = logLevelGetName(defaultLogLevel);

add(QStringList( QStringList() << "-v" << "--verbose" ), "verbose",
"general",
"Specify log filtering. Use '-v help' for level info.", "");
defaultVerbosity,
"Specify log filtering. Use '-v help' for level info.", "");
add("-V", "verboseint", 0U, "",
"This option is intended for internal use only.\n"
"This option takes an unsigned value corresponding "
"to the bitwise log verbosity operator.");
"This option is intended for internal use only.\n"
"This option takes an unsigned value corresponding "
"to the bitwise log verbosity operator.");
add(QStringList( QStringList() << "-l" << "--logfile" << "--logpath" ),
"logpath", "",
"Writes logging messages to a file at logpath.\n"
"If a directory is given, a logfile will be created in that "
"directory with a filename of applicationName.date.pid.log.\n"
"If a full filename is given, that file will be used.\n"
"This is typically used in combination with --daemon, and if used "
"in combination with --pidfile, this can be used with log "
"rotaters, using the HUP call to inform MythTV to reload the "
"file (currently disabled).", "");
"logpath", "",
"Writes logging messages to a file at logpath.\n"
"If a directory is given, a logfile will be created in that "
"directory with a filename of applicationName.date.pid.log.\n"
"If a full filename is given, that file will be used.\n"
"This is typically used in combination with --daemon, and if used "
"in combination with --pidfile, this can be used with log "
"rotaters, using the HUP call to inform MythTV to reload the "
"file (currently disabled).", "");
add(QStringList( QStringList() << "-q" << "--quiet"), "quiet", 0,
"Don't log to the console (-q). Don't log anywhere (-q -q)", "");
add("--loglevel", "loglevel", "info",
"Don't log to the console (-q). Don't log anywhere (-q -q)", "");
add("--loglevel", "loglevel", logLevelStr,
QString(
"Set the logging level. All log messages at lower levels will be "
"discarded.\n"
"In descending order: emerg, alert, crit, err, warning, notice, "
"info, debug\ndefaults to info", "");
"info, debug\ndefaults to ") + logLevelStr, "");
add("--syslog", "syslog", "none",
"Set the syslog logging facility.\nSet to \"none\" to disable, "
"defaults to none", "");
"Set the syslog logging facility.\nSet to \"none\" to disable, "
"defaults to none", "");
add("--nodblog", "nodblog", false, "Disable database logging.", "");
}

Expand Down
3 changes: 2 additions & 1 deletion mythtv/libs/libmythbase/mythcommandlineparser.h
Expand Up @@ -162,7 +162,8 @@ class MBASE_PUBLIC MythCommandLineParser
void addGeometry(void);
void addDisplay(void);
void addUPnP(void);
void addLogging(void);
void addLogging(const QString &defaultVerbosity = "general",
LogLevel_t defaultLogLevel = LOG_INFO);
void addPIDFile(void);
void addJob(void);

Expand Down
31 changes: 1 addition & 30 deletions mythtv/programs/mythccextractor/commandlineparser.cpp
Expand Up @@ -12,36 +12,7 @@ void MythCCExtractorCommandLineParser::LoadArguments(void)
addHelp();
addSettingsOverride();
addVersion();

add(QStringList( QStringList() << "-v" << "--verbose" ), "verbose",
"none",
"Specify log filtering. Use '-v help' for level info.", "");
add("-V", "verboseint", 0U, "",
"This option is intended for internal use only.\n"
"This option takes an unsigned value corresponding "
"to the bitwise log verbosity operator.");
add(QStringList( QStringList() << "-l" << "--logfile" << "--logpath" ),
"logpath", "",
"Writes logging messages to a file at logpath.\n"
"If a directory is given, a logfile will be created in that "
"directory with a filename of applicationName.date.pid.log.\n"
"If a full filename is given, that file will be used.\n"
"This is typically used in combination with --daemon, and if used "
"in combination with --pidfile, this can be used with log "
"rotaters, using the HUP call to inform MythTV to reload the "
"file (currently disabled).", "");
add(QStringList( QStringList() << "-q" << "--quiet"), "quiet", 0,
"Don't log to the console (-q). Don't log anywhere (-q -q)", "");
add("--loglevel", "loglevel", "err",
"Set the logging level. All log messages at lower levels will be "
"discarded.\n"
"In descending order: emerg, alert, crit, err, warning, notice, "
"info, debug\ndefaults to err", "");
add("--syslog", "syslog", "none",
"Set the syslog logging facility.\nSet to \"none\" to disable, "
"defaults to none", "");
add("--nodblog", "nodblog", false, "Disable database logging.", "");

addLogging("none", LOG_ERR);
add(QStringList( QStringList() << "-i" << "--infile" ), "inputfile", "",
"input file", "");
}
Expand Down

0 comments on commit 406b361

Please sign in to comment.