diff options
author | Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> | 2012-11-23 18:34:17 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-12-20 11:24:42 +0100 |
commit | 2c9ab4bd1bd895478ca6c5887b05ff29a73f1215 (patch) | |
tree | f51232578cb1e0b3c35f4a5f4ce48aca4da2b524 /sal/osl/all/log.cxx | |
parent | 585e4181f09d1860413051c8f111ecf4f9deb786 (diff) |
Add ability to send SAL_* messages to syslog
Use environment variable SAL_LOG_SYSLOG=1
Change-Id: I0c260ca69fbeefb0c2e8cc46ca6955e92791c05b
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal/osl/all/log.cxx')
-rw-r--r-- | sal/osl/all/log.cxx | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx index 8d4d5f2ac3c5..7e43082cc85a 100644 --- a/sal/osl/all/log.cxx +++ b/sal/osl/all/log.cxx @@ -56,6 +56,12 @@ #define OSL_DETAIL_GETPID getpid() #endif +#ifdef HAVE_SYSLOG_H +#include <syslog.h> +// sal/osl/unx/salinit.cxx::sal_detail_initialize updates this: +bool sal_use_syslog; +#endif + // Avoid the use of other sal code in this file as much as possible, so that // this code can be called from other sal code without causing endless // recursion. @@ -96,6 +102,22 @@ char const * getEnvironmentVariable() { return p2; } +#ifdef HAVE_SYSLOG_H +int toSyslogPriority(sal_detail_LogLevel level) { + switch (level) { + default: + assert(false); // this cannot happen + // fall through + case SAL_DETAIL_LOG_LEVEL_INFO: + return LOG_INFO; + case SAL_DETAIL_LOG_LEVEL_WARN: + return LOG_WARNING; + case SAL_DETAIL_LOG_LEVEL_DEBUG: + return LOG_DEBUG; + } +} +#endif + bool report(sal_detail_LogLevel level, char const * area) { if (level == SAL_DETAIL_LOG_LEVEL_DEBUG) return true; @@ -167,14 +189,23 @@ void log( char const * message) { std::ostringstream s; +#ifdef HAVE_SYSLOG_H + if (!sal_use_syslog) +#endif + s << toString(level) << ':'; if (level == SAL_DETAIL_LOG_LEVEL_DEBUG) { - s << toString(level) << ':' << /*no where*/' ' << message << '\n'; + s << /*no where*/' ' << message << '\n'; } else { - s << toString(level) << ':' << area << ':' << OSL_DETAIL_GETPID << ':' + s << area << ':' << OSL_DETAIL_GETPID << ':' << osl::Thread::getCurrentIdentifier() << ':' << where << message << '\n'; } - std::fputs(s.str().c_str(), stderr); +#ifdef HAVE_SYSLOG_H + if (sal_use_syslog) + syslog(toSyslogPriority(level), "%s", s.str().c_str()); + else +#endif + std::fputs(s.str().c_str(), stderr); } } |