[Libreoffice-commits] online.git: loolwsd/Log.cpp loolwsd/Log.hpp loolwsd/LOOLForKit.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/loolwsd.xml.in

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Aug 8 03:46:25 UTC 2016


 loolwsd/LOOLForKit.cpp |    2 +-
 loolwsd/LOOLKit.cpp    |    2 +-
 loolwsd/LOOLWSD.cpp    |    9 +++++++--
 loolwsd/Log.cpp        |   13 ++++---------
 loolwsd/Log.hpp        |    2 +-
 loolwsd/loolwsd.xml.in |    4 +---
 6 files changed, 15 insertions(+), 17 deletions(-)

New commits:
commit 5b639c3a2dca60d52fcbee32a8d9e7b2d511c13d
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Jul 30 11:52:10 2016 -0400

    loolwsd: use log settings from the config XML
    
    Change-Id: I0384d97b5411d3ff537b344e67f166daa65630c1
    Reviewed-on: https://gerrit.libreoffice.org/27951
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp
index c29de0d..2081a8f 100644
--- a/loolwsd/LOOLForKit.cpp
+++ b/loolwsd/LOOLForKit.cpp
@@ -202,7 +202,7 @@ int main(int argc, char** argv)
     }
 
     // Initialization
-    Log::initialize("frk");
+    Log::initialize("frk", getenv("LOOL_LOGLEVEL"), getenv("LOOL_LOGCOLOR"));
 
     Util::setTerminationSignals();
     Util::setFatalSignals();
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 9b72946..74c32c9 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -1005,7 +1005,7 @@ void lokit_main(const std::string& childRoot,
                 bool queryVersion)
 {
     // Reinitialize logging when forked.
-    Log::initialize("kit");
+    Log::initialize("kit", getenv("LOOL_LOGLEVEL"), getenv("LOOL_LOGCOLOR"));
     Util::rng::reseed();
 
     assert(!childRoot.empty());
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 7d8c61a..f6425d2 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1288,8 +1288,6 @@ LOOLWSD::~LOOLWSD()
 
 void LOOLWSD::initialize(Application& self)
 {
-    Log::initialize("wsd");
-
     if (geteuid() == 0)
     {
         throw std::runtime_error("Do not run as root. Please run as lool user.");
@@ -1348,6 +1346,13 @@ void LOOLWSD::initialize(Application& self)
     // Allow UT to manipulate before using configuration values.
     UnitWSD::get().configure(config());
 
+    const auto logLevel = config().getString("logging.level", "trace");
+    setenv("LOOL_LOGLEVEL", logLevel.c_str(), true);
+    const auto withColor = config().getBool("logging.color", true);
+    if (withColor)
+        setenv("LOOL_LOGCOLOR", "1", true);
+    Log::initialize("wsd", logLevel, withColor);
+
 #if ENABLE_SSL
     LOOLWSD::SSLEnabled.set(getConfigValue<bool>(conf, "ssl.enable", true));
 #else
diff --git a/loolwsd/Log.cpp b/loolwsd/Log.cpp
index 930268b..a6511f0 100644
--- a/loolwsd/Log.cpp
+++ b/loolwsd/Log.cpp
@@ -100,7 +100,7 @@ namespace Log
         signalLog(buffer);
     }
 
-    void initialize(const std::string& name)
+    void initialize(const std::string& name, const std::string& logLevel, const bool withColor)
     {
         Source.name = name;
         std::ostringstream oss;
@@ -110,19 +110,14 @@ namespace Log
         assert (sizeof (LogPrefix) > strlen(oss.str().c_str()) + 1);
         strncpy(LogPrefix, oss.str().c_str(), sizeof(LogPrefix));
 
-        auto channel = (isatty(fileno(stderr)) || std::getenv("LOOL_LOGCOLOR")
+        // Configure the logger.
+        auto channel = (isatty(fileno(stderr)) || withColor
                      ? static_cast<Poco::Channel*>(new Poco::ColorConsoleChannel())
                      : static_cast<Poco::Channel*>(new Poco::ConsoleChannel()));
         auto& logger = Poco::Logger::create(Source.name, channel, Poco::Message::PRIO_TRACE);
         channel->release();
 
-        // Configure the logger.
-        // TODO: This should come from a file.
-        // See Poco::Logger::setLevel docs for values.
-        // Try: error, information, debug
-        char *loglevel = std::getenv("LOOL_LOGLEVEL");
-        if (loglevel)
-            logger.setLevel(std::string(loglevel));
+        logger.setLevel(logLevel.empty() ? std::string("trace") : logLevel);
 
         info("Initializing " + name);
         info("Log level is [" + std::to_string(logger.getLevel()) + "].");
diff --git a/loolwsd/Log.hpp b/loolwsd/Log.hpp
index f474d34..daa02dc 100644
--- a/loolwsd/Log.hpp
+++ b/loolwsd/Log.hpp
@@ -18,7 +18,7 @@
 
 namespace Log
 {
-    void initialize(const std::string& name);
+    void initialize(const std::string& name, const std::string& logLevel = "trace", const bool withColor = true);
     Poco::Logger& logger();
     std::string prefix();
 
diff --git a/loolwsd/loolwsd.xml.in b/loolwsd/loolwsd.xml.in
index 6366dd6..15153c8 100644
--- a/loolwsd/loolwsd.xml.in
+++ b/loolwsd/loolwsd.xml.in
@@ -18,11 +18,9 @@
 
     <loleaflet_html desc="Allows UI customization by replacing the single endpoint of loleaflet.html" type="string" default="loleaflet.html">loleaflet.html</loleaflet_html>
 
-    <!-- FIXME: logging cannot be set from here. Use LOOL_LOGLEVEL environment variable. LOOL_LOGLEVEL can be 0-8, or
-         none (turns off logging), fatal, critical, error, warning, notice, information, debug, trace -->
     <logging>
         <color type="bool">true</color>
-        <level type="string">trace</level>
+        <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>
     </logging>
 
     <ssl desc="SSL settings">


More information about the Libreoffice-commits mailing list