[Libreoffice-commits] core.git: 2 commits - comphelper/source sal/osl
Thorsten Behrens
Thorsten.Behrens at CIB.de
Wed Jan 17 19:59:16 UTC 2018
comphelper/source/misc/storagehelper.cxx | 1
sal/osl/all/log.cxx | 90 ++++++++++++++++++++++++++-----
2 files changed, 76 insertions(+), 15 deletions(-)
New commits:
commit 53e6785f303e5b308a497e12d411251b216eaabf
Author: Thorsten Behrens <Thorsten.Behrens at CIB.de>
Date: Wed Jan 17 20:57:47 2018 +0100
xmlsecurity: cleanup comment
Change-Id: I1e34e1c4c51411be3de2dbd417126d263713c88a
diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx
index c312b397974f..dad5b83511e2 100644
--- a/comphelper/source/misc/storagehelper.cxx
+++ b/comphelper/source/misc/storagehelper.cxx
@@ -483,7 +483,6 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreateGpgPackageEncryptionDat
throw uno::RuntimeException("The GpgME library failed to initialize for the OpenPGP protocol.");
ctx->setArmor(false);
- // TODO: add self-encryption key from user config
const uno::Reference< security::XCertificate >* pCerts=xSignCertificates.getConstArray();
for (sal_uInt32 i = 0, nNum = xSignCertificates.getLength(); i < nNum; i++, pCerts++)
{
commit 9f027559557cb132835d8a13cdc0281ad4e757ae
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date: Wed Dec 21 21:15:49 2016 +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 636429c6992e..211fcb6fb9bd 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;
@@ -217,7 +278,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) {
@@ -258,12 +319,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);
}
@@ -296,7 +358,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";
}
More information about the Libreoffice-commits
mailing list