]> git.donarmstrong.com Git - lilypond.git/commitdiff
Proper loglevels: cmd-line option --loglevel=NONE/ERROR/WARN/BASIC/PROGRESS/DEBUG
authorReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 29 Jul 2011 17:52:41 +0000 (19:52 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Sun, 14 Aug 2011 12:55:10 +0000 (14:55 +0200)
Allow the user to specify which messages (s)he wants to see on stderr:
The lilypond code basically stays the same, I only added a loglevel
global variable, which is used in the warning/error*/progress*/success
functions (ly:warning, ly:error, etc. in Scheme). If the proper level
is not set for a message, it is not printed.

There are only some larger changes:
-) Global var be_verbose_global replaced by loglevel (in warn.cc, accessor
   is_loglevel(...);  much finer-grained)
-) New functions debug_output, which replaces code like:
   if (be_verbose_global) {
   progress_indication (...)
   }
-) Move all scheme log functions to warn-scheme.cc
-) Add (optional) source location info to warning/error/log messages

All changes were done to warn.cc and to the member of the Input class
(apparently, we have two parallel error-reporting "frameworks" in
lilypond...).

Note for all functions in warn.cc (not for the members of Input):
The debug_output function (and progress_indication and message) have
an optional argument to specify whether the output of the message
should always start on a new line or continue the previous output.

All functions of the Input class now are just a front-end for the functions
in warn.cc

Documentation for this new feature is still missing (both in the AU
as well as in the CG).

28 files changed:
flower/include/warn.hh
flower/warn.cc
input/regression/loglevels.ly [new file with mode: 0644]
lily/all-font-metrics.cc
lily/font-config-scheme.cc
lily/font-config.cc
lily/general-scheme.cc
lily/global-context-scheme.cc
lily/guile-init.cc
lily/includable-lexer.cc
lily/include/input.hh
lily/include/main.hh
lily/input.cc
lily/lexer.ll
lily/lily-guile.cc
lily/main.cc
lily/paper-score.cc
lily/performance.cc
lily/pfb-scheme.cc
lily/program-option-scheme.cc
lily/relocate.cc
lily/system.cc
lily/ttf.cc
lily/warn-scheme.cc [new file with mode: 0644]
scm/backend-library.scm
scm/define-note-names.scm
scm/lily-library.scm
scm/lily.scm

index 3c2a6dc0a9ad1b754cc9d349b96b262715422043..31ca381cb4bff6e269495becb125bd1728effbb0 100644 (file)
 
 #include "std-string.hh"
 
-void error (string s);
-void message (string s);
-void non_fatal_error (string);
-void programming_error (string s);
-void progress_indication (string s);
-void warning (string s);
-void successful (string s);
+/* Log-level bitmasks */
+#define LOG_NONE 0
+#define LOG_ERROR 1<<0
+#define LOG_WARN 1<<1
+#define LOG_BASIC 1<<2  // undocumented basic_progress, i.e. input file name and success
+#define LOG_PROGRESS 1<<3
+// Currently, there is no separation between progress and other info messages:
+#define LOG_INFO 1<<4
+#define LOG_DEBUG 1<<8
+
+/* Log-level definitions (or'ed bitmasks) */
+#define LOGLEVEL_NONE (LOG_NONE)
+#define LOGLEVEL_ERROR (LOG_ERROR)
+#define LOGLEVEL_WARN (LOGLEVEL_ERROR | LOG_WARN)
+#define LOGLEVEL_BASIC (LOGLEVEL_WARN | LOG_BASIC)
+#define LOGLEVEL_PROGRESS (LOGLEVEL_BASIC | LOG_PROGRESS)
+// Currently, there is no separation between progress and other info messages:
+#define LOGLEVEL_INFO (LOGLEVEL_PROGRESS | LOG_INFO)
+#define LOGLEVEL_DEBUG (LOGLEVEL_INFO | LOG_DEBUG)
+
+extern int loglevel;
+
+/* output messages, in decreasing order of importance */
+void error (string s, string location = ""); // Fatal error, exits lilypond!
+void programming_error (string s, string location = "");
+void non_fatal_error (string, string location = "");
+void warning (string s, string location = "");
+void successful (string s, string location = "");
+/* progress_indication does by default *NOT* start on a new line */
+void progress_indication (string s, bool newline = false, string location = "");
+void message (string s, bool newline = true, string location = "");
+void debug_output (string s, bool newline = true, string location = "");
+
+/* Helper functions that always print out the message. Callers should ensure
+   that the loglevel is obeyed */
+void print_message (int level, string location, string s, bool newline = true);
+
+bool is_loglevel (int level);
+void set_loglevel (int level);
+void set_loglevel (string level);
 
 #endif /* WARN_HH */
index 1c2f4ed134724bfb04c36fde2f380e7ce710cbf2..43eab1add7ec41120fde929b19c42009eb98d4fe 100644 (file)
 
 using namespace std;
 
-/* Is progress indication at NEWLINE?  */
-static bool progress_newline = true;
+/** We have several different loglevels, each with its own message function(s):
+      ERROR: error, non_fatal_error, programming_error
+      WARN: warning
+      BASIC_PROGRESS: success/...
+      PROGRESS: progress_indication
+      INFO: message
+      DEBUG: debug
+  All these functions check whether the corresponding loglevel bit is set
+  and print the message only if that's the case
+*/
+
+/* Define the loglevel (default is PROGRESS); for now, PROGRESS=INFO for a
+   all relevant output, so be on the safe side and use INFO as default, just
+   in case some output is generated with INFO */
+int loglevel = LOGLEVEL_INFO;
+
+bool
+is_loglevel (int level)
+{
+  // Check the bitmask containing the loglevel
+  return (loglevel & level);
+}
+
+void
+set_loglevel (int level)
+{
+  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 (PROGRESS)", 
+                               level));
+          set_loglevel (LOGLEVEL_INFO);
+        }
+    }
+}
+
+
+/**
+ * Helper functions: print_message_part (no newline prepended)
+ *                   print_message (always starts on a new line)
+ */
+
+/* Is output message at NEWLINE?  */
+static bool message_newline = true;
 
-/* Display user information that is not a full message.  */
+/* Display user information as a full message.
+   if newline is true, start the message on a new line.
+*/
 void
-progress_indication (string s)
+print_message (int level, string location, string s, bool newline)
 {
+  /* Only print the message if the current loglevel allows it: */
+  if (!is_loglevel (level))
+    return;
+  if (newline && !message_newline)
+    fputc ('\n', stderr);
+
   /* Test if all silly progress_indication ("\n") can be dropped now.  */
   if (s == "\n")
     return;
 
+  if (!location.empty ())
+    s = location + ": " + s;
   fputs (s.c_str (), stderr);
   fflush (stderr);
   if (s.length ())
-    progress_newline = s[s.length () - 1] == '\n';
+    message_newline = s[s.length () - 1] == '\n';
 }
 
