Kaydet (Commit) 848d477d authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Include PID and TID in SAL_DEBUG output

...and clean up log.cxx somewhat.

Change-Id: I657cf6c938cafa61959a8dc59c9f95dba5183d9f
üst 893404cf
......@@ -28,10 +28,12 @@
#include "logformat.hxx"
#if defined WNT
#if defined ANDROID
#include <android/log.h>
#elif defined WNT
#include <process.h>
#define OSL_DETAIL_GETPID _getpid()
#elif !defined ANDROID
#else
#include <unistd.h>
#define OSL_DETAIL_GETPID getpid()
#endif
......@@ -40,10 +42,8 @@
#include <syslog.h>
// sal/osl/unx/salinit.cxx::sal_detail_initialize updates this:
bool sal_use_syslog;
#endif
#ifdef ANDROID
#include <android/log.h>
#else
enum { sal_use_syslog = false; }
#endif
// Avoid the use of other sal code in this file as much as possible, so that
......@@ -59,8 +59,7 @@ bool equalStrings(
return length1 == length2 && std::memcmp(string1, string2, length1) == 0;
}
#ifndef ANDROID
#if !defined ANDROID
char const * toString(sal_detail_LogLevel level) {
switch (level) {
default:
......@@ -74,12 +73,11 @@ char const * toString(sal_detail_LogLevel level) {
return "debug";
}
}
#endif
// getenv is not thread safe, so minimize use of result; except on Android,
// see 60628799633ffde502cb105b98d3f254f93115aa "Notice if SAL_LOG is
// changed while the process is running":
// getenv is not thread safe, so minimize use of result; except on Android, see
// 60628799633ffde502cb105b98d3f254f93115aa "Notice if SAL_LOG is changed while
// the process is running":
#if defined ANDROID
char const * getEnvironmentVariable() {
......@@ -107,24 +105,6 @@ char const * getEnvironmentVariable() {
#endif
#ifndef ANDROID
#if HAVE_SYSLOG_H
int toSyslogPriority(sal_detail_LogLevel level) {
switch (level) {
default:
assert(false); // this cannot happen
// fall through
case SAL_DETAIL_LOG_LEVEL_INFO:
return LOG_INFO;
case SAL_DETAIL_LOG_LEVEL_WARN:
return LOG_WARNING;
case SAL_DETAIL_LOG_LEVEL_DEBUG:
return LOG_DEBUG;
}
}
#endif
#endif
bool report(sal_detail_LogLevel level, char const * area) {
if (level == SAL_DETAIL_LOG_LEVEL_DEBUG)
return true;
......@@ -199,28 +179,27 @@ void log(
char const * message)
{
std::ostringstream s;
#ifndef ANDROID
#if HAVE_SYSLOG_H
if (!sal_use_syslog)
#endif
#if !defined ANDROID
// On Android, the area will be used as the "tag," and log info already
// contains the PID
if (!sal_use_syslog) {
s << toString(level) << ':';
}
if (level != SAL_DETAIL_LOG_LEVEL_DEBUG) {
s << area << ':';
}
s << OSL_DETAIL_GETPID << ':';
#endif
s << osl::Thread::getCurrentIdentifier() << ':';
if (level == SAL_DETAIL_LOG_LEVEL_DEBUG) {
s << /*no area or where */ ' ' << message << '\n';
s << ' ';
} else {
#ifdef ANDROID
// The area will be used as the "tag", and log info already contgains the pid on Android
#else
s << area << ':' << OSL_DETAIL_GETPID << ':';
#endif
s << osl::Thread::getCurrentIdentifier() << ':';
if (strncmp(where, SRCDIR, sizeof(SRCDIR)-1) == 0)
s << where+sizeof(SRCDIR);
else
s << where;
s << message << '\n';
s << (where
+ (std::strncmp(where, SRCDIR "/", std::strlen(SRCDIR "/")) == 0
? std::strlen(SRCDIR "/") : 0));
}
#ifdef ANDROID
s << message << '\n';
#if defined ANDROID
int android_log_level;
switch (level) {
case SAL_DETAIL_LOG_LEVEL_INFO:
......@@ -236,16 +215,29 @@ void log(
android_log_level = ANDROID_LOG_INFO;
break;
}
if (area == NULL)
area = "LibreOffice";
__android_log_print(android_log_level, area, "%s", s.str().c_str());
__android_log_print(
android_log_level, area == 0 ? "LibreOffice" : area, "%s",
s.str().c_str());
#else
if (sal_use_syslog) {
#if HAVE_SYSLOG_H
if (sal_use_syslog)
syslog(toSyslogPriority(level), "%s", s.str().c_str());
else
int prio;
switch (level) {
case SAL_DETAIL_LOG_LEVEL_INFO:
prio = LOG_INFO;
default:
assert(false); // this cannot happen
// fall through
case SAL_DETAIL_LOG_LEVEL_WARN:
prio = LOG_WARNING;
case SAL_DETAIL_LOG_LEVEL_DEBUG:
prio = LOG_DEBUG;
}
syslog(prio, "%s", s.str().c_str());
#endif
} else {
std::fputs(s.str().c_str(), stderr);
}
#endif
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment