summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Onorato <joeo@android.com>2010-03-01 09:11:54 -0800
committerJoe Onorato <joeo@android.com>2010-03-01 13:03:19 -0800
commite2bf2ea4d2846031edfc52b942ad53e5467243f6 (patch)
tree76fa7dca61684d78c93755986db60a3a6d3731e4
parentb91bf4ba864a392412397913ee09a8c1f2e7cc87 (diff)
downloadsystem_core-e2bf2ea4d2846031edfc52b942ad53e5467243f6.zip
system_core-e2bf2ea4d2846031edfc52b942ad53e5467243f6.tar.gz
system_core-e2bf2ea4d2846031edfc52b942ad53e5467243f6.tar.bz2
Make logcat print both the main and system buffers by default. Make SLOGx macros work.
-rw-r--r--include/cutils/log.h100
-rw-r--r--include/cutils/logger.h1
-rw-r--r--include/cutils/logprint.h2
-rw-r--r--liblog/logd_write.c62
-rw-r--r--liblog/logprint.c7
-rw-r--r--logcat/logcat.cpp55
6 files changed, 190 insertions, 37 deletions
diff --git a/include/cutils/log.h b/include/cutils/log.h
index ec3cac8..dd47c35 100644
--- a/include/cutils/log.h
+++ b/include/cutils/log.h
@@ -196,6 +196,91 @@ extern "C" {
#define IF_LOGE() IF_LOG(LOG_ERROR, LOG_TAG)
#endif
+
+// ---------------------------------------------------------------------
+
+/*
+ * Simplified macro to send a verbose system log message using the current LOG_TAG.
+ */
+#ifndef SLOGV
+#if LOG_NDEBUG
+#define SLOGV(...) ((void)0)
+#else
+#define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__))
+#endif
+#endif
+
+#define CONDITION(cond) (__builtin_expect((cond)!=0, 0))
+
+#ifndef SLOGV_IF
+#if LOG_NDEBUG
+#define SLOGV_IF(cond, ...) ((void)0)
+#else
+#define SLOGV_IF(cond, ...) \
+ ( (CONDITION(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+#endif
+
+/*
+ * Simplified macro to send a debug system log message using the current LOG_TAG.
+ */
+#ifndef SLOGD
+#define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGD_IF
+#define SLOGD_IF(cond, ...) \
+ ( (CONDITION(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an info system log message using the current LOG_TAG.
+ */
+#ifndef SLOGI
+#define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGI_IF
+#define SLOGI_IF(cond, ...) \
+ ( (CONDITION(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send a warning system log message using the current LOG_TAG.
+ */
+#ifndef SLOGW
+#define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGW_IF
+#define SLOGW_IF(cond, ...) \
+ ( (CONDITION(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+/*
+ * Simplified macro to send an error system log message using the current LOG_TAG.
+ */
+#ifndef SLOGE
+#define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
+#endif
+
+#ifndef SLOGE_IF
+#define SLOGE_IF(cond, ...) \
+ ( (CONDITION(cond)) \
+ ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \
+ : (void)0 )
+#endif
+
+
+
// ---------------------------------------------------------------------
/*
@@ -338,6 +423,21 @@ typedef enum {
#define android_logToFile(tag, file) (0)
#define android_logToFd(tag, fd) (0)
+typedef enum {
+ LOG_ID_MAIN = 0,
+ LOG_ID_RADIO = 1,
+ LOG_ID_EVENTS = 2,
+ LOG_ID_SYSTEM = 3,
+
+ LOG_ID_MAX
+} log_id_t;
+
+/*
+ * Send a simple string to the log.
+ */
+int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text);
+int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...);
+
#ifdef __cplusplus
}
diff --git a/include/cutils/logger.h b/include/cutils/logger.h
index 3a08019..b60f7ad 100644
--- a/include/cutils/logger.h
+++ b/include/cutils/logger.h
@@ -25,6 +25,7 @@ struct logger_entry {
#define LOGGER_LOG_MAIN "log/main"
#define LOGGER_LOG_RADIO "log/radio"
#define LOGGER_LOG_EVENTS "log/events"
+#define LOGGER_LOG_SYSTEM "log/system"
#define LOGGER_ENTRY_MAX_LEN (4*1024)
#define LOGGER_ENTRY_MAX_PAYLOAD \
diff --git a/include/cutils/logprint.h b/include/cutils/logprint.h
index d6ec480..769c8a7 100644
--- a/include/cutils/logprint.h
+++ b/include/cutils/logprint.h
@@ -142,7 +142,7 @@ char *android_log_formatLogLine (
* Assumes single threaded execution
*
*/
-int android_log_filterAndPrintLogLine(
+int android_log_printLogLine(
AndroidLogFormat *p_format,
int fd,
const AndroidLogEntry *entry);
diff --git a/liblog/logd_write.c b/liblog/logd_write.c
index 241dbf0..49ceb92 100644
--- a/liblog/logd_write.c
+++ b/liblog/logd_write.c
@@ -27,6 +27,7 @@
#include <cutils/logger.h>
#include <cutils/logd.h>
+#include <cutils/log.h>
#define LOG_BUF_SIZE 1024
@@ -41,21 +42,13 @@
#define log_close(filedes) close(filedes)
#endif
-typedef enum {
- LOG_ID_MAIN = 0,
- LOG_ID_RADIO,
- LOG_ID_EVENTS,
- LOG_ID_MAX
-} log_id_t;
-
static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr);
-static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) =
- __write_to_log_init;
+static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init;
#ifdef HAVE_PTHREADS
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
-static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1 };
+static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1 };
/*
* This is used by the C++ code to decide if it should write logs through
@@ -110,6 +103,7 @@ static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
log_fds[LOG_ID_MAIN] = log_open("/dev/"LOGGER_LOG_MAIN, O_WRONLY);
log_fds[LOG_ID_RADIO] = log_open("/dev/"LOGGER_LOG_RADIO, O_WRONLY);
log_fds[LOG_ID_EVENTS] = log_open("/dev/"LOGGER_LOG_EVENTS, O_WRONLY);
+ log_fds[LOG_ID_SYSTEM] = log_open("/dev/"LOGGER_LOG_SYSTEM, O_WRONLY);
write_to_log = __write_to_log_kernel;
@@ -123,6 +117,12 @@ static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
log_fds[LOG_ID_EVENTS] = -1;
write_to_log = __write_to_log_null;
}
+
+ printf("LOG_ID_SYSTEM=%d\n", log_fds[LOG_ID_SYSTEM]);
+ printf("LOG_ID_MAIN=%d\n", log_fds[LOG_ID_MAIN]);
+ if (log_fds[LOG_ID_SYSTEM] < 0) {
+ log_fds[LOG_ID_SYSTEM] = log_fds[LOG_ID_MAIN];
+ }
}
#ifdef HAVE_PTHREADS
@@ -161,6 +161,34 @@ int __android_log_write(int prio, const char *tag, const char *msg)
return write_to_log(log_id, vec, 3);
}
+int __android_log_buf_write(int bufID, int prio, const char *tag, const char *msg)
+{
+ struct iovec vec[3];
+
+ if (!tag)
+ tag = "";
+
+ /* XXX: This needs to go! */
+ if (!strcmp(tag, "HTC_RIL") ||
+ !strncmp(tag, "RIL", 3) || /* Any log tag with "RIL" as the prefix */
+ !strcmp(tag, "AT") ||
+ !strcmp(tag, "GSM") ||
+ !strcmp(tag, "STK") ||
+ !strcmp(tag, "CDMA") ||
+ !strcmp(tag, "PHONE") ||
+ !strcmp(tag, "SMS"))
+ bufID = LOG_ID_RADIO;
+
+ vec[0].iov_base = (unsigned char *) &prio;
+ vec[0].iov_len = 1;
+ vec[1].iov_base = (void *) tag;
+ vec[1].iov_len = strlen(tag) + 1;
+ vec[2].iov_base = (void *) msg;
+ vec[2].iov_len = strlen(msg) + 1;
+
+ return write_to_log(bufID, vec, 3);
+}
+
int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
{
char buf[LOG_BUF_SIZE];
@@ -173,7 +201,7 @@ int __android_log_vprint(int prio, const char *tag, const char *fmt, va_list ap)
int __android_log_print(int prio, const char *tag, const char *fmt, ...)
{
va_list ap;
- char buf[LOG_BUF_SIZE];
+ char buf[LOG_BUF_SIZE];
va_start(ap, fmt);
vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
@@ -182,6 +210,18 @@ int __android_log_print(int prio, const char *tag, const char *fmt, ...)
return __android_log_write(prio, tag, buf);
}
+int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...)
+{
+ va_list ap;
+ char buf[LOG_BUF_SIZE];
+
+ va_start(ap, fmt);
+ vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
+ va_end(ap);
+
+ return __android_log_buf_write(bufID, prio, tag, buf);
+}
+
void __android_log_assert(const char *cond, const char *tag,
const char *fmt, ...)
{
diff --git a/liblog/logprint.c b/liblog/logprint.c
index 080f9e3..5ddda36 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -840,7 +840,7 @@ char *android_log_formatLogLine (
* Returns count bytes written
*/
-int android_log_filterAndPrintLogLine(
+int android_log_printLogLine(
AndroidLogFormat *p_format,
int fd,
const AndroidLogEntry *entry)
@@ -850,11 +850,6 @@ int android_log_filterAndPrintLogLine(
char *outBuffer = NULL;
size_t totalLen;
- if (0 == android_log_shouldPrintLine(p_format, entry->tag,
- entry->priority)) {
- return 0;
- }
-
outBuffer = android_log_formatLogLine(p_format, defaultBuffer,
sizeof(defaultBuffer), entry, &totalLen);
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
index 43c9ccd..670408c 100644
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -24,6 +24,7 @@
#define DEFAULT_MAX_ROTATED_LOGS 4
static AndroidLogFormat * g_logformat;
+static bool g_nonblock = false;
/* logd prefixes records with a length field */
#define RECORD_LENGTH_FIELD_SIZE_BYTES sizeof(uint32_t)
@@ -174,16 +175,6 @@ static void processBuffer(log_device_t* dev, struct logger_entry *buf)
}
}
- if (g_devCount > 1) {
- binaryMsgBuf[0] = dev->label;
- binaryMsgBuf[1] = ' ';
- bytesWritten = write(g_outFD, binaryMsgBuf, 2);
- if (bytesWritten < 0) {
- perror("output error");
- exit(-1);
- }
- }
-
if (dev->binary) {
err = android_log_processBinaryLogBuffer(buf, &entry, g_eventTagMap,
binaryMsgBuf, sizeof(binaryMsgBuf));
@@ -192,15 +183,27 @@ static void processBuffer(log_device_t* dev, struct logger_entry *buf)
} else {
err = android_log_processLogBuffer(buf, &entry);
}
- if (err < 0)
+ if (err < 0) {
goto error;
+ }
+
+ if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority)) {
+ if (false && g_devCount > 1) {
+ binaryMsgBuf[0] = dev->label;
+ binaryMsgBuf[1] = ' ';
+ bytesWritten = write(g_outFD, binaryMsgBuf, 2);
+ if (bytesWritten < 0) {
+ perror("output error");
+ exit(-1);
+ }
+ }
- bytesWritten = android_log_filterAndPrintLogLine(
- g_logformat, g_outFD, &entry);
+ bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry);
- if (bytesWritten < 0) {
- perror("output error");
- exit(-1);
+ if (bytesWritten < 0) {
+ perror("output error");
+ exit(-1);
+ }
}
g_outByteCount += bytesWritten;
@@ -318,6 +321,10 @@ static void readLogLines(log_device_t* devices)
}
eatEntry(dev, entry);
}
+ // They requested to just dump the log
+ if (g_nonblock) {
+ exit(0);
+ }
} else {
// print all that aren't the last in their list
while (true) {
@@ -483,7 +490,7 @@ int main(int argc, char **argv)
break;
case 'd':
- mode |= O_NONBLOCK;
+ g_nonblock = true;
break;
case 'g':
@@ -638,8 +645,16 @@ int main(int argc, char **argv)
}
if (!devices) {
- devices = new log_device_t(strdup("/dev/"LOGGER_LOG_MAIN), false, LOGGER_LOG_MAIN[0]);
+ devices = new log_device_t(strdup("/dev/"LOGGER_LOG_MAIN), false, 'm');
android::g_devCount = 1;
+ int accessmode =
+ (mode & O_RDONLY) ? R_OK : 0
+ | (mode & O_WRONLY) ? W_OK : 0;
+ // only add this if it's available
+ if (0 == access("/dev/"LOGGER_LOG_SYSTEM, accessmode)) {
+ devices->next = new log_device_t(strdup("/dev/"LOGGER_LOG_SYSTEM), false, 's');
+ android::g_devCount++;
+ }
}
if (android::g_logRotateSizeKBytes != 0
@@ -714,7 +729,6 @@ int main(int argc, char **argv)
perror("ioctl");
exit(EXIT_FAILURE);
}
- return 0;
}
if (getLogSize) {
@@ -744,6 +758,9 @@ int main(int argc, char **argv)
if (getLogSize) {
return 0;
}
+ if (clearLog) {
+ return 0;
+ }
//LOG_EVENT_INT(10, 12345);
//LOG_EVENT_LONG(11, 0x1122334455667788LL);