diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-04-02 19:24:30 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-04-02 19:29:48 +0200 |
commit | b070e7f3c9ed680c821bd89d42506695f2438506 (patch) | |
tree | 5bef4c80fea167fe8ada2ca80927fcfe5e979eaf /src/systemd | |
parent | 1fa80181aecd4b9db513f16c136157a4546686d3 (diff) |
journal: implicitly add code location to all messages logged with the native interface
This logic can be turned off by defining SD_JOURNAL_SUPPRESS_LOCATION
before including sd-journal.h.
This also saves/restores errno in all logging functions, in order to be
useful as logging calls without side-effects.
This also adds a couple of __unlikely__ around the early checks in the
logging calls, in order to minimize the runtime impact.
Diffstat (limited to 'src/systemd')
-rw-r--r-- | src/systemd/sd-journal.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h index 5a2dab156..f27e461b0 100644 --- a/src/systemd/sd-journal.h +++ b/src/systemd/sd-journal.h @@ -26,6 +26,7 @@ #include <sys/types.h> #include <stdarg.h> #include <sys/uio.h> +#include <syslog.h> #include <systemd/sd-id128.h> @@ -34,13 +35,30 @@ extern "C" { #endif /* Write to daemon */ - int sd_journal_print(int piority, const char *format, ...) __attribute__ ((format (printf, 2, 3))); int sd_journal_printv(int priority, const char *format, va_list ap); - int sd_journal_send(const char *format, ...) __attribute__((sentinel)); int sd_journal_sendv(const struct iovec *iov, int n); +/* Used by the macros below */ +int sd_journal_print_with_location(int priority, const char *file, const char *line, const char *func, const char *format, ...) __attribute__ ((format (printf, 5, 6))); +int sd_journal_printv_with_location(int priority, const char *file, const char *line, const char *func, const char *format, va_list ap); +int sd_journal_send_with_location(const char *file, const char *line, const char *func, const char *format, ...) __attribute__((sentinel)); +int sd_journal_sendv_with_location(const char *file, const char *line, const char *func, const struct iovec *iov, int n); + +/* implicitly add code location to messages sent, if this is enabled */ +#ifndef SD_JOURNAL_SUPPRESS_LOCATION + +#define _sd_XSTRINGIFY(x) #x +#define _sd_STRINGIFY(x) _sd_XSTRINGIFY(x) + +#define sd_journal_print(priority, ...) sd_journal_print_with_location(priority, "CODE_FILE=" __FILE__, "CODE_LINE=" _sd_STRINGIFY(__LINE__), __func__, __VA_ARGS__) +#define sd_journal_printv(priority, format, ap) sd_journal_printv_with_location(priority, "CODE_FILE=" __FILE__, "CODE_LINE=" _sd_STRINGIFY(__LINE__), __func__, format, ap) +#define sd_journal_send(...) sd_journal_send_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_STRINGIFY(__LINE__), __func__, __VA_ARGS__) +#define sd_journal_sendv(iovec, n) sd_journal_sendv_with_location("CODE_FILE=" __FILE__, "CODE_LINE=" _sd_STRINGIFY(__LINE__), __func__, iovec, n) + +#endif + int sd_journal_stream_fd(const char *identifier, int priority, int level_prefix); /* Browse journal stream */ |