コード例 #1
0
static void processBuffer(log_device_t* dev, struct log_msg *buf)
{
    int bytesWritten = 0;
    int err;
    AndroidLogEntry entry;
    char binaryMsgBuf[1024];

    if (dev->binary) {
        static bool hasOpenedEventTagMap = false;
        static EventTagMap *eventTagMap = NULL;

        if (!eventTagMap && !hasOpenedEventTagMap) {
            eventTagMap = android_openEventTagMap(EVENT_TAG_MAP_FILE);
            hasOpenedEventTagMap = true;
        }
        err = android_log_processBinaryLogBuffer(&buf->entry_v1, &entry,
                                                 eventTagMap,
                                                 binaryMsgBuf,
                                                 sizeof(binaryMsgBuf));
        //printf(">>> pri=%d len=%d msg='%s'\n",
        //    entry.priority, entry.messageLen, entry.message);
    } else {
        err = android_log_processLogBuffer(&buf->entry_v1, &entry);
    }
    if (err < 0) {
        goto error;
    }

    if (android_log_shouldPrintLine(g_logformat, entry.tag, entry.priority)) {
        bool match = regexOk(entry);

        g_printCount += match;
        if (match || g_printItAnyways) {
            bytesWritten = android_log_printLogLine(g_logformat, g_outFD, &entry);

            if (bytesWritten < 0) {
                logcat_panic(false, "output error");
            }
        }
    }

    g_outByteCount += bytesWritten;

    if (g_logRotateSizeKBytes > 0
        && (g_outByteCount / 1024) >= g_logRotateSizeKBytes
    ) {
        rotateLogs();
    }

error:
    //fprintf (stderr, "Error processing record\n");
    return;
}
コード例 #2
0
static void processBuffer(log_device_t* dev, struct log_msg *buf)
{
    int bytesWritten = 0;
    int err;
    AndroidLogEntry entry;
    char binaryMsgBuf[1024];

    if (dev->binary) {
        err = android_log_processBinaryLogBuffer(&buf->entry_v1, &entry,
                                                 g_eventTagMap,
                                                 binaryMsgBuf,
                                                 sizeof(binaryMsgBuf));
        //printf(">>> pri=%d len=%d msg='%s'\n",
        //    entry.priority, entry.messageLen, entry.message);
    } else {
        err = android_log_processLogBuffer(&buf->entry_v1, &entry);
    }
    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_printLogLine(g_logformat, g_outFD, &entry);

        if (bytesWritten < 0) {
            perror("output error");
            exit(-1);
        }
    }

    g_outByteCount += bytesWritten;

    if (g_logRotateSizeKBytes > 0
        && (g_outByteCount / 1024) >= g_logRotateSizeKBytes
    ) {
        rotateLogs();
    }

error:
    //fprintf (stderr, "Error processing record\n");
    return;
}
コード例 #3
0
int LogfilterAndBuffering(
		AndroidLogFormat *p_format,
		const AndroidLogEntry *entry, int index)
{
	char *outBuffer = NULL;
	size_t totalLen=0;
	int ret_val=0;
	size_t len=0;
	if (0 == android_log_shouldPrintLine(p_format, entry->tag,
				entry->priority)) {
		VPRINT("No need to output.\n");
		ret_val=0;
		return ret_val;
	}

	outBuffer = android_log_formatLogLine(p_format, defaultBuffer,
			sizeof(defaultBuffer), entry, &totalLen);

	if (!outBuffer){
		EPRINT("Failed in android_log_formatLogLine.\n");
		ret_val=-1;
		return ret_val;
	}
        len= aplogd_rambuf_space(index);
	if(len >  totalLen ){
		memcpy(aplogd_io_array[index].input_buf, outBuffer, totalLen);
		aplogd_io_array[index].input_buf += totalLen;
		ret_val=totalLen;
		if(outBuffer !=defaultBuffer)
			free(outBuffer);
	}else{
		WPRINT("no enough buffer to contain log messages.len=%d totallen=%d.entry->messageLen=%d\n",len, totalLen,entry->messageLen);
		if(outBuffer !=defaultBuffer)
			free(outBuffer);
		ret_val=-1;
		aplogd_bytes_lost += totalLen;
	}
	return ret_val;
}
コード例 #4
0
int alog_filterAndPrintLogLine(AndroidLogFormat *p_format, const AndroidLogEntry *entry,char * dest)
{
    char defaultBuffer[512];
    char *outBuffer = NULL;
    size_t totalLen;

    if (0 == android_log_shouldPrintLine(p_format, entry->tag, entry->priority)) {
        return 0;
    }

    outBuffer = alog_formatLogLine(p_format,defaultBuffer,sizeof(defaultBuffer), entry, &totalLen);

    printk(KERN_INFO "[LastAlog] alog_filterAndPrintLogLine: <outBuffer>:%s", outBuffer);

    if (!outBuffer)
        return -1;

   memcpy(dest, outBuffer,strlen(outBuffer)+1);

    if (outBuffer != defaultBuffer) {
        kfree(outBuffer);
    }
    return strlen(outBuffer)+1;
}
コード例 #5
0
void logprint_run_tests()
{
#if 0

    fprintf(stderr, "tests disabled\n");

#else

    int err;
    const char *tag;
    AndroidLogFormat *p_format;

    p_format = android_log_format_new();

    fprintf(stderr, "running tests\n");

    tag = "random";

    android_log_addFilterRule(p_format,"*:i");

    assert (ANDROID_LOG_INFO == filterPriForTag(p_format, "random"));
    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
    android_log_addFilterRule(p_format, "*");
    assert (ANDROID_LOG_DEBUG == filterPriForTag(p_format, "random"));
    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
    android_log_addFilterRule(p_format, "*:v");
    assert (ANDROID_LOG_VERBOSE == filterPriForTag(p_format, "random"));
    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
    android_log_addFilterRule(p_format, "*:i");
    assert (ANDROID_LOG_INFO == filterPriForTag(p_format, "random"));
    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);

    android_log_addFilterRule(p_format, "random");
    assert (ANDROID_LOG_VERBOSE == filterPriForTag(p_format, "random"));
    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
    android_log_addFilterRule(p_format, "random:v");
    assert (ANDROID_LOG_VERBOSE == filterPriForTag(p_format, "random"));
    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
    android_log_addFilterRule(p_format, "random:d");
    assert (ANDROID_LOG_DEBUG == filterPriForTag(p_format, "random"));
    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
    android_log_addFilterRule(p_format, "random:w");
    assert (ANDROID_LOG_WARN == filterPriForTag(p_format, "random"));
    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);

    android_log_addFilterRule(p_format, "crap:*");
    assert (ANDROID_LOG_VERBOSE== filterPriForTag(p_format, "crap"));
    assert(android_log_shouldPrintLine(p_format, "crap", ANDROID_LOG_VERBOSE) > 0);

    // invalid expression
    err = android_log_addFilterRule(p_format, "random:z");
    assert (err < 0);
    assert (ANDROID_LOG_WARN == filterPriForTag(p_format, "random"));
    assert(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);

    // Issue #550946
    err = android_log_addFilterString(p_format, " ");
    assert(err == 0);
    assert(ANDROID_LOG_WARN == filterPriForTag(p_format, "random"));

    // note trailing space
    err = android_log_addFilterString(p_format, "*:s random:d ");
    assert(err == 0);
    assert(ANDROID_LOG_DEBUG == filterPriForTag(p_format, "random"));

    err = android_log_addFilterString(p_format, "*:s random:z");
    assert(err < 0);


