forked from enlightenment/efl
eina: add support for Systemd journal in Eina_Log.
NOTE: if you start your process with Systemd it will automatically use Journald API. You will need to overide the default logging function to change that behavior.
This commit is contained in:
parent
116b775c30
commit
06ce7c2ede
|
@ -1,6 +1,7 @@
|
||||||
2013-03-16 Cedric Bail
|
2013-03-16 Cedric Bail
|
||||||
|
|
||||||
* Remove Glew and Direct3d code from Ecore_Evas module.
|
* Remove Glew and Direct3d code from Ecore_Evas module.
|
||||||
|
* Add Eina_Log integration for Systemd journal.
|
||||||
|
|
||||||
2013-03-15 Carsten Haitzler (The Rasterman)
|
2013-03-15 Carsten Haitzler (The Rasterman)
|
||||||
|
|
||||||
|
|
1
NEWS
1
NEWS
|
@ -19,6 +19,7 @@ Additions:
|
||||||
eina_xattr_fd_copy()
|
eina_xattr_fd_copy()
|
||||||
- Add eina_stringshare_refplace()
|
- Add eina_stringshare_refplace()
|
||||||
- Add eina_file_copy()
|
- Add eina_file_copy()
|
||||||
|
- Add eina_log_print_cb_journald()
|
||||||
* Add Cserve2 scalecache support
|
* Add Cserve2 scalecache support
|
||||||
* ecore_x:
|
* ecore_x:
|
||||||
- Add window profile support.
|
- Add window profile support.
|
||||||
|
|
|
@ -290,7 +290,7 @@ AM_CONDITIONAL([HAVE_CRYPTO_OPENSSL], [test "${build_crypto}" = "openssl"])
|
||||||
|
|
||||||
# check for systemd library if requested
|
# check for systemd library if requested
|
||||||
if test "x{want_systemd}" = "xyes"; then
|
if test "x{want_systemd}" = "xyes"; then
|
||||||
PKG_CHECK_MODULES([SYSTEMD], [libsystemd-daemon],
|
PKG_CHECK_MODULES([SYSTEMD], [libsystemd-daemon libsystemd-journal],
|
||||||
[want_systemd="yes"],
|
[want_systemd="yes"],
|
||||||
[want_systemd="no"])
|
[want_systemd="no"])
|
||||||
fi
|
fi
|
||||||
|
@ -695,6 +695,8 @@ AC_DEFINE_IF([EINA_DEBUG_MALLOC],
|
||||||
[test "x${ac_cv_func_malloc_usable_size}" = "xyes" && test "x${want_debug_malloc}" = "xyes"],
|
[test "x${ac_cv_func_malloc_usable_size}" = "xyes" && test "x${want_debug_malloc}" = "xyes"],
|
||||||
[1], [Turn on debugging overhead in mempool])
|
[1], [Turn on debugging overhead in mempool])
|
||||||
|
|
||||||
|
EFL_OPTIONAL_DEPEND_PKG([EINA], [${want_systemd}], [SYSTEMD], [libsystemd-journal])
|
||||||
|
|
||||||
EFL_EVAL_PKGS([EINA])
|
EFL_EVAL_PKGS([EINA])
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
@ -761,6 +763,8 @@ EINA_CHECK_MODULE([chained-pool], [static], [chained pool])
|
||||||
EINA_CHECK_MODULE([pass-through], [static], [pass through])
|
EINA_CHECK_MODULE([pass-through], [static], [pass through])
|
||||||
EINA_CHECK_MODULE([one-big], [static], [one big])
|
EINA_CHECK_MODULE([one-big], [static], [one big])
|
||||||
|
|
||||||
|
EFL_ADD_FEATURE([EINA], [systemd-journal], [${have_systemd}])
|
||||||
|
|
||||||
EFL_LIB_END([Eina])
|
EFL_LIB_END([Eina])
|
||||||
#### End of Eina
|
#### End of Eina
|
||||||
|
|
||||||
|
@ -3740,6 +3744,7 @@ echo " Image Loaders.: ${features_evas_loader}"
|
||||||
if test "x${have_pixman}" = "xyes" ; then
|
if test "x${have_pixman}" = "xyes" ; then
|
||||||
echo " Pixman........: ${features_evas_pixman}"
|
echo " Pixman........: ${features_evas_pixman}"
|
||||||
fi
|
fi
|
||||||
|
echo "Eina............: yes (${features_eina})"
|
||||||
echo "Ecore...........: yes (${features_ecore})"
|
echo "Ecore...........: yes (${features_ecore})"
|
||||||
echo "Ecore_Con.......: yes (${features_ecore_con})"
|
echo "Ecore_Con.......: yes (${features_ecore_con})"
|
||||||
echo "Ecore_File......: yes"
|
echo "Ecore_File......: yes"
|
||||||
|
|
|
@ -34,6 +34,10 @@
|
||||||
# define EINA_LOG_BACKTRACE
|
# define EINA_LOG_BACKTRACE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_SYSTEMD
|
||||||
|
# include <systemd/sd-journal.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_EVIL
|
#ifdef HAVE_EVIL
|
||||||
# include <Evil.h>
|
# include <Evil.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -43,6 +47,8 @@
|
||||||
#include "eina_inlist.h"
|
#include "eina_inlist.h"
|
||||||
#include "eina_lock.h"
|
#include "eina_lock.h"
|
||||||
#include "eina_thread.h"
|
#include "eina_thread.h"
|
||||||
|
#include "eina_convert.h"
|
||||||
|
#include "eina_strbuf.h"
|
||||||
|
|
||||||
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
|
/* undefs EINA_ARG_NONULL() so NULL checks are not compiled out! */
|
||||||
#include "eina_safety_checks.h"
|
#include "eina_safety_checks.h"
|
||||||
|
@ -1354,6 +1360,11 @@ eina_log_init(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_SYSTEMD
|
||||||
|
if (getenv("NOTIFY_SOCKET"))
|
||||||
|
_print_cb = eina_log_print_cb_journald;
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((tmp = getenv(EINA_LOG_ENV_FILE_DISABLE)) && (atoi(tmp) == 1))
|
if ((tmp = getenv(EINA_LOG_ENV_FILE_DISABLE)) && (atoi(tmp) == 1))
|
||||||
_disable_file = EINA_TRUE;
|
_disable_file = EINA_TRUE;
|
||||||
|
|
||||||
|
@ -1371,6 +1382,10 @@ eina_log_init(void)
|
||||||
// Global log level
|
// Global log level
|
||||||
if ((level = getenv(EINA_LOG_ENV_LEVEL)))
|
if ((level = getenv(EINA_LOG_ENV_LEVEL)))
|
||||||
_log_level = atoi(level);
|
_log_level = atoi(level);
|
||||||
|
#ifdef HAVE_SYSTEMD
|
||||||
|
else if (getenv("NOTIFY_SOCKET") && (_print_cb == eina_log_print_cb_journald))
|
||||||
|
_log_level = EINA_LOG_LEVEL_INFO;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Register UNKNOWN domain, the default logger
|
// Register UNKNOWN domain, the default logger
|
||||||
EINA_LOG_DOMAIN_GLOBAL = eina_log_domain_register("", NULL);
|
EINA_LOG_DOMAIN_GLOBAL = eina_log_domain_register("", NULL);
|
||||||
|
@ -1874,6 +1889,74 @@ eina_log_print_cb_stdout(const Eina_Log_Domain *d,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EAPI void
|
||||||
|
eina_log_print_cb_journald(const Eina_Log_Domain *d,
|
||||||
|
Eina_Log_Level level,
|
||||||
|
const char *file,
|
||||||
|
const char *fnc,
|
||||||
|
int line,
|
||||||
|
const char *fmt,
|
||||||
|
void *data EINA_UNUSED,
|
||||||
|
va_list args)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_SYSTEMD
|
||||||
|
char buf[12];
|
||||||
|
char *tmp;
|
||||||
|
Eina_Thread cur;
|
||||||
|
|
||||||
|
vasprintf(&tmp, fmt, args);
|
||||||
|
|
||||||
|
eina_convert_itoa(line, buf);
|
||||||
|
|
||||||
|
cur = SELF();
|
||||||
|
|
||||||
|
#ifdef EINA_LOG_BACKTRACE
|
||||||
|
if (EINA_LIKELY(level >= _backtrace_level))
|
||||||
|
#endif
|
||||||
|
sd_journal_send_with_location(file, buf, fnc,
|
||||||
|
"PRIORITY=%i", level,
|
||||||
|
"MESSAGE=%s", tmp,
|
||||||
|
"EFL_DOMAIN=%s", d->domain_str,
|
||||||
|
"THREAD=%lu", cur,
|
||||||
|
NULL);
|
||||||
|
#ifdef EINA_LOG_BACKTRACE
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Eina_Strbuf *bts;
|
||||||
|
char **strings;
|
||||||
|
void *bt[256];
|
||||||
|
int btlen;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
btlen = backtrace((void **)bt, 256);
|
||||||
|
strings = backtrace_symbols((void **)bt, btlen);
|
||||||
|
|
||||||
|
bts = eina_strbuf_new();
|
||||||
|
for (i = 0; i < btlen; i++)
|
||||||
|
if (i + 1 == btlen)
|
||||||
|
eina_strbuf_append_printf(bts, "[%s]", strings[i]);
|
||||||
|
else
|
||||||
|
eina_strbuf_append_printf(bts, "[%s], ", strings[i]);
|
||||||
|
|
||||||
|
sd_journal_send_with_location(file, buf, fnc,
|
||||||
|
"PRIORITY=%i", level,
|
||||||
|
"MESSAGE=%s", tmp,
|
||||||
|
"EFL_DOMAIN=%s", d->domain_str,
|
||||||
|
"THREAD=%lu", cur,
|
||||||
|
"BACKTRACE=%s", eina_strbuf_string_get(bts),
|
||||||
|
NULL);
|
||||||
|
eina_strbuf_free(bts);
|
||||||
|
free(strings);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
free(tmp);
|
||||||
|
|
||||||
|
#else
|
||||||
|
eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, data, args);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
eina_log_print_cb_file(const Eina_Log_Domain *d,
|
eina_log_print_cb_file(const Eina_Log_Domain *d,
|
||||||
EINA_UNUSED Eina_Log_Level level,
|
EINA_UNUSED Eina_Log_Level level,
|
||||||
|
|
|
@ -891,6 +891,35 @@ EAPI void eina_log_print_cb_file(const Eina_Log_Domain *d,
|
||||||
void *data,
|
void *data,
|
||||||
va_list args);
|
va_list args);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alternative logging method, this will output to systemd journal.
|
||||||
|
*
|
||||||
|
* @param d The domain.
|
||||||
|
* @param level Not used.
|
||||||
|
* @param file The file which is logged.
|
||||||
|
* @param fnc The function which is logged.
|
||||||
|
* @param line The line which is logged.
|
||||||
|
* @param fmt The ouptut format to use.
|
||||||
|
* @param data The file which will store the output (as a FILE *).
|
||||||
|
* @param args The arguments needed by the format.
|
||||||
|
*
|
||||||
|
* This method will never output color.
|
||||||
|
*
|
||||||
|
* @note if systemd journal is not there it will display error on stderr.
|
||||||
|
* @note if the process has been started by systemd this will be the default logging method.
|
||||||
|
*
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
EAPI void eina_log_print_cb_journald(const Eina_Log_Domain *d,
|
||||||
|
Eina_Log_Level level,
|
||||||
|
const char *file,
|
||||||
|
const char *fnc,
|
||||||
|
int line,
|
||||||
|
const char *fmt,
|
||||||
|
void *data,
|
||||||
|
va_list args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure console color of given file.
|
* Configure console color of given file.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue