summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2013-01-05 22:57:39 +0200
committerTor Lillqvist <tml@iki.fi>2013-01-05 23:04:43 +0200
commit60628799633ffde502cb105b98d3f254f93115aa (patch)
treebdfd522fd8e419c5153dd97b29a11e64a12797f7 /sal
parent16bac2ba920a2d04ef83e36299aec42ff0ac8c18 (diff)
Notice if SAL_LOG is changed while the process is running
It used to call getenv("SAL_LOG") just once and assume it never changed. Sure, I don't expect that LO code will start changing SAL_LOG back and forth all the time. But it is definitely useful in our Android (and iOS) apps to be able to call for instance putenv("SAL_LOG=+WARN+INFO") as early as possible, before explicitly using any LO code. That used to work earlier, but not any more with the getEnvironmentVariable() thing, as the new logging mechanism gets called while initialising some static globals (i.e. before out app code had even started), and that then caused the one and only call to getenv("SAL_LOG"). This meant that we didn't get any debugging logging from SAL_INFO and friends in the Android app(s) any more. Change-Id: I932facff4118e5f016c95a4c1461e871184d3fc6
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/all/log.cxx17
1 files changed, 14 insertions, 3 deletions
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 7e43082cc85a..6b98c0411434 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -56,6 +56,9 @@
#define OSL_DETAIL_GETPID getpid()
#endif
+#include <android/log.h>
+#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "log.cxx", __VA_ARGS__))
+
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
// sal/osl/unx/salinit.cxx::sal_detail_initialize updates this:
@@ -91,15 +94,23 @@ char const * toString(sal_detail_LogLevel level) {
// getenv is not thread safe, so minimize use of result:
char const * getEnvironmentVariable() {
+ static char const * cached_value = NULL;
char const * p1 = std::getenv("SAL_LOG");
if (p1 == 0) {
return "+WARN";
}
- char const * p2 = strdup(p1); // leaked
+ char * p2 = strdup(p1); // leaked whenever it has changed
if (p2 == 0) {
std::abort(); // cannot do much here
}
- return p2;
+ if (cached_value == NULL) {
+ cached_value = p2;
+ } else if (strcmp(cached_value, p2) == 0) {
+ free(p2);
+ } else {
+ cached_value = p2;
+ }
+ return cached_value;
}
#ifdef HAVE_SYSLOG_H
@@ -122,7 +133,7 @@ bool report(sal_detail_LogLevel level, char const * area) {
if (level == SAL_DETAIL_LOG_LEVEL_DEBUG)
return true;
assert(area != 0);
- static char const * env = getEnvironmentVariable();
+ char const * env = getEnvironmentVariable();
std::size_t areaLen = std::strlen(area);
enum Sense { POSITIVE = 0, NEGATIVE = 1 };
std::size_t senseLen[2] = { 0, 1 };