Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Hello,

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 - 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.

diff --git a/vcl/headless/headlessinst.cxx b/vcl/headless/headlessinst.cxx
index 7793d85..204500f 100644
--- a/vcl/headless/headlessinst.cxx
+++ b/vcl/headless/headlessinst.cxx
@@ -42,6 +42,8 @@ public:
 HeadlessSalInstance::HeadlessSalInstance( SalYieldMutex *pMutex ) :
     SvpSalInstance( pMutex)
 {
+    SAL_INFO("vcl", "ciao\n");
+    ::fprintf(stdout, "LibreOffice\n");
 }

 HeadlessSalInstance::~HeadlessSalInstance()

Any help appreciated

thanks,
riccardo
From 5bb7dc21b0a24623c65e959695095e30ba15d390 Mon Sep 17 00:00:00 2001
From: Riccardo Magliocchetti <riccardo.magliocchetti@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
---
 configure.ac            |    6 +++++-
 sal/osl/all/log.cxx     |   36 +++++++++++++++++++++++++++++++++---
 sal/osl/unx/salinit.cxx |   12 ++++++++++++
 solenv/gbuild/gbuild.mk |    5 +++++
 4 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 320384c..e06fb01 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4273,7 +4273,11 @@ SOURCEVERSION="OOO$UPD"
 AC_SUBST(UPD)
 AC_SUBST(SOURCEVERSION)
 
-
+dnl ===================================================================
+dnl Check for syslog header
+dnl ===================================================================
+AC_CHECK_HEADER([syslog.h], ENABLE_SYSLOG="TRUE", ENABLE_SYSLOG="")
+AC_SUBST(ENABLE_SYSLOG)
 
 dnl ===================================================================
 dnl Set the ENABLE_CRASHDUMP variable.
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 8d4d5f2..b6d8edf 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -56,12 +56,18 @@
 #define OSL_DETAIL_GETPID getpid()
 #endif
 
+#ifdef ENABLE_SYSLOG
+#include <syslog.h>
+#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.
 
 namespace {
 
+bool sal_use_syslog = false;
+
 bool equalStrings(
     char const * string1, std::size_t length1, char const * string2,
     std::size_t length2)
@@ -96,6 +102,22 @@ char const * getEnvironmentVariable() {
     return p2;
 }
 
+#ifdef ENABLE_SYSLOG
+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,22 @@ void log(
     char const * message)
 {
     std::ostringstream s;
+    if (!sal_use_syslog)
+        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 ENABLE_SYSLOG
+    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..890589e 100644
--- a/sal/osl/unx/salinit.cxx
+++ b/sal/osl/unx/salinit.cxx
@@ -25,10 +25,16 @@
 #include <unistd.h>
 #endif
 
+#ifdef ENABLE_SYSLOG
+#include <syslog.h>
+#endif
+
 #include "osl/process.h"
 #include "sal/main.h"
 #include "sal/types.h"
 
+extern bool sal_use_syslog;
+
 extern "C" {
 
 void sal_detail_initialize(int argc, char ** argv) {
@@ -57,6 +63,12 @@ void sal_detail_initialize(int argc, char ** argv) {
         close(fd);
     }
 #endif
+#ifdef ENABLE_SYSLOG
+    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);
 }
diff --git a/solenv/gbuild/gbuild.mk b/solenv/gbuild/gbuild.mk
index 9e621cd..99ca578 100644
--- a/solenv/gbuild/gbuild.mk
+++ b/solenv/gbuild/gbuild.mk
@@ -255,6 +255,11 @@ gb_GLOBALDEFS += -DDEBUG \
 endif
 endif
 
+ifeq ($(ENABLE_SYSLOG),TRUE)
+gb_GLOBALDEFS += -DENABLE_SYSLOG \
+
+endif
+
 ifeq ($(ENABLE_HEADLESS),TRUE)
 gb_GLOBALDEFS += -DLIBO_HEADLESS \
 
-- 
1.7.5.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.