configure.ac | 2 - sal/osl/all/log.cxx | 96 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 81 insertions(+), 17 deletions(-)
New commits: commit 10ed63ccdc87cd38f8e964aa3e3c257946e0ae57 Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> AuthorDate: Tue Oct 27 08:24:50 2020 +0100 Commit: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> CommitDate: Tue Oct 27 08:24:50 2020 +0100 Release 5.4.12 Change-Id: Ie50de9dc5c4e1baa96098dfc5f2f7ebf2d44ef26 diff --git a/configure.ac b/configure.ac index af7fc01b8195..9f2d8bb17402 100644 --- a/configure.ac +++ b/configure.ac @@ -9,7 +9,7 @@ dnl in order to create a configure script. # several non-alphanumeric characters, those are split off and used only for the # ABOUTBOXPRODUCTVERSIONSUFFIX in openoffice.lst. Why that is necessary, no idea. -AC_INIT([LibreOffice],[5.4.11.0],[],[],[http://documentfoundation.org/]) +AC_INIT([LibreOffice],[5.4.12.0],[],[],[http://documentfoundation.org/]) AC_PREREQ([2.59]) commit 40ab562d98035fed5f85b892530a6e836ec39306 Author: Thorsten Behrens <thorsten.behr...@cib.de> AuthorDate: Wed Jan 17 21:13:16 2018 +0100 Commit: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> CommitDate: Tue Oct 27 08:21:26 2020 +0100 sal: use snprintf for sal log Change-Id: I0fe7029991052a59ee56cef1897cf6688bfa24b9 Reviewed-on: https://gerrit.libreoffice.org/48083 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx index 82b48475200c..a21d3d7b0833 100644 --- a/sal/osl/all/log.cxx +++ b/sal/osl/all/log.cxx @@ -101,6 +101,8 @@ char const * getEnvironmentVariable(const char* env) { } #ifdef WNT +# define INI_STRINGBUF_SIZE 1024 + bool getValueFromLoggingIniFile(const char* key, char* value) { char buffer[MAX_PATH]; GetModuleFileName(NULL, buffer, MAX_PATH); @@ -126,7 +128,7 @@ bool getValueFromLoggingIniFile(const char* key, char* value) { if (aKey != sWantedKey) continue; aValue = sLine.substr(n+1, sLine.length()); - sprintf(value, "%s", aValue.c_str()); + snprintf(value, INI_STRINGBUF_SIZE, "%s", aValue.c_str()); return true; } } @@ -142,7 +144,7 @@ char const * getLogLevel() { return env; #ifdef WNT - static char logLevel[1024]; + static char logLevel[INI_STRINGBUF_SIZE]; if (getValueFromLoggingIniFile("LogLevel", logLevel)) return logLevel; #endif @@ -157,7 +159,7 @@ std::ofstream * getLogFile() { return nullptr; #ifdef WNT - static char logFilePath[1024]; + static char logFilePath[INI_STRINGBUF_SIZE]; if (getValueFromLoggingIniFile("LogFilePath", logFilePath)) logFile = logFilePath; else @@ -196,7 +198,7 @@ void maybeOutputTimestamp(std::ostringstream &s) { tm.tm_year = dateTime.Year - 1900; strftime(ts, sizeof(ts), "%Y-%m-%d:%H:%M:%S", &tm); char milliSecs[11]; - sprintf(milliSecs, "%03u", static_cast<unsigned>(dateTime.NanoSeconds/1000000)); + snprintf(milliSecs, sizeof(milliSecs), "%03u", static_cast<unsigned>(dateTime.NanoSeconds/1000000)); s << ts << '.' << milliSecs << ':'; } if (outputRelativeTimer) { @@ -217,7 +219,7 @@ void maybeOutputTimestamp(std::ostringstream &s) { else milliSeconds = (now.Nanosec-first.Nanosec)/1000000; char relativeTimestamp[100]; - sprintf(relativeTimestamp, "%d.%03d", seconds, milliSeconds); + snprintf(relativeTimestamp, sizeof(relativeTimestamp), "%d.%03d", seconds, milliSeconds); s << relativeTimestamp << ':'; } return; commit fbe195ff4ef045b17d99ded1c34510d871f4a7a3 Author: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> AuthorDate: Wed Dec 21 21:15:49 2016 +0100 Commit: Samuel Mehrbrodt <samuel.mehrbr...@cib.de> CommitDate: Tue Oct 27 08:20:56 2020 +0100 WNT: allow to set log level/path from file Expects a file logging.ini in the program/ directory with the keys LogFilePath and LogLevel, e.g.: LogFilePath=C:\log.txt LogLevel=info Note: This is Windows-only for now. En passant remove extraneous newlines from syslog and android log calls. Change-Id: I35c730469e4079139da908aa287b989dc98e0f9d diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx index 446108b3c042..82b48475200c 100644 --- a/sal/osl/all/log.cxx +++ b/sal/osl/all/log.cxx @@ -33,6 +33,7 @@ #include <android/log.h> #elif defined WNT #include <process.h> +#include <windows.h> #define OSL_DETAIL_GETPID _getpid() #else #include <unistd.h> @@ -81,13 +82,13 @@ char const * toString(sal_detail_LogLevel level) { // the process is running": #if defined ANDROID -char const * getEnvironmentVariable() { +char const * getLogLevel() { return std::getenv("SAL_LOG"); } #else -char const * getEnvironmentVariable_(const char* env) { +char const * getEnvironmentVariable(const char* env) { char const * p1 = std::getenv(env); if (p1 == nullptr) { return nullptr; @@ -99,18 +100,78 @@ char const * getEnvironmentVariable_(const char* env) { return p2; } -char const * getEnvironmentVariable() { - static char const * env = getEnvironmentVariable_("SAL_LOG"); - return env; +#ifdef WNT +bool getValueFromLoggingIniFile(const char* key, char* value) { + char buffer[MAX_PATH]; + GetModuleFileName(NULL, buffer, MAX_PATH); + std::string sProgramDirectory = std::string(buffer); + std::string::size_type pos = sProgramDirectory.find_last_of( "\\/" ); + sProgramDirectory = sProgramDirectory.substr(0, pos+1); + sProgramDirectory += "logging.ini"; + + std::ifstream logFileStream(sProgramDirectory); + if (!logFileStream.good()) + return false; + + std::size_t n; + std::string aKey; + std::string aValue; + std::string sWantedKey(key); + std::string sLine; + while (std::getline(logFileStream, sLine)) { + if (sLine.find('#') == 0) + continue; + if ( ( n = sLine.find('=') ) != std::string::npos) { + aKey = sLine.substr(0, n); + if (aKey != sWantedKey) + continue; + aValue = sLine.substr(n+1, sLine.length()); + sprintf(value, "%s", aValue.c_str()); + return true; + } + } + return false; } +#endif + +char const * getLogLevel() { + // First check the environment variable, then the setting in logging.ini + static char const * env = getEnvironmentVariable("SAL_LOG"); + + if (env != nullptr) + return env; + +#ifdef WNT + static char logLevel[1024]; + if (getValueFromLoggingIniFile("LogLevel", logLevel)) + return logLevel; +#endif -char const * getLogFile() { - static char const * logFile = getEnvironmentVariable_("SAL_LOG_FILE"); - return logFile; + return nullptr; +} + +std::ofstream * getLogFile() { + // First check the environment variable, then the setting in logging.ini + char const * logFile = getEnvironmentVariable("SAL_LOG_FILE"); + if (!logFile) + return nullptr; + +#ifdef WNT + static char logFilePath[1024]; + if (getValueFromLoggingIniFile("LogFilePath", logFilePath)) + logFile = logFilePath; + else + return nullptr; +#endif + + // stays until process exits + static std::ofstream file(logFile, std::ios::app | std::ios::out); + + return &file; } void maybeOutputTimestamp(std::ostringstream &s) { - char const * env = getEnvironmentVariable(); + static char const * env = getLogLevel(); if (env == nullptr) return; bool outputTimestamp = false; @@ -218,7 +279,7 @@ void sal_detail_log( if (backtraceDepth != 0) { s << " at:\n" << osl::detail::backtraceAsString(backtraceDepth); } - s << '\n'; + #if defined ANDROID int android_log_level; switch (level) { @@ -259,12 +320,13 @@ void sal_detail_log( syslog(prio, "%s", s.str().c_str()); #endif } else { - const char* logFile = getLogFile(); + // avoid calling getLogFile() more than once + static std::ofstream * logFile = getLogFile(); if (logFile) { - std::ofstream file(logFile, std::ios::app | std::ios::out); - file << s.str(); + *logFile << s.str() << std::endl; } else { + s << '\n'; std::fputs(s.str().c_str(), stderr); std::fflush(stderr); } @@ -297,7 +359,7 @@ sal_Bool sal_detail_log_report(sal_detail_LogLevel level, char const * area) { return true; } assert(area != nullptr); - char const * env = getEnvironmentVariable(); + static char const * env = getLogLevel(); if (env == nullptr) { env = "+WARN"; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits