/** * returns 1 if this log line should be printed based on its priority * and tag, and 0 if it should not */ LIBLOG_ABI_PUBLIC int android_log_shouldPrintLine ( AndroidLogFormat *p_format, const char *tag, android_LogPriority pri) { return pri >= filterPriForTag(p_format, tag); }
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 }