#if 0
    char *ret;
    char defaultBuffer[512];

    ret = android_log_formatLogLine(p_format,
        defaultBuffer, sizeof(defaultBuffer), 0, ANDROID_LOG_ERROR, 123,
        123, 123, "random", "nofile", strlen("Hello"), "Hello", NULL);
#endif


    fprintf(stderr, "tests complete\n");
#endif
}
コード例 #6
0
TEST(liblog, filterRule) {
    static const char tag[] = "random";

    AndroidLogFormat *p_format = android_log_format_new();

    android_log_addFilterRule(p_format,"*:i");

    EXPECT_TRUE(checkPriForTag(p_format, tag, ANDROID_LOG_INFO));
    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);
    android_log_addFilterRule(p_format, "*");
    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_DEBUG));
    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
    android_log_addFilterRule(p_format, "*:v");
    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_VERBOSE));
    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
    android_log_addFilterRule(p_format, "*:i");
    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_INFO));
    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);

    android_log_addFilterRule(p_format, tag);
    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_VERBOSE));
    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
    android_log_addFilterRule(p_format, "random:v");
    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_VERBOSE));
    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
    android_log_addFilterRule(p_format, "random:d");
    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_DEBUG));
    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) > 0);
    android_log_addFilterRule(p_format, "random:w");
    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_WARN));
    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);

    android_log_addFilterRule(p_format, "crap:*");
    EXPECT_TRUE (checkPriForTag(p_format, "crap", ANDROID_LOG_VERBOSE));
    EXPECT_TRUE(android_log_shouldPrintLine(p_format, "crap", ANDROID_LOG_VERBOSE) > 0);

    // invalid expression
    EXPECT_TRUE (android_log_addFilterRule(p_format, "random:z") < 0);
    EXPECT_TRUE (checkPriForTag(p_format, tag, ANDROID_LOG_WARN));
    EXPECT_TRUE(android_log_shouldPrintLine(p_format, tag, ANDROID_LOG_DEBUG) == 0);

    // Issue #550946
    EXPECT_TRUE(android_log_addFilterString(p_format, " ") == 0);
    EXPECT_TRUE(checkPriForTag(p_format, tag, ANDROID_LOG_WARN));

    // note trailing space
    EXPECT_TRUE(android_log_addFilterString(p_format, "*:s random:d ") == 0);
    EXPECT_TRUE(checkPriForTag(p_format, tag, ANDROID_LOG_DEBUG));

    EXPECT_TRUE(android_log_addFilterString(p_format, "*:s random:z") < 0);

#if 0 // bitrot, seek update
    char defaultBuffer[512];

    android_log_formatLogLine(p_format,
        defaultBuffer, sizeof(defaultBuffer), 0, ANDROID_LOG_ERROR, 123,
        123, 123, tag, "nofile", strlen("Hello"), "Hello", NULL);

    fprintf(stderr, "%s\n", defaultBuffer);
#endif

    android_log_format_free(p_format);
}
コード例 #7
0
static bool checkPriForTag(AndroidLogFormat *p_format, const char *tag, android_LogPriority pri) {
    return android_log_shouldPrintLine(p_format, tag, pri)
        && !android_log_shouldPrintLine(p_format, tag, (android_LogPriority)(pri - 1));
}