From b2f52824b30cfb4abd3bf70f77eb502cc93070ad Mon Sep 17 00:00:00 2001 From: Daniel Wolf Date: Wed, 13 Sep 2017 20:39:52 +0200 Subject: [PATCH] Added --consoleLevel option. Default value is ERROR, not WARN. --- README.adoc | 15 ++++++++++++++- VERSION.md | 2 ++ src/rhubarb/main.cpp | 24 ++++++++++++++---------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/README.adoc b/README.adoc index a2c01c2..5963387 100644 --- a/README.adoc +++ b/README.adoc @@ -151,9 +151,12 @@ The following command-line options can be helpful in special situations, especia |=== | Option | Description +[[quiet]] | `-q`, `--quiet` | By default, Rhubarb Lip Sync writes a number of progress messages to `stderr`. If you're using it as part of a batch process, this may clutter your console. If you specify the `--quiet` flag, there won't be any output to `stderr` unless an error occurred. +You can combine this option with the <> option to change the minimum event level that is printed to `stderr`. + | `--machineReadable` a| This option is useful if you want to integrate Rhubarb Lip Sync with another (possibly graphical) application. All progress output to `stderr` will be in structured JSON format, allowing your program to parse the output and display a graphical progress bar or something similar. @@ -163,6 +166,8 @@ In this mode, each line printed to `stderr` will be an object in JSON format. Ev * Event-specific structured data. For instance, a `"progress"` event contains the property `value` with a numeric value between 0.0 and 1.0. * Property `log`: A log message describing the event, plus severity information. If you aren't interested in the structured data, you can display this as a fallback. For instance, a `"progress"` event with the structured information `"value": 0.69` may contain the following redundant log message: `"Progress: 69%"`. +You can combine this option with the <> option. Note, however, that this only affects unstructured events of type `"log"` (not to be confused with the `log` property each event contains). + The following is an example output from a _successful_ run: [source,json] @@ -192,11 +197,19 @@ Note that the output format <>. That means that th * Changes in JSON formatting, such as a re-ordering of properties or changes in whitespaces (except for line breaks -- every event will remain on a singe line.) * Fewer or more events of type `"log"` or changes in the wording of log messages +[[consoleLevel]] +| `--consoleLevel` __ +| Sets the log level for reporting to the console (`stderr`). Options: `trace`, `debug`, `info`, `warning`, `error`, `fatal`. + +If <> is also specified, only events with the specified level or higher will be printed. Otherwise, a small number of essential events (startup, progress, etc.) will be printed even if their levels are below the specified value. + +_Default value: ``error``_ + | `--logFile` __ | Creates a log file with diagnostic information at the specified path. |`--logLevel` __ -| Sets the log level for the log file. Options: `trace`, `debug`, `info`, `warning`, `error`, `fatal`. +| Sets the log level for the log file. Only events with the specified level or higher will be logged. Options: `trace`, `debug`, `info`, `warning`, `error`, `fatal`. _Default value: ``debug``_ diff --git a/VERSION.md b/VERSION.md index 4ddd3a1..e0a5b74 100644 --- a/VERSION.md +++ b/VERSION.md @@ -4,6 +4,8 @@ * Full Unicode support. File names, dialog files, strings in exported files etc. should now be fully Unicode-compatible. * Added `--machineReadable` command-line option to allow for better integration with other applications. +* Added `--consoleLevel` command-line option to control how much detail to log to the console (`stderr`). +* Unless specified using `--consoleLevel`, only errors and fatal errors are printed to the console. Previously, warnings were also printed. ## Version 1.6.0 diff --git a/src/rhubarb/main.cpp b/src/rhubarb/main.cpp index 2050ed9..5a6caa2 100644 --- a/src/rhubarb/main.cpp +++ b/src/rhubarb/main.cpp @@ -93,8 +93,8 @@ ShapeSet getTargetShapeSet(const string& extendedShapesString) { int main(int platformArgc, char *platformArgv[]) { // Set up default logging so early errors are printed to stdout - const logging::Level minStderrLevel = logging::Level::Warn; - shared_ptr defaultSink = std::make_shared(minStderrLevel); + const logging::Level defaultMinStderrLevel = logging::Level::Error; + shared_ptr defaultSink = make_shared(defaultMinStderrLevel); logging::addSink(defaultSink); // Use UTF-8 throughout @@ -112,8 +112,9 @@ int main(int platformArgc, char *platformArgv[]) { tclap::ValueArg outputFileName("o", "output", "The output file path.", false, string(), "string", cmd); auto logLevels = vector(logging::LevelConverter::get().getValues()); tclap::ValuesConstraint logLevelConstraint(logLevels); - tclap::ValueArg logLevel("", "logLevel", "The minimum log level to log", false, logging::Level::Debug, &logLevelConstraint, cmd); + tclap::ValueArg logLevel("", "logLevel", "The minimum log level that will be written to the log file", false, logging::Level::Debug, &logLevelConstraint, cmd); tclap::ValueArg logFileName("", "logFile", "The log file path.", false, string(), "string", cmd); + tclap::ValueArg consoleLevel("", "consoleLevel", "The minimum log level that will be printed on the console (stderr)", false, defaultMinStderrLevel, &logLevelConstraint, cmd); tclap::SwitchArg machineReadableMode("", "machineReadable", "Formats all output to stderr in a structured JSON format.", cmd, false); tclap::SwitchArg quietMode("q", "quiet", "Suppresses all output to stderr except for warnings and error messages.", cmd, false); tclap::ValueArg maxThreadCount("", "threads", "The maximum number of worker threads to use.", false, getProcessorCoreCount(), "number", cmd); @@ -133,17 +134,20 @@ int main(int platformArgc, char *platformArgv[]) { } // Set up logging + // ... to stderr + if (quietMode.getValue()) { + logging::addSink(make_shared(consoleLevel.getValue())); + } else if (machineReadableMode.getValue()) { + logging::addSink(make_shared(consoleLevel.getValue())); + } else { + logging::addSink(make_shared(consoleLevel.getValue())); + } + logging::removeSink(defaultSink); + // ... to log file if (logFileName.isSet()) { auto fileSink = createFileSink(path(logFileName.getValue()), logLevel.getValue()); logging::addSink(fileSink); } - if (quietMode.getValue()) { - logging::removeSink(defaultSink); - logging::addSink(make_shared(minStderrLevel)); - } else if (machineReadableMode.getValue()) { - logging::removeSink(defaultSink); - logging::addSink(make_shared(minStderrLevel)); - } // Validate and transform command line arguments if (maxThreadCount.getValue() < 1) {