[Libreoffice-commits] online.git: 3 commits - loolwsd/configure.ac loolwsd/Log.cpp loolwsd/LOOLForKit.cpp loolwsd/LOOLWSD.cpp loolwsd/loolwsd.xml.in

Jan Holesovsky kendy at collabora.com
Tue Sep 27 12:37:30 UTC 2016


 loolwsd/LOOLForKit.cpp |   10 +++++++++-
 loolwsd/LOOLWSD.cpp    |    9 ++++++---
 loolwsd/Log.cpp        |   18 +++++++-----------
 loolwsd/configure.ac   |   18 ++++++++++++++++++
 loolwsd/loolwsd.xml.in |    6 +++---
 5 files changed, 43 insertions(+), 18 deletions(-)

New commits:
commit 0409243683621da95e1b0598cc1c839233345a6e
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Sep 27 14:30:45 2016 +0200

    Log either to file or the console, not to both.
    
    Change-Id: Iac1e74d0624c2bbac4ffaf99b11488f02e626a2a

diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp
index f1408cd..376b91f 100644
--- a/loolwsd/LOOLForKit.cpp
+++ b/loolwsd/LOOLForKit.cpp
@@ -198,7 +198,15 @@ int main(int argc, char** argv)
     }
 
     // Initialization
-    Log::initialize("frk", getenv("LOOL_LOGLEVEL"), getenv("LOOL_LOGCOLOR"));
+    const bool logToFile = getenv("LOOL_LOGFILE");
+    const auto logFilename = getenv("LOOL_LOGFILENAME");
+    std::map<std::string, std::string> logProperties;
+    if (logToFile && logFilename)
+    {
+        logProperties["path"] = std::string(logFilename);
+    }
+
+    Log::initialize("frk", getenv("LOOL_LOGLEVEL"), getenv("LOOL_LOGCOLOR"), logToFile, logProperties);
 
     Util::setTerminationSignals();
     Util::setFatalSignals();
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 12654db..1c4d4a7 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1514,8 +1514,11 @@ void LOOLWSD::initialize(Application& self)
 
     ServerApplication::initialize(self);
 
-    Log::warn("Launch this in your browser:");
-    Log::warn(lcl_getLaunchURI());
+#if ENABLE_DEBUG
+    std::cerr << "\nLaunch this in your browser:\n\n" <<
+        lcl_getLaunchURI() <<
+        "\n\nFull log is available in: " << LOOLWSD_LOGFILE << std::endl;
+#endif
 }
 
 void LOOLWSD::initializeSSL()
diff --git a/loolwsd/Log.cpp b/loolwsd/Log.cpp
index 498b881..8575b49 100644
--- a/loolwsd/Log.cpp
+++ b/loolwsd/Log.cpp
@@ -126,24 +126,20 @@ namespace Log
         strncpy(LogPrefix, oss.str().c_str(), sizeof(LogPrefix));
 
         // Configure the logger.
-        AutoPtr<Channel> channel = (withColor
-                                    ? static_cast<Poco::Channel*>(new Poco::ColorConsoleChannel())
-                                    : static_cast<Poco::Channel*>(new Poco::ConsoleChannel()));
+        AutoPtr<Channel> channel;
 
         if (logToFile)
         {
-            auto splitterChannel(new SplitterChannel());
-            splitterChannel->addChannel(channel);
-
-            AutoPtr<FileChannel> rotatedFileChannel(new FileChannel("loolwsd.log"));
+            channel = static_cast<Poco::Channel*>(new FileChannel("loolwsd.log"));
             for (const auto& pair : config)
             {
-                rotatedFileChannel->setProperty(pair.first, pair.second);
+                channel->setProperty(pair.first, pair.second);
             }
-
-            splitterChannel->addChannel(rotatedFileChannel);
-            channel = splitterChannel;
         }
+        else if (withColor)
+            channel = static_cast<Poco::Channel*>(new Poco::ColorConsoleChannel());
+        else
+            channel = static_cast<Poco::Channel*>(new Poco::ConsoleChannel());
 
         auto& logger = Poco::Logger::create(Source.name, channel, Poco::Message::PRIO_TRACE);
 
diff --git a/loolwsd/configure.ac b/loolwsd/configure.ac
index da761de..b5f18f4 100644
--- a/loolwsd/configure.ac
+++ b/loolwsd/configure.ac
@@ -115,7 +115,7 @@ if test "$enable_debug" = "yes"; then
    ENABLE_DEBUG=true
    LOOLWSD_LOGLEVEL="trace"
    LOOLWSD_LOG_TO_FILE="true"
-   LOOLWSD_LOGFILE="loolwsd.log"
+   LOOLWSD_LOGFILE="/tmp/loolwsd.log"
    debug_msg="low security debugging mode"
 else
     AC_DEFINE([ENABLE_DEBUG],0,[Whether to compile in some extra debugging support code and disable some security pieces])
@@ -128,6 +128,7 @@ if test -n "$with_logfile" ; then
    LOOLWSD_LOGFILE="$with_logfile"
 fi
 AC_SUBST(LOOLWSD_LOGFILE)