-/* Display a single user message.  Always starts on a new line.  */
+
+/** The actual output functions to be called in lilypond code.
+ *  Sorted in descending order of importance (errors, warnings, progress, info,
+ *  debug). Each prints a message on a separate line.
+ */
+
+/* Display a fatal error message.  Also exits lilypond.  */
 void
-message (string s)
+error (string s, string location)
 {
-  if (!progress_newline)
-    fputc ('\n', stderr);
-  progress_indication (s);
+  print_message (LOG_ERROR, location, _f ("fatal error: %s", s) + "\n");
+  exit (1);
 }
 
-/* Display a success message.  Always starts on a new line.  */
+/* Display a severe programming error message, but don't exit.  */
 void
-successful (string s)
+programming_error (string s, string location)
 {
-  message (_f ("success: %s", s.c_str ()) + "\n");
+  print_message (LOG_ERROR, location, _f ("programming error: %s", s) + "\n");
+  print_message (LOG_ERROR, location, _ ("continuing, cross fingers") + "\n");
 }
 
-/* Display a warning message.  Always starts on a new line.  */
+/* Display a non-fatal error message, don't exit.  */
 void
-warning (string s)
+non_fatal_error (string s, string location)
 {
-  message (_f ("warning: %s", s.c_str ()) + "\n");
+  print_message (LOG_ERROR, location, _f ("error: %s", s) + "\n");
 }
 
+/* Display a warning message. */
 void
-non_fatal_error (string s)
+warning (string s, string location)
 {
-  message (_f ("error: %s", s.c_str ()) + "\n");
+  print_message (LOG_WARN, location, _f ("warning: %s", s) + "\n");
 }
 
-/* Display an error message.  Always starts on a new line.  */
+/* Display a success message.  */
 void
-error (string s)
+successful (string s, string location)
 {
-  non_fatal_error (s);
-  exit (1);
+  print_message (LOG_BASIC, location, _f ("success: %s", s) + "\n", true);
+}
+
+/* Display information about the progress.  */
+void
+progress_indication (string s, bool newline, string location)
+{
+  print_message (LOG_PROGRESS, location, s, newline);
 }
 
+/* Display a single info message.  */
 void
-programming_error (string s)
+message (string s, bool newline, string location)
 {
-  message (_f ("programming error: %s", s) + "\n");
-  message (_ ("continuing, cross fingers") + "\n");
+  // Use the progress loglevel for all normal messages (including progress msg)
+  print_message (LOG_INFO, location, s, newline);
 }
 
