Reduce verbosity of logging

This commit is contained in:
Peter Serwylo 2017-07-06 11:06:55 +10:00
parent ba84bbb9ea
commit acbf563724
4 changed files with 56 additions and 7 deletions

View File

@ -0,0 +1,23 @@
package org.fdroid.fdroid.shadows;
import android.annotation.SuppressLint;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
/**
* Workaround for the large amount of "WARNING: unknown service appops" messages which clogged up our CI output.
*/
@Implements(className = org.robolectric.shadows.ShadowContextImpl.CLASS_NAME)
@SuppressLint("Unused")
public class ShadowContextImpl extends org.robolectric.shadows.ShadowContextImpl {
@Override
@Implementation
public Object getSystemService(String name) {
if ("appops".equals(name)) {
return null;
}
return super.getSystemService(name);
}
}

View File

@ -0,0 +1,32 @@
package org.fdroid.fdroid.shadows;
import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.util.Log;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
/**
* There are two lines of output which end up in our CI 1000s of times:
*
* - I/CursorWindowStats: Created a new Cursor. # Open Cursors=1 (# cursors opened by this proc=1)
* - D/SQLiteCursor: received count(*) from native_fill_window: 0
*
* Neither of them seem like they are telling us anything useful, so this suppresses them by intercepting the call
* to {@link Log#isLoggable(String, int)} and returning if it matches either of them.
*/
@Implements(Log.class)
@SuppressLint("Unused")
public class ShadowLog extends org.robolectric.shadows.ShadowLog {
@Implementation
public static synchronized boolean isLoggable(String tag, int level) {
if ((TextUtils.equals(tag, "CursorWindowStats") && level <= Log.INFO)
|| (TextUtils.equals(tag, "SQLiteCursor") && level <= Log.DEBUG)) {
return false;
}
return org.robolectric.shadows.ShadowLog.isLoggable(tag, level);
}
}

View File

@ -32,12 +32,10 @@ import org.fdroid.fdroid.data.App;
import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.data.RepoPushRequest;
import org.fdroid.fdroid.mock.RepoDetails;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowLog;
import java.io.File;
import java.io.IOException;
@ -62,11 +60,6 @@ public class RepoXMLHandlerTest {
private static final String FAKE_SIGNING_CERT = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345"; // NOCHECKSTYLE LineLength
@Before
public void setUp() {
ShadowLog.stream = System.out;
}
@Test
public void testExtendedPerms() throws IOException {
Repo expectedRepo = new Repo();

View File

@ -0,0 +1 @@
shadows=org.fdroid.fdroid.shadows.ShadowContextImpl,org.fdroid.fdroid.shadows.ShadowLog