Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix message printed twice when a throwable is given #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions plog-formatter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.MIN_SDK_VERSION as int
targetSdkVersion rootProject.ext.TARGET_SDK_VERSION as int
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

packagingOptions {
Expand All @@ -25,6 +26,9 @@ dependencies {
//For develop only
provided project(':plog')
provided "com.android.support:support-annotations:${rootProject.ext.SUPPORT_VERSION as String}"
androidTestImplementation project(':plog')
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
}

publish {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.mym.plog.formatter;

import android.support.test.runner.AndroidJUnit4;
import android.util.Log;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mym.plog.Formatter;

import static org.junit.Assert.assertEquals;

@RunWith(AndroidJUnit4.class)
public class DefaultFormatterTest {
@Test
public void testFormatThrowableParams() throws Exception {
Formatter formatter = new DefaultFormatter();
Throwable throwable = new Throwable("Test");
String formatted = formatter.format("Throwable is %s", throwable);
assertEquals("Throwable is " + Log.getStackTraceString(throwable), formatted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public String format(String msg, Object... params) throws Exception {
boolean formatted = false;
for (FormatterImpl impl : mFormatterImpls) {
if (isFormatterAvailable(impl.typeFlag, param, impl.supportedClass)){
formattedParam[i] = impl.formatter.format(msg, param);
formattedParam[i] = impl.formatter.format("", param);
formatted = true;
break;
}
Expand Down