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