summaryrefslogtreecommitdiff
path: root/sal/osl/all
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-12-19 12:54:34 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-12-20 06:44:15 +0000
commitb85699a02706ee6d0b322888bf5da1c8906134dd (patch)
treea57b6b92d0e6d33f6dcd84e1736ba31c5f710993 /sal/osl/all
parented2b8ca92ae00ab96b0ea2b1c3fc9be4622b61ff (diff)
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@libreoffice.org> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sal/osl/all')
-rw-r--r--sal/osl/all/log.cxx23
1 files changed, 18 insertions, 5 deletions
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 00bd67cbb759..b400e43ab164 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
}