aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2018-08-09 13:28:21 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2018-08-09 13:28:21 +0200
commit6b6a0c6d3c0d39afecd3c0c6bd0e0a4c006adc5f (patch)
treee0b122db2bdce454c006d1eecf9e7c64858df402
parent8420cb4c80521d100d5f92155b6295f342dae3e3 (diff)
downloadnextpnr-6b6a0c6d3c0d39afecd3c0c6bd0e0a4c006adc5f.tar.gz
nextpnr-6b6a0c6d3c0d39afecd3c0c6bd0e0a4c006adc5f.tar.bz2
nextpnr-6b6a0c6d3c0d39afecd3c0c6bd0e0a4c006adc5f.zip
Added quiet mode for logging
-rw-r--r--common/command.cc5
-rw-r--r--common/log.cc32
-rw-r--r--common/log.h6
3 files changed, 28 insertions, 15 deletions
diff --git a/common/command.cc b/common/command.cc
index 54111130..d5639e9a 100644
--- a/common/command.cc
+++ b/common/command.cc
@@ -84,6 +84,7 @@ po::options_description CommandHandler::getGeneralOptions()
po::options_description general("General options");
general.add_options()("help,h", "show help");
general.add_options()("verbose,v", "verbose output");
+ general.add_options()("quiet,q", "quiet mode, only errors displayed");
general.add_options()("debug", "debug output");
general.add_options()("force,f", "keep running after errors");
#ifndef NO_GUI
@@ -119,6 +120,10 @@ void CommandHandler::setupContext(Context *ctx)
ctx->debug = true;
}
+ if (vm.count("quiet")) {
+ log_quiet_warnings = true;
+ }
+
if (vm.count("force")) {
ctx->force = true;
}
diff --git a/common/log.cc b/common/log.cc
index 2625be05..c3e798b6 100644
--- a/common/log.cc
+++ b/common/log.cc
@@ -30,6 +30,8 @@
NEXTPNR_NAMESPACE_BEGIN
+void log_internal(const char *format, ...) NPNR_ATTRIBUTE(format(printf, 1, 2));
+
std::vector<FILE *> log_files;
std::vector<std::ostream *> log_streams;
FILE *log_errfile = NULL;
@@ -38,7 +40,6 @@ log_write_type log_write_function = nullptr;
bool log_error_stderr = false;
bool log_cmd_error_throw = false;
bool log_quiet_warnings = false;
-int log_verbose_level;
std::string log_last_error;
void (*log_error_atexit)() = NULL;
@@ -80,7 +81,7 @@ void logv(const char *format, va_list ap)
//
// Trim newlines from the beginning
while (format[0] == '\n' && format[1] != 0) {
- log("\n");
+ log_internal("\n");
format++;
}
@@ -108,7 +109,7 @@ void logv_info(const char *format, va_list ap)
{
std::string message = vstringf(format, ap);
- log("Info: %s", message.c_str());
+ log_internal("Info: %s", message.c_str());
log_flush();
}
@@ -116,7 +117,7 @@ void logv_warning(const char *format, va_list ap)
{
std::string message = vstringf(format, ap);
- log("Warning: %s", message.c_str());
+ log_internal("Warning: %s", message.c_str());
log_flush();
}
@@ -124,7 +125,7 @@ void logv_warning_noprefix(const char *format, va_list ap)
{
std::string message = vstringf(format, ap);
- log("%s", message.c_str());
+ log_internal("%s", message.c_str());
}
void logv_error(const char *format, va_list ap)
@@ -142,7 +143,7 @@ void logv_error(const char *format, va_list ap)
f = stderr;
log_last_error = vstringf(format, ap);
- log("ERROR: %s", log_last_error.c_str());
+ log_internal("ERROR: %s", log_last_error.c_str());
log_flush();
if (log_error_atexit)
@@ -154,8 +155,17 @@ void logv_error(const char *format, va_list ap)
throw log_execution_error_exception();
}
+void log_internal(const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ logv(format, ap);
+ va_end(ap);
+}
+
void log(const char *format, ...)
{
+ if (log_quiet_warnings) return;
va_list ap;
va_start(ap, format);
logv(format, ap);
@@ -164,6 +174,7 @@ void log(const char *format, ...)
void log_info(const char *format, ...)
{
+ if (log_quiet_warnings) return;
va_list ap;
va_start(ap, format);
logv_info(format, ap);
@@ -172,6 +183,7 @@ void log_info(const char *format, ...)
void log_warning(const char *format, ...)
{
+ if (log_quiet_warnings) return;
va_list ap;
va_start(ap, format);
logv_warning(format, ap);
@@ -180,6 +192,7 @@ void log_warning(const char *format, ...)
void log_warning_noprefix(const char *format, ...)
{
+ if (log_quiet_warnings) return;
va_list ap;
va_start(ap, format);
logv_warning_noprefix(format, ap);
@@ -200,7 +213,7 @@ void log_cmd_error(const char *format, ...)
if (log_cmd_error_throw) {
log_last_error = vstringf(format, ap);
- log("ERROR: %s", log_last_error.c_str());
+ log_internal("ERROR: %s", log_last_error.c_str());
log_flush();
throw log_cmd_error_exception();
}
@@ -210,10 +223,11 @@ void log_cmd_error(const char *format, ...)
void log_break()
{
+ if (log_quiet_warnings) return;
if (log_newline_count < 2)
- log("\n");
+ log_internal("\n");
if (log_newline_count < 2)
- log("\n");
+ log_internal("\n");
}
void log_flush()
diff --git a/common/log.h b/common/log.h
index 35450311..10de3c7c 100644
--- a/common/log.h
+++ b/common/log.h
@@ -48,15 +48,9 @@ extern FILE *log_errfile;
extern log_write_type log_write_function;
extern bool log_quiet_warnings;
-extern int log_verbose_level;
extern std::string log_last_error;
extern void (*log_error_atexit)();
-void logv(const char *format, va_list ap);
-void logv_warning(const char *format, va_list ap);
-void logv_warning_noprefix(const char *format, va_list ap);
-NPNR_NORETURN void logv_error(const char *format, va_list ap) NPNR_ATTRIBUTE(noreturn);
-
extern std::ostream clog;
void log(const char *format, ...) NPNR_ATTRIBUTE(format(printf, 1, 2));
void log_header(const char *format, ...) NPNR_ATTRIBUTE(format(printf, 1, 2));