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>
This commit is contained in:
committed by
Stephan Bergmann
parent
585e4181f0
commit
2c9ab4bd1b
@@ -13,3 +13,4 @@ Any change in this header will cause a rebuild of almost everything.
|
||||
#undef HAVE_GCC_BUILTIN_ATOMIC
|
||||
#undef HAVE_SFINAE_ANONYMOUS_BROKEN
|
||||
#undef HAVE_THREADSAFE_STATICS
|
||||
#undef HAVE_SYSLOG_H
|
||||
|
@@ -4257,7 +4257,10 @@ SOURCEVERSION="OOO$UPD"
|
||||
AC_SUBST(UPD)
|
||||
AC_SUBST(SOURCEVERSION)
|
||||
|
||||
|
||||
dnl ===================================================================
|
||||
dnl Check for syslog header
|
||||
dnl ===================================================================
|
||||
AC_CHECK_HEADER(syslog.h, AC_DEFINE(HAVE_SYSLOG_H))
|
||||
|
||||
dnl ===================================================================
|
||||
dnl Set the ENABLE_CRASHDUMP variable.
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -29,6 +29,13 @@
|
||||
#include "sal/main.h"
|
||||
#include "sal/types.h"
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
// from sal/osl/all/log.cxx:
|
||||
extern bool sal_use_syslog;
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
||||
void sal_detail_initialize(int argc, char ** argv) {
|
||||
@@ -57,6 +64,12 @@ void sal_detail_initialize(int argc, char ** argv) {
|
||||
close(fd);
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
const char *use_syslog = getenv("SAL_LOG_SYSLOG");
|
||||
sal_use_syslog = use_syslog != NULL && !strcmp(use_syslog, "1");
|
||||
if (sal_use_syslog)
|
||||
openlog("libreoffice", 0, LOG_USER);
|
||||
#endif
|
||||
|
||||
osl_setCommandArgs(argc, argv);
|
||||
}
|
||||
|
Reference in New Issue
Block a user