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.
This commit is contained in:
Jean-Philippe Andre 2016-02-17 15:40:43 +09:00
parent f649dac12f
commit a4270b25a3
1 changed files with 49 additions and 29 deletions

View File

@ -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,