On 5 Apr 2002 at 18:17, Noel Koethe wrote:

> Will this be changed so the user could use -nv with >/dev/null
> and get only errors or warnings displayed?

So what I think you want is for any log message tagged as
LOG_VERBOSE (verbose information) or LOG_NONVERBOSE (basic
information) in the source to go to stdout when no log file
has been specified and the `-O -' option has not been used
and for everything else to go to stderr?

I'm not sure what Hrvoje Niksic thinks of that idea, but here
is a source code patch to accomplish it. I'd like some second
opinions (preferably from Hrvoje) before committing it. The
patch does not include any documentation changes - these will
follow if the patch is committed.

N.B. The patch contains a form-feed. I'm not sure if that will
survive the email passage.

2002-04-05  Ian Abbott  <[EMAIL PROTECTED]>

        * wget.h (enum log_options): Set order to `LOG_VERBOSE', `LOG_NONVERBOSE',
        `LOG_NOTQUIET', `LOG_ALWAYS' to reflect relative importance of the log
        messages to which they are associated.

        * log.c (get_log_fp): Add parameter to indicate logging level.  If a log
        file is not being used, send `LOG_VERBOSE' and `LOG_NONVERBOSE' logs to
        `stdout' instead of to `stderr', except when output documents are going to
        `stdout'.
        (logputs): Pass logging level to `get_log_fp()'.
        (logvprintf_state): Include logging level in the state.
        (logvprintf): Pass logging level (from passed state) to `get_log_fp()'.
        (logflush): If some logs go to `stderr' and some to `stdout', ensure that
        both streams get flushed.
        (logprintf): Put logging level in state passed to `logvprintf()'.
        (debug_logprintf): Put `LOG_VERBOSE' logging level in state passed to
        `logvprintf()'.
        (log_init): If no log file specified, don't set `logfp' to `stderr' -
        leave it set to NULL so that `get_log_fp()' can decide whether to return
        `stdout' or `stderr' based on the logging level (and other factors). In
        this case, ensure logs get saved to memory if either of `stderr' or
        `stdout' is a TTY.
        (log_dump_context): Use `logfp' value directly instead of calling
        `get_log_fp()'.

Index: src/log.c
===================================================================
RCS file: /pack/anoncvs/wget/src/log.c,v
retrieving revision 1.12
diff -u -r1.12 log.c
--- src/log.c   2001/12/19 09:36:58     1.12
+++ src/log.c   2002/04/05 18:03:44
@@ -287,12 +287,16 @@
    If logging is inhibited, return NULL.  */
 
 static FILE *
-get_log_fp (void)
+get_log_fp (enum log_options o)
 {
   if (inhibit_logging)
     return NULL;
   if (logfp)
     return logfp;
+  if (opt.dfp == stdout)
+    return stderr;
+  if (o < LOG_NOTQUIET)
+    return stdout;
   return stderr;
 }
 


@@ -305,7 +309,7 @@
   FILE *fp;
 
   check_redirect_output ();
-  if (!(fp = get_log_fp ()))
+  if (!(fp = get_log_fp (o)))
     return;
   CHECK_VERBOSE (o);
 
@@ -322,6 +326,7 @@
   char *bigmsg;
   int expected_size;
   int allocated;
+  enum log_options o;
 };
 
 /* Print a message to the log.  A copy of message will be saved to
@@ -341,7 +346,7 @@
   char *write_ptr = smallmsg;
   int available_size = sizeof (smallmsg);
   int numwritten;
-  FILE *fp = get_log_fp ();
+  FILE *fp = get_log_fp (state->o);
 
   if (!save_context_p)
     {
@@ -411,9 +416,12 @@
 void
 logflush (void)
 {
-  FILE *fp = get_log_fp ();
-  if (fp)
-    fflush (fp);
+  FILE *fp1 = get_log_fp (LOG_VERBOSE);
+  FILE *fp2 = get_log_fp (LOG_ALWAYS);
+  if (fp1)
+    fflush (fp1);
+  if (fp2 && (fp2 != fp1))
+    fflush (fp2);
   needs_flushing = 0;
 }
 
@@ -497,6 +505,7 @@
   CHECK_VERBOSE (o);
 
   memset (&lpstate, '\0', sizeof (lpstate));
+  lpstate.o = o;
   do
     {
       VA_START_2 (enum log_options, o, char *, fmt, args);
@@ -532,6 +541,7 @@
        return;
 
       memset (&lpstate, '\0', sizeof (lpstate));
+      lpstate.o = LOG_VERBOSE;
       do
        {
          VA_START_1 (char *, fmt, args);
@@ -559,13 +569,10 @@
     }
   else
     {
-      /* The log goes to stderr to avoid collisions with the output if
-         the user specifies `-O -'.  #### Francois Pinard suggests
-         that it's a better idea to print to stdout by default, and to
-         stderr only if the user actually specifies `-O -'.  He says
-         this inconsistency is harder to document, but is overall
-         easier on the user.  */
-      logfp = stderr;
+      /* LOG_NOTQUIET and LOG_ALWAYS logs will go to stdwrr. Other logs
+         will go to stdout unless the user specifies `-O -'.  This allows
+         the user to redirect standard output but still see errors and
+         warnings if standard error is a TTY.  */
 
       /* If the output is a TTY, enable storing, which will make Wget
          remember all the printed messages, to be able to dump them to
@@ -573,7 +580,7 @@
          Ctrl+Break is pressed under Windows).  */
       if (1
 #ifdef HAVE_ISATTY
-         && isatty (fileno (logfp))
+         && (isatty (fileno (stderr)) || isatty (fileno (stdout)))
 #endif
          )
        {
@@ -606,7 +613,7 @@
 log_dump_context (void)
 {
   int num = log_line_current;
-  FILE *fp = get_log_fp ();
+  FILE *fp = logfp;
   if (!fp)
     return;
 
Index: src/wget.h
===================================================================
RCS file: /pack/anoncvs/wget/src/wget.h,v
retrieving revision 1.32
diff -u -r1.32 wget.h
--- src/wget.h  2002/02/19 05:32:59     1.32
+++ src/wget.h  2002/04/05 18:03:45
@@ -92,7 +92,7 @@
 
 /* These are from log.c, but they are used everywhere, so we declare
    them here.  */
-enum log_options { LOG_VERBOSE, LOG_NOTQUIET, LOG_NONVERBOSE, LOG_ALWAYS };
+enum log_options { LOG_VERBOSE, LOG_NONVERBOSE, LOG_NOTQUIET, LOG_ALWAYS };
 
 #ifdef HAVE_STDARG_H
 void logprintf PARAMS ((enum log_options, const char *, ...))

Reply via email to