[Libreoffice-commits] core.git: Branch 'feature/cib_contract57' - sal/osl

Thorsten Behrens Thorsten.Behrens at CIB.de
Mon Jan 16 03:24:09 UTC 2017


 sal/osl/all/log.cxx |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

New commits:
commit d9add6fe073b6407d3d1f1c1dbb80efd9d718f98
Author: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Date:   Mon Jan 16 04:19:34 2017 +0100

    sal: don't reopen logfile on every log line
    
    Change-Id: Iac34fc87a99e98ca5e41eb621d55bf356c371e97

diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 326d44e..7dd3880 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -144,7 +144,7 @@ char const * getLogLevel() {
     return nullptr;
 }
 
-char const * getLogFile() {
+char const * getLogFilePath() {
     // First check the environment variable, then the setting in logging.ini
     static char const * logFile = getEnvironmentVariable_("SAL_LOG_FILE");
     if (logFile != nullptr)
@@ -158,13 +158,19 @@ char const * getLogFile() {
     return nullptr;
 }
 
+std::ofstream * getLogFile() {
+    static std::ofstream file(getLogFilePath(), std::ios::app | std::ios::out);
+
+    return &file;
+}
+
 #endif
 
 bool report(sal_detail_LogLevel level, char const * area) {
     if (level == SAL_DETAIL_LOG_LEVEL_DEBUG)
         return true;
     assert(area != 0);
-    char const * env = getLogLevel();
+    static char const * env = getLogLevel();
     if (env == 0) {
         env = "+WARN";
     }
@@ -295,10 +301,9 @@ void log(
         syslog(prio, "%s", s.str().c_str());
 #endif
     } else {
-        const char* logFile = getLogFile();
+        static std::ofstream * logFile = getLogFile();
         if (logFile) {
-            std::ofstream file(logFile, std::ios::app | std::ios::out);
-            file << s.str();
+            *logFile << s.str();
         }
         else {
             std::fputs(s.str().c_str(), stderr);


More information about the Libreoffice-commits mailing list