+/* Display a debug information, not necessarily on a new line.  */
+void
+debug_output (string s, bool newline, string location)
+{
+  print_message (LOG_DEBUG, location, s, newline);
+}
diff --git a/input/regression/loglevels.ly b/input/regression/loglevels.ly
new file mode 100644 (file)
index 0000000..af01de5
--- /dev/null
@@ -0,0 +1,41 @@
+\version "2.15.7"
+
+#(ly:set-option 'warning-as-error #f)
+
+\header{
+  texidoc="
+Test the different loglevels of lilypond. Run this file with --loglevel=NONE,
+ERROR, WARNING, PROGRESS, DEBUG to see the different loglevels. The errors
+are commented out. Comment them in to check the output manually.
+"
+}
+
+%%%% message functions of the Input class:
+#(display "\nMessage functions of the Input class:\n")
+
+messageTest = #(define-music-function (parser location) ()
+   (ly:input-message location "Test ly:input-message" )
+   (make-music 'Music))
+
+{
+%   #(display "-) Testing message\n")
+  \messageTest % message
+%   #(display "-) Testing warning\n")
+  c4( c( c) % warning
+%   #(display "-) Testing error\n")
+%   sr  % error
+}
+
+%%%% message functions in the warn.hh file:
+#(display "Message functions in the warn.hh file:\n")
+
+% #(display "-) Testing debug\n")
+#(ly:debug "Test debug\n")
+% #(display "-) Testing progress\n")
+#(ly:progress "Test progress\n")
+% #(display "-) Testing message\n")
+#(ly:message "Test message\n")
+% #(display "-) Testing warning\n")
+#(ly:warning "Test warning\n")
+% #(display "-) Testing error\n")
+% #(ly:error "Test error\n")
index d42811c0a7c096adfa1d9609fe8f9f77efa81e6a..25064f61b47e964d693423053e834a527488d4b6 100644 (file)
@@ -86,8 +86,7 @@ All_font_metrics::find_pango_font (PangoFontDescription const *description,
   SCM val;
   if (!pango_dict_->try_retrieve (key, &val))
     {
-      if (be_verbose_global)
-        progress_indication ("\n[" + string (pango_fn));
+      debug_output ("[" + string (pango_fn), true); // start on a new line
 
       Pango_font *pf = new Pango_font (pango_ft2_fontmap_,
                                        description,
@@ -98,8 +97,7 @@ All_font_metrics::find_pango_font (PangoFontDescription const *description,
       pango_dict_->set (key, val);
       pf->unprotect ();
 
-      if (be_verbose_global)
-        progress_indication ("]");
+      debug_output ("]", false);
 
       pf->description_ = scm_cons (SCM_BOOL_F,
                                    scm_from_double (1.0));
@@ -124,13 +122,11 @@ All_font_metrics::find_otf (string name)
       if (file_name.empty ())
         return 0;
 
-      if (be_verbose_global)
-        progress_indication ("\n[" + file_name);
+      debug_output ("[" + file_name, true); // start on a new line
 
       val = Open_type_font::make_otf (file_name);
 
-      if (be_verbose_global)
-        progress_indication ("]");
+      debug_output ("]", false);
 
       unsmob_metrics (val)->file_name_ = file_name;
       SCM name_string = ly_string2scm (name);
index 993e52568eb1ce6a631b7364355ebfbe7fec22e8..d5ecb4b39ac2da85f7bfee536175b6cedb52b776 100644 (file)
@@ -149,8 +149,8 @@ LY_DEFINE (ly_font_config_add_directory, "ly:font-config-add-directory", 1, 0, 0
 
   if (!FcConfigAppFontAddDir (0, (const FcChar8 *)d.c_str ()))
     error (_f ("failed adding font directory: %s", d.c_str ()));
-  else if (be_verbose_global)
-    message (_f ("adding font directory: %s", d.c_str ()));
+  else
+    debug_output (_f ("Adding font directory: %s", d.c_str ()));
 
   return SCM_UNSPECIFIED;
 }
@@ -165,8 +165,8 @@ LY_DEFINE (ly_font_config_add_font, "ly:font-config-add-font", 1, 0, 0,
 
   if (!FcConfigAppFontAddFile (0, (const FcChar8 *)f.c_str ()))
     error (_f ("failed adding font file: %s", f.c_str ()));
-  else if (be_verbose_global)
-    message (_f ("adding font file: %s", f.c_str ()));
+  else
+    debug_output (_f ("Adding font file: %s", f.c_str ()));
 
   return SCM_UNSPECIFIED;
 }
index 63cb66fc3519967e5e4b238bb9f85a8758e1b5e8..8ad36fbbabadb8edfa9a0a3db2d0b0bce3d1a143 100644 (file)
@@ -35,8 +35,7 @@ FcConfig *font_config_global = 0;
 void
 init_fontconfig ()
 {
-  if (be_verbose_global)
-    message (_ ("Initializing FontConfig..."));
+  debug_output (_ ("Initializing FontConfig..."));
 
   /* TODO: Find a way for Fontconfig to update its cache, if needed. */
   font_config_global = FcInitLoadConfig ();
@@ -52,18 +51,16 @@ init_fontconfig ()
       string dir = dirs[i];
       if (!FcConfigAppFontAddDir (font_config_global, (FcChar8 *)dir.c_str ()))
         error (_f ("failed adding font directory: %s", dir.c_str ()));
-      else if (be_verbose_global)
-        message (_f ("adding font directory: %s", dir.c_str ()));
+      else
+        debug_output (_f ("Adding font directory: %s", dir.c_str ()));
     }
 
-  if (be_verbose_global)
-    message (_ ("Building font database..."));
+  debug_output (_ ("Building font database..."));
 
   FcConfigBuildFonts (font_config_global);
   FcConfigSetCurrent (font_config_global);
 
-  if (be_verbose_global)
-    message ("\n");
+  debug_output ("\n");
 
 }
 
index fa838e3189c0a2bc7badd68987f7ef94e8a982da..e74bf0bf1627b2a8e96ed232d923194a9cd396c6 100644 (file)
@@ -40,6 +40,9 @@ using namespace std;
 #include "version.hh"
 #include "warn.hh"
 
+/* Declaration of log function(s) */
+SCM ly_progress (SCM, SCM);
+
 LY_DEFINE (ly_start_environment, "ly:start-environment",
            0, 0, 0, (),
            "Return the environment (a list of strings) that was in"
@@ -96,82 +99,6 @@ LY_DEFINE (ly_gulp_file, "ly:gulp-file",
   return scm_from_locale_stringn (contents.c_str (), contents.length ());
 }
 
-LY_DEFINE (ly_error, "ly:error",
-           1, 0, 1, (SCM str, SCM rest),
-           "A Scheme callable function to issue the error @var{str}."
-           "  The error is formatted with @code{format} and @var{rest}.")
-{
-  LY_ASSERT_TYPE (scm_is_string, str, 1);
-  str = scm_simple_format (SCM_BOOL_F, str, rest);
-  error (ly_scm2string (str));
-  return SCM_UNSPECIFIED;
-}
-
-LY_DEFINE (ly_message, "ly:message",
-           1, 0, 1, (SCM str, SCM rest),
-           "A Scheme callable function to issue the message @var{str}."
-           "  The message is formatted with @code{format} and @var{rest}.")
-{
-  LY_ASSERT_TYPE (scm_is_string, str, 1);
-  str = scm_simple_format (SCM_BOOL_F, str, rest);
-  message (ly_scm2string (str));
-  return SCM_UNSPECIFIED;
-}
-
-LY_DEFINE (ly_progress, "ly:progress",
-           1, 0, 1, (SCM str, SCM rest),
-           "A Scheme callable function to print progress @var{str}."
-           "  The message is formatted with @code{format} and @var{rest}.")
-{
-  LY_ASSERT_TYPE (scm_is_string, str, 1);
-  str = scm_simple_format (SCM_BOOL_F, str, rest);
-  progress_indication (ly_scm2string (str));
-  return SCM_UNSPECIFIED;
-}
-
-LY_DEFINE (ly_programming_error, "ly:programming-error",
-           1, 0, 1, (SCM str, SCM rest),
-           "A Scheme callable function to issue the internal warning"
-           "  @var{str}.  The message is formatted with @code{format}"
-           " and @var{rest}.")
-{
-  LY_ASSERT_TYPE (scm_is_string, str, 1);
-  str = scm_simple_format (SCM_BOOL_F, str, rest);
-
-  if (get_program_option ("warning-as-error"))
-    error (ly_scm2string (str));
-  else
-    programming_error (ly_scm2string (str));
-
-  return SCM_UNSPECIFIED;
-}
-
-LY_DEFINE (ly_success, "ly:success",
-           1, 0, 1, (SCM str, SCM rest),
-           "A Scheme callable function to issue a success message @var{str}."
-           "  The message is formatted with @code{format} and @var{rest}.")
-{
-  LY_ASSERT_TYPE (scm_is_string, str, 1);
-  str = scm_simple_format (SCM_BOOL_F, str, rest);
-  successful (ly_scm2string (str));
-  return SCM_UNSPECIFIED;
-
-}
-LY_DEFINE (ly_warning, "ly:warning",
-           1, 0, 1, (SCM str, SCM rest),
-           "A Scheme callable function to issue the warning @var{str}."
-           "  The message is formatted with @code{format} and @var{rest}.")
-{
-  LY_ASSERT_TYPE (scm_is_string, str, 1);
-  str = scm_simple_format (SCM_BOOL_F, str, rest);
-
-  if (get_program_option ("warning-as-error"))
-    error (ly_scm2string (str));
-  else
-    warning (ly_scm2string (str));
-
-  return SCM_UNSPECIFIED;
-}
 
 LY_DEFINE (ly_dir_p, "ly:dir?",
            1, 0, 0, (SCM s),
@@ -714,15 +641,11 @@ LY_DEFINE (ly_spawn, "ly:spawn",
 
   char *standard_output = 0;
   char *standard_error = 0;
-  int exit_status = be_verbose_global
-                    ? ly_run_command (argv, &standard_output, &standard_error)
-                    : ly_run_command (argv, 0, 0);
+  // Always get the pointer to the stdout/stderr messages
+  int exit_status = ly_run_command (argv, &standard_output, &standard_error);
 
-  if (be_verbose_global)
-    {
-      fprintf (stderr, "\n%s", standard_output);
-      fprintf (stderr, "%s", standard_error);
-    }
+  // Print out stdout and stderr only in debug mode
+  debug_output (string ("\n") + standard_output + standard_error, true);
 
   for (int i = 0; i < n; i++)
     free (argv[i]);
index 2b02da2b2a59603bc73c0438e929e3f8e00d76bd..eeda64521001681855dfa9ee04df5a7aa54a89f4 100644 (file)
@@ -123,8 +123,7 @@ LY_DEFINE (ly_interpret_music_expression, "ly:interpret-music-expression",
 
   send_stream_event (g, "Finish", 0, 0);
 
-  if (be_verbose_global)
-    message (_f ("elapsed time: %.2f seconds", timer.read ()));
+  debug_output (_f ("elapsed time: %.2f seconds", timer.read ()));
 
   return ctx;
 }
index df2f192538a648ca283ee96eef85ff6fee9cc279..e737dcf706f8877a8854f3cdb312d25a236dd99d 100644 (file)
@@ -43,12 +43,12 @@ ly_init_ly_module (void *)
   for (vsize i = scm_init_funcs_->size (); i--;)
     (scm_init_funcs_->at (i)) ();
 
-  if (be_verbose_global)
+  if (is_loglevel (LOG_DEBUG))
     {
-      progress_indication ("[");
+      debug_output ("[", true);
       scm_display (scm_c_eval_string ("(%search-load-path \"lily.scm\")"),
                    scm_current_error_port ());
-      progress_indication ("]\n");
+      debug_output ("]\n", false);
     }
 
   scm_primitive_load_path (scm_from_locale_string ("lily.scm"));
index 6fb6e2054cb70a3cef64205fd5197c245531b68f..15d52a3ae9b50368536bf60a38fc967053d23bad 100644 (file)
@@ -81,13 +81,8 @@ Includable_lexer::new_input (string name, Sources *sources)
   if (yy_current_buffer)
     state_stack_.push_back (yy_current_buffer);
 
-  if (be_verbose_global)
-    {
-      string spaces = "";
-      for (size_t i = 0; i < state_stack_.size (); i++)
-        spaces += " ";
-      progress_indication (string ("\n") + spaces + string ("[") + file->name_string ());
-    }
+  debug_output (string (state_stack_.size (), ' ') // indentation!
+                + string ("[") + file->name_string ());
 
   include_stack_.push_back (file);
 
@@ -109,13 +104,8 @@ Includable_lexer::new_input (string name, string data, Sources *sources)
   if (yy_current_buffer)
     state_stack_.push_back (yy_current_buffer);
 
-  if (be_verbose_global)
-    {
-      string spaces = "";
-      for (size_t i = 0; i < state_stack_.size (); i++)
-        spaces += " ";
-      progress_indication (string ("\n") + spaces + string ("[") + name);
-    }
+  debug_output (string (state_stack_.size (), ' ') // indentation!
+                + string ("[") + name);
   include_stack_.push_back (file);
 
   yy_switch_to_buffer (yy_create_buffer (file->get_istream (), YY_BUF_SIZE));
@@ -135,8 +125,7 @@ Includable_lexer::close_input ()
 {
   include_stack_.pop_back ();
   char_count_stack_.pop_back ();
-  if (be_verbose_global)
-    progress_indication ("]");
+  debug_output ("]", false);
   yy_delete_buffer (yy_current_buffer);
 #if HAVE_FLEXLEXER_YY_CURRENT_BUFFER
   yy_current_buffer = 0;
index af9dcff3e6b56280ba1c300a4dc80914c4ceb8c1..91c15df3299dba369b234c1e2de9d84ff0ffb1f0 100644 (file)
@@ -36,11 +36,12 @@ public:
   char const *end () const;
 
   void set (Source_file *, char const *, char const *);
-  void warning (string) const;
+  void error (string) const;
   void programming_error (string) const;
   void non_fatal_error (string) const;
-  void error (string) const;
+  void warning (string) const;
   void message (string) const;
+  void debug_output (string) const;
   void set_spot (Input const &);
   void step_forward ();
   void set_location (Input const &, Input const &);
@@ -60,6 +61,8 @@ public:
 
   Input (Input const &i);
   Input ();
+protected:
+  void print_message (int level, string s) const;
 };
 
 #include "smobs.hh"
index 8644a3ee17738f0bc488a2516a019bacb6d41b9a..7c21437b809581b791ecde72541ed4f34d7b15d4 100644 (file)
@@ -42,7 +42,6 @@ extern vector<string> start_environment_global;
 extern string output_backend_global;
 extern string output_name_global;
 extern bool be_safe_global;
-extern bool be_verbose_global;
 extern bool do_internal_type_checking_global;
 extern bool point_and_click_global;
 extern string lilypond_datadir;
index 6cc8a182a540bdc29ecfe96d763af0dcf70f42b3..292e06a44950fc623eab74d985faacd6f9534a39 100644 (file)
@@ -79,47 +79,61 @@ Input::set_location (Input const &i_start, Input const &i_end)
   [file:line:column:][warning:]message
 */
 void
-Input::message (string s) const
+Input::print_message (int level, string s) const
 {
+  string location;
   if (source_file_)
-    s = location_string () + ": " + s + "\n"
-        + source_file_->quote_input (start_) + "\n";
-  ::message (s);
+    ::print_message (level, location_string (),
+                     s + "\n" + source_file_->quote_input (start_) + "\n");
+  else
+    ::print_message (level, "", s);
+}
+
+void
+Input::error (string s) const
+{
+  print_message (LOG_ERROR, _f ("error: %s", s));
+  // UGH, fix naming or usage (use non_fatal_error in most places, instead)
+  // exit (1);
 }
 
 void
 Input::programming_error (string s) const
 {
   if (get_program_option ("warning-as-error"))
-    ::error (s);
+    error (s);
   else
     {
-      message (_f ("programming error: %s", s.c_str ()));
-      message (_ ("continuing, cross fingers") + "\n");
+      print_message (LOG_ERROR, _f ("programming error: %s", s));
+      print_message (LOG_ERROR, _ ("continuing, cross fingers") + "\n");
     }
 }
 
+void
+Input::non_fatal_error (string s) const
+{
+  print_message (LOG_ERROR, _f ("error: %s", s));
+}
+
 void
 Input::warning (string s) const
 {
   if (get_program_option ("warning-as-error"))
-    ::error (s);
+    error (s);
   else
-    message (_f ("warning: %s", s));
+    print_message (LOG_WARN, _f ("warning: %s", s));
 }
 
 void
-Input::error (string s) const
+Input::message (string s) const
 {
-  message (_f ("error: %s", s));
-  // UGH, fix naming or usage
-  // exit (1);
+  print_message (LOG_INFO, s);
 }
 
 void
-Input::non_fatal_error (string s) const
+Input::debug_output (string s) const
 {
-  message (_f ("error: %s", s));
+  print_message (LOG_DEBUG, s);
 }
 
 string
index 83a7940b6938dc634083fe9936ee389635713412..7cda144e263c9720868330a988904f7fd45dee89 100644 (file)
@@ -192,8 +192,7 @@ BOM_UTF8    \357\273\277
       LexerError (_ ("stray UTF-8 BOM encountered").c_str ());
       exit (1);
     }
-  if (be_verbose_global)
-     message (_ ("Skipping UTF-8 BOM"));
+  debug_output (_ ("Skipping UTF-8 BOM"));
 }
 
 <INITIAL,chords,figures,incl,lyrics,markup,notes>{
index 4d6f6a79c6440c331d54f090853cda0439243500..ff3f7064bf62d4666d8cc4c8193ea6b2cc8b33af 100644 (file)
@@ -92,14 +92,12 @@ gulp_file_to_string (string fn, bool must_exist, int size)
       return s;
     }
 
-  if (be_verbose_global)
-    progress_indication ("[" + s);
+  debug_output ("[" + s, true);
 
   vector<char> chars = gulp_file (s, size);
   string result (&chars[0], chars.size ());
 
-  if (be_verbose_global)
-    progress_indication ("]\n");
+  debug_output ("]\n", false);
 
   return result;
 }
index d0d21601ec500bb94d5e8a7f7a733f1accc39e94..33eb30af68d01f78e68c9fecb2e8fd0c7de2e9a2 100644 (file)
@@ -77,9 +77,6 @@ bool be_safe_global = false;
 /* Provide URI links to the original file */
 bool point_and_click_global = true;
 
-/* Verbose progress indication? */
-bool be_verbose_global = false;
-
 /* Scheme code to execute before parsing, after .scm init.
    This is where -e arguments are appended to.  */
 string init_scheme_code_global;
@@ -169,10 +166,16 @@ static Long_option_init options_static[]
     "and cd into DIR")
   },
 #endif
+  {
+    _i ("LOGLEVEL"), "loglevel", 'l', _i ("print log messages according to"
+    " LOGLEVEL.  Possible values are:\n"
+    "NONE, ERROR, WARNING, BASIC, PROGRESS (default) and DEBUG.")
+  },
   {_i ("FILE"), "output", 'o', _i ("write output to FILE (suffix will be added)")},
   {0, "relocate", 0, _i ("relocate using directory of lilypond program")},
+  {0, "silent", 's', _i ("no progress, only error messages (equivalent to loglevel=ERROR)")},
   {0, "version", 'v', _i ("show version number and exit")},
-  {0, "verbose", 'V', _i ("be verbose")},
+  {0, "verbose", 'V', _i ("be verbose (equivalent to loglevel=DEBUG)")},
   {0, "warranty", 'w', _i ("show warranty and copyright")},
   {0, 0, 0, 0}
 };
@@ -404,7 +407,7 @@ main_with_guile (void *, int, char **)
   prepend_load_path (lilypond_datadir);
   prepend_load_path (lilypond_datadir + "/scm");
 
-  if (be_verbose_global)
+  if (is_loglevel (LOG_DEBUG))
     dir_info (stderr);
 
   init_scheme_variables_global = "(list " + init_scheme_variables_global + ")";
@@ -556,7 +559,13 @@ parse_argv (int argc, char **argv)
           show_help = true;
           break;
         case 'V':
-          be_verbose_global = true;
+          set_loglevel (LOGLEVEL_DEBUG);
+          break;
+        case 's':
+          set_loglevel (LOGLEVEL_ERROR);
+          break;
+        case 'l':
+          set_loglevel (option_parser->optional_argument_str0_);
           break;
         default:
           programming_error (to_string ("unhandled short option: %c",
@@ -572,7 +581,7 @@ parse_argv (int argc, char **argv)
   if (show_help)
     {
       ly_usage ();
-      if (be_verbose_global)
+      if (is_loglevel (LOG_DEBUG))
         dir_info (stdout);
       exit (0);
     }
@@ -610,11 +619,13 @@ main (int argc, char **argv, char **envp)
     start_environment_global.push_back (*p);
 
   if (getenv ("LILYPOND_VERBOSE"))
-    be_verbose_global = true;
+    set_loglevel (LOGLEVEL_DEBUG);
+  if (getenv ("LILYPOND_LOGLEVEL"))
+    set_loglevel (getenv ("LILYPOND_LOGLEVEL"));
 
   setup_localisation ();
   parse_argv (argc, argv);
-  if (isatty (STDIN_FILENO))
+  if (isatty (STDIN_FILENO) && (is_loglevel (LOG_BASIC)))
     identify (stderr);
 
   setup_paths (argv[0]);
index c9c316026093054e88f4b9249ccbcda246135da3..7041ea61ae3b1af803350f6e653758f539ebac3a 100644 (file)
@@ -131,10 +131,9 @@ Paper_score::calc_breaking ()
 void
 Paper_score::process ()
 {
-  if (be_verbose_global)
-    message (_f ("Element count %d (spanners %d) ",
-                 system_->element_count (),
-                 system_->spanner_count ()));
+  debug_output (_f ("Element count %d (spanners %d) ",
+                    system_->element_count (),
+                    system_->spanner_count ()));
 
   message (_ ("Preprocessing graphical objects..."));
 
index 1bc547a5a8b9e987464fa6c5a70b7b76051f2d15..017b75619cb4b5424b040101e6fab6acc054f0d0 100644 (file)
@@ -51,17 +51,14 @@ Performance::output (Midi_stream &midi_stream) const
   int tracks_ = audio_staffs_.size ();
 
   midi_stream.write (Midi_header (1, tracks_, 384));
-  if (be_verbose_global)
-    progress_indication (_ ("Track...") + " ");
+  debug_output (_ ("Track...") + " ", false);
 
   for (vsize i = 0; i < audio_staffs_.size (); i++)
     {
       Audio_staff *s = audio_staffs_[i];
-      if (be_verbose_global)
-        progress_indication ("[" + to_string (i));
+      debug_output ("[" + to_string (i), true);
       s->output (midi_stream, i, ports_);
-      if (be_verbose_global)
-        progress_indication ("]");
+      debug_output ("]", false);
     }
 }
 
index 34d159cf044cc55dab725c2cc9418827822c0205..f8a6c1278f38ab7a530ef0d36533c1739401f889 100644 (file)
@@ -15,8 +15,7 @@ LY_DEFINE (ly_pfb_2_pfa, "ly:pfb->pfa",
 
   string file_name = ly_scm2string (pfb_file_name);
 
-  if (be_verbose_global)
-    progress_indication ("\n[" + file_name);
+  debug_output ("[" + file_name); // start message on a new line
 
   vector<char> pfb_string = gulp_file (file_name, 0);
   char *pfa = pfb2pfa ((Byte *) &pfb_string[0], pfb_string.size ());
@@ -24,8 +23,7 @@ LY_DEFINE (ly_pfb_2_pfa, "ly:pfb->pfa",
   SCM pfa_scm = scm_from_locale_string (pfa);
   free (pfa);
 
-  if (be_verbose_global)
-    progress_indication ("]");
+  debug_output ("]", false);
 
   return pfa_scm;
 }
@@ -38,8 +36,7 @@ LY_DEFINE (ly_otf_2_cff, "ly:otf->cff",
   LY_ASSERT_TYPE (scm_is_string, otf_file_name, 1);
 
   string file_name = ly_scm2string (otf_file_name);
-  if (be_verbose_global)
-    progress_indication ("\n[" + file_name);
+  debug_output ("[" + file_name); // start message on a new line
 
   FT_Face face = open_ft_face (file_name, 0 /* index */);
   string table = get_otf_table (face, "CFF ");
@@ -47,8 +44,7 @@ LY_DEFINE (ly_otf_2_cff, "ly:otf->cff",
   SCM asscm = scm_from_locale_stringn ((char *) table.data (),
                                        table.length ());
 
-  if (be_verbose_global)
-    progress_indication ("]");
+  debug_output ("]", false);
 
   return asscm;
 }
index 976d51062c2169eb872b307f363cd195edc2398b..1071d14d7d7f43497a23f0e666df906406b12326 100644 (file)
@@ -247,10 +247,10 @@ LY_DEFINE (ly_command_line_code, "ly:command-line-code", 0, 0, 0, (),
   return ly_string2scm (init_scheme_code_global);
 }
 
-LY_DEFINE (ly_command_line_verbose_p, "ly:command-line-verbose?", 0, 0, 0, (),
-           "Was @code{be_verbose_global} set?")
+LY_DEFINE (ly_verbose_output_p, "ly:verbose-output?", 0, 0, 0, (),
+           "Was verbose output requested, i.e. loglevel at least @code{DEBUG}?")
 {
-  return scm_from_bool (be_verbose_global);
+  return scm_from_bool (is_loglevel (LOG_DEBUG));
 }
 
 LY_DEFINE (ly_all_options, "ly:all-options",
index 964e02941db88d54fb7e1771fa8a2578395f8113..a4e75d2ae5e67da2954c984920a84ccb837b59cd 100644 (file)
@@ -49,9 +49,8 @@ sane_putenv (char const *key, string value, bool overwrite)
       string combine = string (key) + "=" + value;
       char *s = strdup (combine.c_str ());
 
-      if (be_verbose_global)
-        progress_indication (_f ("Setting %s to %s", key, value.c_str ())
-                             + "\n");
+      debug_output (_f ("Setting %s to %s", key, value.c_str ())
+                    + "\n");
 
       int retval = putenv (s);
       /*
@@ -69,7 +68,8 @@ set_env_file (char const *key, string value, bool overwrite = false)
 {
   if (is_file (value))
     return sane_putenv (key, value, overwrite);
-  else if (be_verbose_global)
+  else if (is_loglevel (LOG_DEBUG))
+    // this warning should only be printed in debug mode!
     warning (_f ("no such file: %s for %s", value, key));
   return -1;
 }
@@ -79,7 +79,8 @@ set_env_dir (char const *key, string value)
 {
   if (is_dir (value))
     return sane_putenv (key, value, false);
-  else if (be_verbose_global)
+  else if (is_loglevel (LOG_DEBUG))
+    // this warning should only be printed in debug mode!
     warning (_f ("no such directory: %s for %s", value, key));
   return -1;
 }
@@ -89,15 +90,15 @@ prepend_env_path (char const *key, string value)
 {
   if (is_dir (value))
     {
-      if (be_verbose_global)
-        progress_indication (_f ("%s=%s (prepend)\n", key, value.c_str ()));
+      debug_output (_f ("%s=%s (prepend)\n", key, value.c_str ()), false);
 
       if (char const *cur = getenv (key))
         value += to_string (PATHSEP) + cur;
 
       return sane_putenv (key, value.c_str (), true);
     }
-  else if (be_verbose_global)
+  else if (is_loglevel (LOG_DEBUG))
+    // this warning should only be printed in debug mode
     warning (_f ("no such directory: %s for %s", value, key));
   return -1;
 }
@@ -130,10 +131,9 @@ prefix_relocation (string prefix)
 
   prepend_env_path ("PATH", bindir);
 
-  if (be_verbose_global)
-    warning (_f ("Relocation: compile datadir=%s, new datadir=%s",
-                 old_lilypond_datadir.c_str (),
-                 lilypond_datadir.c_str ()));
+  debug_output (_f ("Relocation: compile datadir=%s, new datadir=%s",
+                    old_lilypond_datadir.c_str (),
+                    lilypond_datadir.c_str ()));
 }
 
 /*
@@ -143,8 +143,7 @@ prefix_relocation (string prefix)
 static void
 framework_relocation (string prefix)
 {
-  if (be_verbose_global)
-    warning (_f ("Relocation: framework_prefix=%s", prefix));
+  debug_output (_f ("Relocation: framework_prefix=%s", prefix));
 
   sane_putenv ("INSTALLER_PREFIX", prefix, true);
 
@@ -184,15 +183,13 @@ setup_paths (char const *argv0_ptr)
           if (argv0_filename.is_absolute ())
             {
               argv0_abs = argv0_filename.to_string ();
-              if (be_verbose_global)
-                warning (_f ("Relocation: is absolute: argv0=%s", argv0_ptr));
+              debug_output (_f ("Relocation: is absolute: argv0=%s\n", argv0_ptr));
             }
           else if (argv0_filename.dir_.length ())
             {
               argv0_abs = get_working_directory ()
                           + "/" + string (argv0_filename.to_string ());
-              if (be_verbose_global)
-                warning (_f ("Relocation: from cwd: argv0=%s", argv0_ptr));
+              debug_output (_f ("Relocation: from cwd: argv0=%s\n", argv0_ptr));
             }
           else
             {
@@ -208,9 +205,8 @@ setup_paths (char const *argv0_ptr)
               argv0_abs = path.find (argv0_filename.to_string (), ext);
 #endif /* __MINGW32__ */
 
-              if (be_verbose_global)
-                warning (_f ("Relocation: from PATH=%s\nargv0=%s",
-                             path.to_string ().c_str (), argv0_ptr));
+              debug_output (_f ("Relocation: from PATH=%s\nargv0=%s",
+                                path.to_string ().c_str (), argv0_ptr), true);
 
               if (argv0_abs.empty ())
                 programming_error ("cannot find absolute argv0");
@@ -361,10 +357,7 @@ read_line (FILE *f)
 void
 read_relocation_file (string filename)
 {
-  if (be_verbose_global)
-    progress_indication (_f ("Relocation file: %s", filename.c_str ())
-                         + "\n");
-
+  debug_output (_f ("Relocation file: %s", filename.c_str ()) + "\n");
   char const *cname = filename.c_str ();
   FILE *f = fopen (cname, "r");
   if (!f)
index 8a071cce90c9d89e6f88816eba4cfc43867ed0f1..5d3c0e33479e81ff608a7f8a92a14bd0beebcc09 100644 (file)
@@ -197,8 +197,7 @@ System::do_break_substitution_and_fixup_refpoints ()
         }
     }
 
-  if (be_verbose_global)
-    message (_f ("Element count %d", count + element_count ()) + "\n");
+  debug_output (_f ("Element count %d", count + element_count ()) + "\n");
 }
 
 SCM
@@ -216,16 +215,14 @@ System::get_paper_systems ()
   SCM lines = scm_c_make_vector (broken_intos_.size (), SCM_EOL);
   for (vsize i = 0; i < broken_intos_.size (); i++)
     {
-      if (be_verbose_global)
-        progress_indication ("[");
+      debug_output ("[", false);
 
       System *system = dynamic_cast<System *> (broken_intos_[i]);
 
       scm_vector_set_x (lines, scm_from_int (i),
                         system->get_paper_system ());
 
-      if (be_verbose_global)
-        progress_indication (to_string (i) + "]");
+      debug_output (to_string (i) + "]", false);
     }
   return lines;
 }
@@ -398,8 +395,7 @@ System::pre_processing ()
   for (vsize i = 0; i < all_elements_->size (); i++)
     all_elements_->grob (i)->discretionary_processing ();
 
-  if (be_verbose_global)
-    message (_f ("Grob count %d", element_count ()));
+  debug_output (_f ("Grob count %d", element_count ()));
 
   /*
     order is significant: broken grobs are added to the end of the
index 932f7a6c95050b42d375a5ef9171ddba184d52b8..18f1dcd0b663b4de2d0d89f547eb3171281b1ab8 100644 (file)
@@ -515,8 +515,7 @@ LY_DEFINE (ly_ttf_ps_name, "ly:ttf-ps-name",
     }
 
   string file_name = ly_scm2string (ttf_file_name);
-  if (be_verbose_global)
-    progress_indication ("\n[" + file_name);
+  debug_output ("\n[" + file_name, false);
 
   FT_Face face;
 
@@ -538,8 +537,7 @@ LY_DEFINE (ly_ttf_ps_name, "ly:ttf-ps-name",
   SCM ps_name = scm_from_locale_string (ps_name_str0 ? ps_name_str0 : "");
   FT_Done_Face (face);
 
-  if (be_verbose_global)
-    progress_indication ("]");
+  debug_output ("]", false);
 
   return ps_name;
 }
@@ -567,8 +565,7 @@ LY_DEFINE (ly_ttf_2_pfa, "ly:ttf->pfa",
     }
 
   string file_name = ly_scm2string (ttf_file_name);
-  if (be_verbose_global)
-    progress_indication ("\n[" + file_name);
+  debug_output ("[" + file_name); // Debug message should start on a new line
 
   Memory_out_stream stream;
 
@@ -576,8 +573,7 @@ LY_DEFINE (ly_ttf_2_pfa, "ly:ttf->pfa",
   SCM asscm = scm_from_locale_stringn (stream.get_string (),
                                        stream.get_length ());
 
-  if (be_verbose_global)
-    progress_indication ("]");
+  debug_output ("]", false);
 
   return asscm;
 }
diff --git a/lily/warn-scheme.cc b/lily/warn-scheme.cc
new file mode 100644 (file)
index 0000000..1587d7f
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+  This file is part of LilyPond, the GNU music typesetter.
+
+  Copyright (C) 1998--2011 Jan Nieuwenhuizen <janneke@gnu.org>
+  Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+  LilyPond is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  LilyPond is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "config.hh"
+
+#include "lily-guile.hh"
+#include "program-option.hh"
+#include "version.hh"
+#include "warn.hh"
+
+/*
+  Error / warning / progress / debug message output functions
+*/
+
+LY_DEFINE (ly_error, "ly:error",
+           1, 0, 1, (SCM str, SCM rest),
+           "A Scheme callable function to issue the error @var{str}."
+           "  The error is formatted with @code{format} and @var{rest}.")
+{
+  LY_ASSERT_TYPE (scm_is_string, str, 1);
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+  error (ly_scm2string (str));
+  return SCM_UNSPECIFIED;
+}
+
+LY_DEFINE (ly_programming_error, "ly:programming-error",
+           1, 0, 1, (SCM str, SCM rest),
+           "A Scheme callable function to issue the internal warning"
+           "  @var{str}.  The message is formatted with @code{format}"
+           " and @var{rest}.")
+{
+  LY_ASSERT_TYPE (scm_is_string, str, 1);
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+
+  if (get_program_option ("warning-as-error"))
+    error (ly_scm2string (str));
+  else
+    programming_error (ly_scm2string (str));
+
+  return SCM_UNSPECIFIED;
+}
+
+LY_DEFINE (ly_warning, "ly:warning",
+           1, 0, 1, (SCM str, SCM rest),
+           "A Scheme callable function to issue the warning @var{str}."
+           "  The message is formatted with @code{format} and @var{rest}.")
+{
+  LY_ASSERT_TYPE (scm_is_string, str, 1);
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+
+  if (get_program_option ("warning-as-error"))
+    error (ly_scm2string (str));
+  else
+    warning (ly_scm2string (str));
+
+  return SCM_UNSPECIFIED;
+}
+
+LY_DEFINE (ly_progress, "ly:progress",
+           1, 0, 1, (SCM str, SCM rest),
+           "A Scheme callable function to print progress @var{str}."
+           "  The message is formatted with @code{format} and @var{rest}.")
+{
+  LY_ASSERT_TYPE (scm_is_string, str, 1);
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+  // Calls to ly:progress should in general not start a new line
+  progress_indication (ly_scm2string (str), false);
+  return SCM_UNSPECIFIED;
+}
+
+LY_DEFINE (ly_success, "ly:success",
+           1, 0, 1, (SCM str, SCM rest),
+           "A Scheme callable function to issue a success message @var{str}."
+           "  The message is formatted with @code{format} and @var{rest}.")
+{
+  LY_ASSERT_TYPE (scm_is_string, str, 1);
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+  successful (ly_scm2string (str));
+  return SCM_UNSPECIFIED;
+}
+
+LY_DEFINE (ly_message, "ly:message",
+           1, 0, 1, (SCM str, SCM rest),
+           "A Scheme callable function to issue the message @var{str}."
+           "  The message is formatted with @code{format} and @var{rest}.")
+{
+  LY_ASSERT_TYPE (scm_is_string, str, 1);
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+  message (ly_scm2string (str));
+  return SCM_UNSPECIFIED;
+}
+
+LY_DEFINE (ly_debug, "ly:debug",
+           1, 0, 1, (SCM str, SCM rest),
+           "A Scheme callable function to issue a debug message @var{str}."
+           "  The message is formatted with @code{format} and @var{rest}.")
+{
+  // TODO: Add the newline flag!
+  LY_ASSERT_TYPE (scm_is_string, str, 1);
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+  debug_output (ly_scm2string (str));
+  return SCM_UNSPECIFIED;
+}
+
+LY_DEFINE (ly_warning_located, "ly:warning-located",
+           2, 0, 1, (SCM location, SCM str, SCM rest),
+           "A Scheme callable function to issue the warning @var{str} at"
+           " the specified location in an input file."
+           "  The message is formatted with @code{format} and @var{rest}.")
+{
+  LY_ASSERT_TYPE (scm_is_string, location, 1);
+  LY_ASSERT_TYPE (scm_is_string, str, 2);
+  str = scm_simple_format (SCM_BOOL_F, str, rest);
+
+  if (get_program_option ("warning-as-error"))
+    error (ly_scm2string (str), ly_scm2string (location));
+  else
+    warning (ly_scm2string (str), ly_scm2string (location));
+
+  return SCM_UNSPECIFIED;
+}
index 93cd2c02d8b3e2ce30f38c851f7f5d06547f6edb..b58d8aca89ef4382f967463f82e5f67366597799 100644 (file)
             (ice-9 optargs))
 
 (define-public (ly:system command)
-  (if (ly:get-option 'verbose)
-      (begin
-       (ly:message (_ "Invoking `~a'...") (string-join command)))
-      (ly:progress "\n"))
+  (ly:debug (_ "Invoking `~a'...") (string-join command))
   (let ((status (apply ly:spawn command)))
     (if (> status 0)
        (begin
index 1c8fef1df92f2d9bbe3ae5bd3fac407a4a003c6c..2d85a97ed36ec7a8a39ec1d2951aadf2353dc559 100644 (file)
                          '())))
     (if (pair? alist)
        (begin
-         (if (ly:get-option 'verbose)
-             (ly:message (_ "Using `~a' note names...") str))
+         (ly:debug (_ "Using `~a' note names...") str)
          (set! pitchnames alist)
          (ly:parser-set-note-names parser alist))
        (ly:warning (_ "Could not find language `~a'.  Ignoring.") str))))
index ede65ff5e2a54b88d303e0a2429e3980384c7022..5b990e76040d762841280c36d041e6e2c7361b22 100644 (file)
@@ -852,17 +852,12 @@ print a warning and set an optional @var{default}."
     scaling))
 
 (define-public (version-not-seen-message input-file-name)
-  (ly:message
-   "~a:0: ~a ~a"
-    input-file-name
-    (_ "warning:")
-    (format #f
-           (_ "no \\version statement found, please add~afor future compatibility")
-           (format #f "\n\n\\version ~s\n\n" (lilypond-version)))))
+  (ly:warning-located
+    (ly:format "~a:0" input-file-name)
+    (_ "no \\version statement found, please add~afor future compatibility")
+    (format #f "\n\n\\version ~s\n\n" (lilypond-version))))
 
 (define-public (old-relative-not-used-message input-file-name)
-  (ly:message
-   "~a:0: ~a ~a"
-    input-file-name
-    (_ "warning:")
+  (ly:warning-located
+    (ly:format "~a:0" input-file-name)
     (_ "old relative compatibility not used")))
index e8fb65d4f408dbbd6a2628b9062c1d4a9ecf387e..c2b4fa7f2b4a06200d0cfe92154be2145fb11809 100644 (file)
@@ -179,8 +179,8 @@ second.  Dump results to `FILE.stacks' and
 `FILE.graph'.")
     (trace-scheme-coverage #f
 "Record coverage of Scheme files in `FILE.cov'.")
-    (verbose ,(ly:command-line-verbose?)
-"Value of the --verbose flag (read-only).")
+    (verbose ,(ly:verbose-output?)
+"Verbose output, i.e. loglevel at least DEBUG (read-only).")
     (warning-as-error #f
 "Change all warning and programming_error
 messages into errors.")
@@ -226,12 +226,10 @@ messages into errors.")
 
 (cond
   ((guile-v2)
-   (if (ly:get-option 'verbose)
-       (ly:message  (_ "Using (ice-9 curried-definitions) module\n")))
+   (ly:debug (_ "Using (ice-9 curried-definitions) module\n"))
    (use-modules (ice-9 curried-definitions)))
   (else
-    (if (ly:get-option 'verbose)
-        (ly:message (_ "Guile 1.8\n")))))
+    (ly:debug (_ "Guile 1.8\n"))))
 
 ;; TODO add in modules for V1.8.7 deprecated in V2.0 and integrated
 ;; into Guile base code, like (ice-9 syncase).
@@ -288,13 +286,14 @@ messages into errors.")
 
 (define-public (ly:load x)
   (let* ((file-name (%search-load-path x)))
-    (if (ly:get-option 'verbose)
-       (ly:progress "[~A" file-name))
+    (ly:debug "[~A" file-name)
     (if (not file-name)
-       (ly:error (_ "cannot find: ~A") x))
+        (ly:error (_ "cannot find: ~A") x))
     (primitive-load-path file-name)  ;; to support Guile V2 autocompile
+    ;; TODO: Any chance to use ly:debug here? Need to extend it to prevent
+    ;;       a newline in this case
     (if (ly:get-option 'verbose)
-       (ly:progress "]\n"))))
+        (ly:progress "]\n"))))
 
 (define-public DOS
   (let ((platform (string-tokenize