+ loglevel = level;
+ debug_output (_f ("Log level set to %d\n", loglevel));
+}
+
+void
+set_loglevel (string level)
+{
+ /* Convert the loglevel string to lower-case, so we allow
+ both upper- and lower-case loglevels */
+ std::transform (level.begin (), level.end (), level.begin (), ::tolower);
+
+ /* Compare just the first few characters, so the loglevels
+ can be abbreviated */
+ if (level.compare (0, 5, "debug") == 0) // debug
+ set_loglevel (LOGLEVEL_DEBUG);
+ else if (level.compare (0, 4, "info") == 0) // info
+ set_loglevel (LOGLEVEL_INFO);
+ else if (level.compare (0, 4, "prog") == 0) // progress
+ set_loglevel (LOGLEVEL_PROGRESS);
+ else if (level.compare (0, 5, "basic") == 0) // basic progress
+ set_loglevel (LOGLEVEL_BASIC);
+ else if (level.compare (0, 4, "warn") == 0) // warning
+ set_loglevel (LOGLEVEL_WARN);
+ else if (level.compare (0, 3, "err") == 0) // error
+ set_loglevel (LOGLEVEL_ERROR);
+ else if (level.compare (0, 4, "none") == 0) // none
+ set_loglevel (LOGLEVEL_NONE);
+ else
+ {
+ int l;
+ if (sscanf (level.c_str (), "%d", &l))
+ set_loglevel (l);
+ else
+ {
+ non_fatal_error (_f ("unknown log level `%s', using default (INFO)",
+ level));
+ set_loglevel (LOGLEVEL_INFO);
+ }
+ }
+}
+
+/**
+ * Register a warning string to be expected and the output suppressed.
+ * If the warning is encountered, it will be removed from the list of
+ * expected warnings again.
+ */
+vector<string> expected_warnings;
+void expect_warning (const string &msg)
+{
+ expected_warnings.push_back (msg);
+}
+
+void check_expected_warnings ()
+{
+ if (expected_warnings.size () > 0)
+ {
+ /* Some expected warning was not triggered, so print out a warning. */
+ string msg = _f ("%d expected warning(s) not encountered: ",
+ expected_warnings.size ());
+ for (vsize i = 0; i < expected_warnings.size (); i++)
+ msg += "\n " + expected_warnings[i];
+
+ warning (msg);
+ }
+ expected_warnings.clear ();
+}