[Libreoffice-commits] core.git: sal/osl
Markus Mohrhard
markus.mohrhard at googlemail.com
Tue Dec 20 06:44:52 UTC 2016
sal/osl/all/log.cxx | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
New commits:
commit b85699a02706ee6d0b322888bf5da1c8906134dd
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon Dec 19 12:54:34 2016 +0100
add an option to pipe log output to file
The target file and the option are controlled by SAL_LOG_FILE. The
variable should contain the target file in a system dependent notation.
Change-Id: Ie1ce9c39740c8b7a989e5af222be21a3e3142084
Reviewed-on: https://gerrit.libreoffice.org/32176
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 00bd67cb..b400e43 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -19,6 +19,7 @@
#include <stdio.h>
#include <string.h>
+#include <fstream>
#include "osl/thread.hxx"
#include "rtl/string.h"
@@ -86,8 +87,8 @@ char const * getEnvironmentVariable() {
#else
-char const * getEnvironmentVariable_() {
- char const * p1 = std::getenv("SAL_LOG");
+char const * getEnvironmentVariable_(const char* env) {
+ char const * p1 = std::getenv(env);
if (p1 == nullptr) {
return nullptr;
}
@@ -99,10 +100,15 @@ char const * getEnvironmentVariable_() {
}
char const * getEnvironmentVariable() {
- static char const * env = getEnvironmentVariable_();
+ static char const * env = getEnvironmentVariable_("SAL_LOG");
return env;
}
+char const * getLogFile() {
+ static char const * logFile = getEnvironmentVariable_("SAL_LOG_FILE");
+ return logFile;
+}
+
void maybeOutputTimestamp(std::ostringstream &s) {
char const * env = getEnvironmentVariable();
if (env == nullptr)
@@ -339,8 +345,15 @@ void log(
syslog(prio, "%s", s.str().c_str());
#endif
} else {
- std::fputs(s.str().c_str(), stderr);
- std::fflush(stderr);
+ const char* logFile = getLogFile();
+ if (logFile) {
+ std::ofstream file(logFile, std::ios::app | std::ios::out);
+ file << s.str();
+ }
+ else {
+ std::fputs(s.str().c_str(), stderr);
+ std::fflush(stderr);
+ }
}
#endif
}
More information about the Libreoffice-commits
mailing list