jpeg pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=a4270b25a3f0866b4011e58d9857e7c4ce2bdd57

commit a4270b25a3f0866b4011e58d9857e7c4ce2bdd57
Author: Jean-Philippe Andre <jp.an...@samsung.com>
Date:   Wed Feb 17 15:40:43 2016 +0900

    eina log: print formatted string when log domain is invalid
    
    Before this patch, eina_log would simply record a non-formatted
    entry like:
      unknown domain -1, original message format 'proxy=%p, obj=%p'
    
    This was not very useful as even if the log domain is invalid, the
    message itself might be relevant (often those are ERR logs).
    
    Now the message format is roughly the same as the default format,
    except that the line info comes from the original message (and
    doesn't refer to eina_log.c).
    
    Backtrace printing will happen at the same level as the original
    log level, in order to avoid log pollution in case DBG logs are
    printed with an invalid domain (and CRI would trigger bt).
    
    I actually wonder if the logs shouldn't actually be forwarded
    to the standard log callback instead of just stderr. This may
    be useful for logging with dlog or journald (atm we will simply
    lose all logs without a valid domain). This would mean eina_log
    itself requires a log domain.
---
 src/lib/eina/eina_log.c | 78 +++++++++++++++++++++++++++++++------------------
 1 file changed, 49 insertions(+), 29 deletions(-)

diff --git a/src/lib/eina/eina_log.c b/src/lib/eina/eina_log.c
index b544468..9d518c9 100644
--- a/src/lib/eina/eina_log.c
+++ b/src/lib/eina/eina_log.c
@@ -1191,6 +1191,16 @@ eina_log_domain_unregister_unlocked(int domain)
    d->deleted = 1;
 }
 
+#ifdef EINA_LOG_BACKTRACE
+# define DISPLAY_BACKTRACE(File, Level) \
+   if (EINA_UNLIKELY(Level <= _backtrace_level)) { \
+      fprintf(File, "*** Backtrace ***\n"); \
+      EINA_BT(File); \
+   }
+#else
+# define DISPLAY_BACKTRACE(File, Level)
+#endif
+
 static inline void
 eina_log_print_unlocked(int domain,
                         Eina_Log_Level level,
@@ -1206,28 +1216,35 @@ eina_log_print_unlocked(int domain,
    if (EINA_UNLIKELY((unsigned int)domain >= _log_domains_count) ||
        EINA_UNLIKELY(domain < 0))
      {
-        if (file && fnc && fmt)
+        DECLARE_LEVEL_NAME(level);
+        if (level > _log_level)
           {
-             fprintf(
-              stderr,
-              "CRI: %s:%d %s() eina_log_print() unknown domain %d, original 
message format '%s'\n",
-              file,
-              line,
-              fnc,
-              domain,
-              fmt);
+             fprintf(stderr, "CRI<%u>:eina_log %s:%d %s() unknown log domain 
%d, "
+                     "original message level was: %s\n", eina_log_pid_get(),
+                     file, line, fnc, domain, name);
           }
         else
           {
-             fprintf(
-              stderr,
-              "CRI: eina_log_print() unknown domain %d, original message 
format '%s'\n",
-              domain,
-              fmt ? fmt : "");
+             if (file && fnc && fmt)
+               {
+                  fprintf(stderr, "CRI<%u>:eina_log %s:%d %s() unknown log 
domain %d, "
+                                  "original message was: %s: '", 
eina_log_pid_get(),
+                          file, line, fnc, domain, name);
+                  vfprintf(stderr, fmt, args);
+               }
+             else
+               {
+                  fprintf(stderr, "CRI<%u>:eina_log unknown log domain %d, 
original "
+                                  "message was: %s: '", eina_log_pid_get(), 
domain, name);
+                  if (fmt)
+                    vfprintf(stderr, fmt, args);
+               }
+             fputs("'\n", stderr);
           }
 
-        if (_abort_on_critical)
-           abort();
+        DISPLAY_BACKTRACE(stderr, level);
+        if (EINA_UNLIKELY(_abort_on_critical))
+          abort();
 
         return;
      }
@@ -1237,9 +1254,22 @@ eina_log_print_unlocked(int domain,
 #ifdef EINA_SAFETY_CHECKS
    if (EINA_UNLIKELY(d->deleted))
      {
-           fprintf(stderr,
-                "ERR: eina_log_print() domain %d is deleted\n",
-                domain);
+        if (level > d->level)
+          fprintf(stderr, "ERR<%u>:eina_log %s:%d %s() log domain %d was 
deleted\n",
+                  eina_log_pid_get(), file, line, fnc, domain);
+        else
+          {
+             DECLARE_LEVEL_NAME(level);
+             fprintf(stderr, "ERR<%u>:eina_log %s:%d %s() log domain %d was "
+                             "deleted, original message was: %s: '",
+                     eina_log_pid_get(), file, line, fnc, domain, name);
+             vfprintf(stderr, fmt, args);
+             fputs("'\n", stderr);
+          }
+        DISPLAY_BACKTRACE(stderr, level);
+        if (EINA_UNLIKELY(_abort_on_critical) &&
+            EINA_UNLIKELY(level <= _abort_level_on_critical))
+           abort();
         return;
      }
 
@@ -1853,16 +1883,6 @@ eina_log_domain_registered_level_set(int domain, int 
level)
 #endif
 }
 
-#ifdef EINA_LOG_BACKTRACE
-# define DISPLAY_BACKTRACE(File, Level) \
-   if (EINA_UNLIKELY(Level <= _backtrace_level)) { \
-      fprintf(File, "*** Backtrace ***\n"); \
-      EINA_BT(File); \
-   }
-#else
-# define DISPLAY_BACKTRACE(File, Level)
-#endif
-
 EAPI void
 eina_log_print_cb_stderr(const Eina_Log_Domain *d,
                          Eina_Log_Level level,

-- 


Reply via email to