aboutsummaryrefslogtreecommitdiffstats
path: root/common/log.cc
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 /common/log.cc
parent8420cb4c80521d100d5f92155b6295f342dae3e3 (diff)
downloadnextpnr-6b6a0c6d3c0d39afecd3c0c6bd0e0a4c006adc5f.tar.gz
nextpnr-6b6a0c6d3c0d39afecd3c0c6bd0e0a4c006adc5f.tar.bz2
nextpnr-6b6a0c6d3c0d39afecd3c0c6bd0e0a4c006adc5f.zip
Added quiet mode for logging
Diffstat (limited to 'common/log.cc')
-rw-r--r--common/log.cc32
1 files changed, 23 insertions, 9 deletions
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()