summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2021-04-21 17:37:57 +0300
committerTor Lillqvist <tml@collabora.com>2021-04-28 09:30:17 +0200
commit41ff704cc49b7097b717882616011962ecd7198f (patch)
tree65c94d0f52acebe9c637e0de1a636dd2f0b79cfc /sal
parent9bfe083adf1fd9d470b600d0a801d144db24474f (diff)
Add API to LibreOfficeKit to set arbitrary run-time options in core
Add setOption(const char*, const char*) At the moment this enables starting and stopping the ProfileZone event recording and overriding the SAL_LOG environment variable. Change-Id: Ic3a934bb4246c755a91eee8a8343fafc15815116 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114439 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tor Lillqvist <tml@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114559 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114656 Tested-by: Tor Lillqvist <tml@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/all/log.cxx63
-rw-r--r--sal/util/sal.map1
2 files changed, 38 insertions, 26 deletions
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 927e78b97064..c493f4ddf03e 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -125,7 +125,9 @@ char const* setEnvFromLoggingIniFile(const char* env, const char* key)
}
#endif
-char const * getLogLevel() {
+char const* pLogSelector = nullptr;
+
+char const* getLogLevelEnvVar() {
static char const* const pLevel = [] {
char const* pResult = nullptr;
@@ -176,33 +178,36 @@ std::ofstream * getLogFile() {
return pFile;
}
-void maybeOutputTimestamp(std::ostringstream &s) {
- static const std::pair<bool, bool> aFlags = [] {
- char const* env = getLogLevel();
- bool outputTimestamp = false;
- bool outputRelativeTimer = false;
- for (char const* p = env; p && *p;)
+
+std::pair<bool, bool> getTimestampFlags(char const *selector)
+{
+ bool outputTimestamp = false;
+ bool outputRelativeTimer = false;
+ for (char const* p = selector; p && *p;)
{
if (*p++ == '+')
- {
- char const * p1 = p;
- while (*p1 != '.' && *p1 != '+' && *p1 != '-' && *p1 != '\0') {
- ++p1;
- }
- if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("TIMESTAMP")))
- outputTimestamp = true;
- else if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("RELATIVETIMER")))
- outputRelativeTimer = true;
- char const * p2 = p1;
- while (*p2 != '+' && *p2 != '-' && *p2 != '\0') {
- ++p2;
+ {
+ char const * p1 = p;
+ while (*p1 != '.' && *p1 != '+' && *p1 != '-' && *p1 != '\0') {
+ ++p1;
+ }
+ if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("TIMESTAMP")))
+ outputTimestamp = true;
+ else if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("RELATIVETIMER")))
+ outputRelativeTimer = true;
+ char const * p2 = p1;
+ while (*p2 != '+' && *p2 != '-' && *p2 != '\0') {
+ ++p2;
+ }
+ p = p2;
}
- p = p2;
- }
}
- return std::pair(outputTimestamp, outputRelativeTimer);
- }();
- const auto& [outputTimestamp, outputRelativeTimer] = aFlags;
+ return std::pair(outputTimestamp, outputRelativeTimer);
+}
+
+void maybeOutputTimestamp(std::ostringstream &s) {
+ static const std::pair<bool, bool> aEnvFlags = getTimestampFlags(getLogLevelEnvVar());
+ const auto& [outputTimestamp, outputRelativeTimer] = (pLogSelector == nullptr ? aEnvFlags : getTimestampFlags(pLogSelector));
if (outputTimestamp)
{
@@ -340,6 +345,11 @@ void sal_detail_log(
#endif
}
+void sal_detail_set_log_selector(char const *logSelector)
+{
+ pLogSelector = logSelector;
+}
+
void sal_detail_logFormat(
sal_detail_LogLevel level, char const * area, char const * where,
char const * format, ...)
@@ -372,12 +382,13 @@ unsigned char sal_detail_log_report(sal_detail_LogLevel level, char const * area
return SAL_DETAIL_LOG_ACTION_LOG;
}
assert(area != nullptr);
- static char const* const env = [] {
- char const* pResult = getLogLevel();
+ static char const* const envEnv = [] {
+ char const* pResult = getLogLevelEnvVar();
if (!pResult)
pResult = "+WARN";
return pResult;
}();
+ char const* const env = (pLogSelector == nullptr ? envEnv : pLogSelector);
std::size_t areaLen = std::strlen(area);
enum Sense { POSITIVE = 0, NEGATIVE = 1 };
std::size_t senseLen[2] = { 0, 1 };
diff --git a/sal/util/sal.map b/sal/util/sal.map
index dbd22c36ee16..49efb2a436cd 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -747,6 +747,7 @@ PRIVATE_1.6 { # LibreOffice 6.4
global:
rtl_str_toInt64_WithLength;
rtl_ustr_toInt64_WithLength;
+ sal_detail_set_log_selector;
} PRIVATE_1.5;
PRIVATE_1.7 { # LibreOffice 7.1