Hello Stephan,

Il 18/12/2012 09:42, Stephan Bergmann ha scritto:
On 12/17/2012 09:15 PM, Riccardo Magliocchetti wrote:
i've refreshed my patch for adding possibility to send SAL_* messages to
syslog. I have two issues:
- am not able to send the ENABLE_SYSLOG definition down to
sal/osl/unx/salinit.cxx

You need to add it to config_host.mk.in to have it visible in
solenv/gbuild/gbuild.mk (or use the newly introduced mechanism of adding
a config/config_*.h that you then include in sal/osl/unx/salinit.cxx,
removing the change from solenv/gbuild/gbuild.mk again).

I've taken the approach suggested by Tor

- if i add calls to SAL_INFO in vcl/headless/headlessinst.cxx like, i
see the fprintf but i don't see the SAL_INFO one. Tried with SAL_WARN,
same result.

Did you configure --enable-dbgutil or at least --enable-debug?

No and that was one of the causes of not seeing them :) why this SAL messages are shown only on debug build?

Also, the definition of sal_use_syslog in sal/osl/all/log.cxx is in an
unnamed namespace, so the extern declaration in sal/osl/unx/salinit.cxx
is unrelated (and the code should result in a link error?); so move the
definition out of the unnamed namespace. It would be best to place the
extern declaration into a header anyway, but it looks like there is no
good header directory that would be included from both sal/osl/all and
sal/osl/unx, so short of that please at least add comments to the
declaration and definition linking those two together across the two
.cxx files. And in any case, wrap sal_use_syslog in #ifdef ENABLE_SYSLOG.

Done, new patch attached, still have to compile with --enable-debug so haven't see if it works but at least now it initialize correctly :) More testing tomorrow.

BTW added a printf in sal_detail_initialize and seeing it called twice on startup, is it expected?

compiled with:
./autogen.sh --with-parallelism=4 --without-java --enable-headless --enable-symbols
run with:
SAL_LOG_SYSLOG=1 SAL_LOG=+INFO.vcl /usr/local/lib/libreoffice/program/soffice "--accept=socket,host=localhost,port=2002;urp;"

thanks,
riccardo
>From d9e5944d4ec3e663e0cf821c7fdd9127f0f0a1c1 Mon Sep 17 00:00:00 2001
From: Riccardo Magliocchetti <riccardo.magliocche...@gmail.com>
Date: Fri, 23 Nov 2012 18:34:17 +0100
Subject: [PATCH] Add ability to send SAL_* messages to syslog

Use environment variable SAL_LOG_SYSLOG=1

Change-Id: I0c260ca69fbeefb0c2e8cc46ca6955e92791c05b
---
 config/config_global.h.in |    1 +
 config_host.mk.in         |    1 +
 configure.ac              |    5 ++++-
 sal/osl/all/log.cxx       |   40 +++++++++++++++++++++++++++++++++++++---
 sal/osl/unx/salinit.cxx   |   14 ++++++++++++++
 5 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/config/config_global.h.in b/config/config_global.h.in
index 77980d4..63effa9 100644
--- a/config/config_global.h.in
+++ b/config/config_global.h.in
@@ -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
diff --git a/config_host.mk.in b/config_host.mk.in
index fd12153..30a4b96 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -238,6 +238,7 @@ export HAVE_LD_BSYMBOLIC_FUNCTIONS=@HAVE_LD_BSYMBOLIC_FUNCTIONS@
 export HAVE_LD_HASH_STYLE=@HAVE_LD_HASH_STYLE@
 export HAVE_NON_CONST_NPP_GETMIMEDESCRIPTION=@HAVE_NON_CONST_NPP_GETMIMEDESCRIPTION@
 export HAVE_POSIX_FALLOCATE=@HAVE_POSIX_FALLOCATE@
+export HAVE_SYSLOG_H=@HAVE_SYSLOG_H@
 export HAVE_READDIR_R=@HAVE_READDIR_R@
 export HAVE_THREADSAFE_STATICS=@HAVE_THREADSAFE_STATICS@
 export HOST_PLATFORM=@host@
diff --git a/configure.ac b/configure.ac
index 320384c..fa11dc6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4273,7 +4273,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.
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 8d4d5f2..b03fa45 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,26 @@ void log(
     char const * message)
 {
     std::ostringstream s;
+#ifdef HAVE_SYSLOG_H
+    if (!sal_use_syslog)
+        s << toString(level) << ':';
+#else
+    s << toString(level) << ':';
+#endif
     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);
 }
 
 }
diff --git a/sal/osl/unx/salinit.cxx b/sal/osl/unx/salinit.cxx
index d880258..ad6253c 100644
--- a/sal/osl/unx/salinit.cxx
+++ b/sal/osl/unx/salinit.cxx
@@ -29,6 +29,14 @@
 #include "sal/main.h"
 #include "sal/types.h"
 
+#ifdef HAVE_SYSLOG_H
+#include <string.h>
+#include <syslog.h>
+#endif
+
+// from sal/osl/all/log.cxx
+extern bool sal_use_syslog;
+
 extern "C" {
 
 void sal_detail_initialize(int argc, char ** argv) {
@@ -57,6 +65,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);
 }
-- 
1.7.5.4

_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to