Hello,
Il 27/08/2012 09:41, Riccardo Magliocchetti ha scritto:
Hello Stephan,
Il 27/08/2012 09:13, Stephan Bergmann ha scritto:
On 08/26/2012 12:34 PM, Riccardo Magliocchetti wrote:
while in headless mode i'd like to have messages delivered to syslog
instead of stderr / stdout, looking at the SAL_* implementation it looks
like what i want is to substitute the std::fputs in
osl/all/log.cxx::log() with syslog() plus some map between these levels
and syslog ones. Is that ok?
yes
So here's a quick patch, not even compile tested because i have few
questions to resolve before considering it ready for review:
- what about errors? it looks like SAL does not have a level for errors.
I'd like to have the errors in vcl/headless/headlessinst.cxx going to
syslog too. Should i use straight syslog or can i use another facility?
- is it ok to initialize syslog in desktop/source/app/sofficemain.cxx?
- can you suggests something better than WANT_SYSLOG_LOGS ? :)
- should i add a switch for syslog logging to configure so that the
feature may be used also in other environments? May be useful for large
deployments i think where you want centralized logs.
thanks in advance,
riccardo
diff --git a/configure.in b/configure.in
index 7d7ec8b..b7cc0f4 100644
--- a/configure.in
+++ b/configure.in
@@ -9098,6 +9098,8 @@ if test "x$enable_headless" = "xyes"; then
ENABLE_HEADLESS="TRUE"
SCPDEFS="$SCPDEFS -DLIBO_HEADLESS"
R="headless"
+ dnl if we support syslog, we want our logs there
+ AC_CHECK_HEADER(syslog.h, AC_DEFINE(WANT_SYSLOG_LOGS))
fi
AC_SUBST(ENABLE_HEADLESS)
diff --git a/desktop/source/app/sofficemain.cxx b/desktop/source/app/sofficemain.cxx
index a0fba04..251cc20 100755
--- a/desktop/source/app/sofficemain.cxx
+++ b/desktop/source/app/sofficemain.cxx
@@ -43,6 +43,10 @@
#include <windows.h>
#endif
+#ifdef WANT_SYSLOG_LOGS
+#include <syslog.h>
+#endif
+
int SVMain();
// -=-= main() -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@@ -82,6 +86,9 @@ extern "C" int DESKTOP_DLLPUBLIC soffice_main()
return EXIT_FAILURE;
}
#endif
+#ifdef WANT_SYSLOG_LOGS
+ openlog("libreoffice", 0, LOG_USER);
+#endif
return SVMain();
#if defined ANDROID || defined WNT
} catch (const ::com::sun::star::uno::Exception &e) {
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index bac0e93..f869060 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -55,6 +55,10 @@
#define OSL_DETAIL_GETPID getpid()
#endif
+#ifdef WANT_SYSLOG_LOGS
+#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.
@@ -82,6 +86,22 @@ char const * toString(sal_detail_LogLevel level) {
}
}
+#ifdef WANT_SYSLOG_LOGS
+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;
@@ -156,14 +176,21 @@ void log(
char const * message)
{
std::ostringstream s;
+#ifndef WANT_SYSLOG_LOGS
+ 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';
}
+#ifdef WANT_SYSLOG_LOGS
+ syslog(toSyslogPriority(level), "%s", s.str().c_str());
+#else
std::fputs(s.str().c_str(), stderr);
+#endif
}
}
diff --git a/vcl/headless/headlessinst.cxx b/vcl/headless/headlessinst.cxx
index 439de86..792e8af 100644
--- a/vcl/headless/headlessinst.cxx
+++ b/vcl/headless/headlessinst.cxx
@@ -78,7 +78,6 @@ public:
virtual bool ErrorTrapPop( bool ) { return false; }
};
-// All the interesting stuff is slaved from the AndroidSalInstance
void InitSalData() {}
void DeInitSalData() {}
void InitSalMain() {}
@@ -89,6 +88,7 @@ void SalAbort( const rtl::OUString& rErrorText, bool bDumpCore )
rtl::OUString aError( rErrorText );
if( aError.isEmpty() )
aError = rtl::OUString::createFromAscii("Unknown application error");
+ /* FIXME: use sal error ? */
::fprintf( stderr, "%s\n", rtl::OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr() );
::fprintf( stderr, "SalAbort: '%s'",
_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice