ack florian
[oweals/gnunet.git] / src / util / common_logging.c
index 0cefa194d128bebe8311614e53f0e14f4061f124..a391d0b9e686e0edb44fe0ab35c5ee4cb9a2ec1e 100644 (file)
@@ -25,6 +25,7 @@
  */
 #include "platform.h"
 #include "gnunet_crypto_lib.h"
+#include "gnunet_disk_lib.h"
 #include "gnunet_strings_lib.h"
 #include <regex.h>
 
@@ -256,6 +257,8 @@ get_type (const char *log)
     return GNUNET_ERROR_TYPE_DEBUG;
   if (0 == strcasecmp (log, _("INFO")))
     return GNUNET_ERROR_TYPE_INFO;
+  if (0 == strcasecmp (log, _("MESSAGE")))
+    return GNUNET_ERROR_TYPE_MESSAGE;
   if (0 == strcasecmp (log, _("WARNING")))
     return GNUNET_ERROR_TYPE_WARNING;
   if (0 == strcasecmp (log, _("ERROR")))
@@ -357,6 +360,15 @@ setup_log_file (const struct tm *tm)
     return GNUNET_OK; /* no change */
   log_rotate (last_fn);
   strcpy (last_fn, fn);
+  if (GNUNET_SYSERR ==
+      GNUNET_DISK_directory_create_for_file (fn))
+  {
+    fprintf (stderr,
+             "Failed to create directory for `%s': %s\n",
+             fn,
+             STRERROR (errno));
+    return GNUNET_SYSERR;
+  }
 #if WINDOWS
   altlog_fd = OPEN (fn, O_APPEND |
                         O_BINARY |
@@ -510,9 +522,10 @@ GNUNET_get_log_call_status (int caller_level,
   if (min_level >= 0)
     return caller_level <= min_level;
   /* All programs/services previously defaulted to WARNING.
-   * Now WE default to WARNING, and THEY default to NULL.
+   * Now *we* default to WARNING, and THEY default to NULL.
+   * Or rather we default to MESSAGE, since things aren't always bad.
    */
-  return caller_level <= GNUNET_ERROR_TYPE_WARNING;
+  return caller_level <= GNUNET_ERROR_TYPE_MESSAGE;
 }
 
 
@@ -788,12 +801,26 @@ output_message (enum GNUNET_ErrorType kind,
   if ( (NULL != GNUNET_stderr) &&
        (NULL == loggers) )
   {
-    FPRINTF (GNUNET_stderr,
+    if (kind == GNUNET_ERROR_TYPE_MESSAGE) {
+       /* The idea here is to produce "normal" output messages
+        * for end users while still having the power of the
+        * logging engine for developer needs. So ideally this
+        * is what it should look like when CLI tools are used
+        * interactively, yet the same message shouldn't look 
+        * this way if the output is going to logfiles or robots
+        * instead. Is this the right place to do this? --lynX
+        */
+       FPRINTF (GNUNET_stderr,
+             "* %s",
+             msg);
+    } else {
+       FPRINTF (GNUNET_stderr,
              "%s %s %s %s",
              datestr,
              comp,
              GNUNET_error_type_to_string (kind),
              msg);
+    }
     fflush (GNUNET_stderr);
   }
   pos = loggers;
@@ -1056,6 +1083,8 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind)
     return _("ERROR");
   if ((kind & GNUNET_ERROR_TYPE_WARNING) > 0)
     return _("WARNING");
+  if ((kind & GNUNET_ERROR_TYPE_MESSAGE) > 0)
+    return _("MESSAGE");
   if ((kind & GNUNET_ERROR_TYPE_INFO) > 0)
     return _("INFO");
   if ((kind & GNUNET_ERROR_TYPE_DEBUG) > 0)