+AC_DEFINE_UNQUOTED([LOOLWSD_LOGFILE],["$LOOLWSD_LOGFILE"],[Pathname of the logfile.])
 
 MAX_DOCUMENTS=10
 AS_IF([test -n "$with_max_documents"],
commit 0cb07b22e371c60d2013d12d0c9afc814181305f
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Sep 27 13:40:44 2016 +0200

    Set less verbose logging for non-debug builds.
    
    For debugging builds, use a logfile instead of the console.
    
    Change-Id: I0d5654a568115c054c7439fe1358f5613dc432bf

diff --git a/loolwsd/configure.ac b/loolwsd/configure.ac
index bb41235..da761de 100644
--- a/loolwsd/configure.ac
+++ b/loolwsd/configure.ac
@@ -60,6 +60,10 @@ AC_ARG_WITH([lo-path],
             AS_HELP_STRING([--with-lo-path=<path>],
                            [Path to a working installation directory or instdir of LibreOffice]))
 
+AC_ARG_WITH([logfile],
+            AS_HELP_STRING([--with-logfile=<path>],
+                           [Path to the location of the logfile.]))
+
 AC_ARG_WITH([poco-includes],
             AS_HELP_STRING([--with-poco-includes=<path>],
                            [Path to the "include" directory with the Poco headers]))
@@ -102,15 +106,28 @@ AS_IF([test "$enable_debug" = yes -a -n "$with_poco_libs"],
       [POCO_DEBUG_SUFFIX=])
 
 ENABLE_DEBUG=
+LOOLWSD_LOGLEVEL="warning"
+LOOLWSD_LOG_TO_FILE="false"
+LOOLWSD_LOGFILE="/var/log/loolwsd.log"
 debug_msg="secure mode: product build"
 if test "$enable_debug" = "yes"; then
    AC_DEFINE([ENABLE_DEBUG],1,[Whether to compile in some extra debugging support code and disable some security pieces])
    ENABLE_DEBUG=true
+   LOOLWSD_LOGLEVEL="trace"
+   LOOLWSD_LOG_TO_FILE="true"
+   LOOLWSD_LOGFILE="loolwsd.log"
    debug_msg="low security debugging mode"
 else
     AC_DEFINE([ENABLE_DEBUG],0,[Whether to compile in some extra debugging support code and disable some security pieces])
 fi
 AC_SUBST(ENABLE_DEBUG)
+AC_SUBST(LOOLWSD_LOGLEVEL)
+AC_SUBST(LOOLWSD_LOG_TO_FILE)
+
+if test -n "$with_logfile" ; then
+   LOOLWSD_LOGFILE="$with_logfile"
+fi
+AC_SUBST(LOOLWSD_LOGFILE)
 
 MAX_DOCUMENTS=10
 AS_IF([test -n "$with_max_documents"],
diff --git a/loolwsd/loolwsd.xml.in b/loolwsd/loolwsd.xml.in
index 20b1dd7..50527f8 100644
--- a/loolwsd/loolwsd.xml.in
+++ b/loolwsd/loolwsd.xml.in
@@ -20,9 +20,9 @@
 
     <logging>
         <color type="bool">true</color>
-        <level type="string" desc="Can be 0-8, or none (turns off logging), fatal, critical, error, warning, notice, information, debug, trace" default="trace">trace</level>
-        <file enable="false">
-            <property name="path" desc="Log file path.">loolwsd.log</property>
+        <level type="string" desc="Can be 0-8, or none (turns off logging), fatal, critical, error, warning, notice, information, debug, trace" default="@LOOLWSD_LOGLEVEL@">@LOOLWSD_LOGLEVEL@</level>
+        <file enable="@LOOLWSD_LOG_TO_FILE@">
+            <property name="path" desc="Log file path.">@LOOLWSD_LOGFILE@</property>
             <property name="rotation" desc="Log file rotation strategy. See Poco FileChannel.">never</property>
             <property name="archive" desc="Append either timestamp or number to the archived log filename.">timestamp</property>
             <property name="compress" desc="Enable/disable log file compression.">true</property>
commit 0467f84a6f53d9e2297e7b1fba2e15d80aed6d3a
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Sep 27 13:15:17 2016 +0200

    Actually move the check for tty where we check for various envvars etc.
    
    Change-Id: Ib05208770f9e1865fd322302b861108f351607da

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5c81d42..12654db 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1400,7 +1400,7 @@ void LOOLWSD::initialize(Application& self)
 
     const auto logLevel = getConfigValue<std::string>(conf, "logging.level", "trace");
     setenv("LOOL_LOGLEVEL", logLevel.c_str(), true);
-    const auto withColor = getConfigValue<bool>(conf, "logging.color", true);
+    const auto withColor = getConfigValue<bool>(conf, "logging.color", true) && isatty(fileno(stderr));
     if (withColor)
     {
         setenv("LOOL_LOGCOLOR", "1", true);
diff --git a/loolwsd/Log.cpp b/loolwsd/Log.cpp
index 8f0059d..498b881 100644
--- a/loolwsd/Log.cpp
+++ b/loolwsd/Log.cpp
@@ -126,7 +126,7 @@ namespace Log
         strncpy(LogPrefix, oss.str().c_str(), sizeof(LogPrefix));
 
         // Configure the logger.
-        AutoPtr<Channel> channel = (isatty(fileno(stderr)) && withColor
+        AutoPtr<Channel> channel = (withColor
                                     ? static_cast<Poco::Channel*>(new Poco::ColorConsoleChannel())
                                     : static_cast<Poco::Channel*>(new Poco::ConsoleChannel()));
 


More information about the Libreoffice-commits mailing list