-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from orhanobut/log
Change Logger.log() signature to log(priority,"tag","message",throwable)
- Loading branch information
Showing
10 changed files
with
166 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION_NAME=1.14 | ||
VERSION_NAME=1.15 | ||
GROUP=com.orhanobut | ||
|
||
POM_DESCRIPTION=Simple, Pretty and Advanced Logger | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
logger/src/test/java/com.orhanobut.logger/LogAssert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.orhanobut.logger; | ||
|
||
import org.robolectric.shadows.ShadowLog; | ||
|
||
import java.util.List; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
final class LogAssert { | ||
private static final String DEFAULT_TAG = "PRETTYLOGGER"; | ||
|
||
private static final char TOP_LEFT_CORNER = '╔'; | ||
private static final char BOTTOM_LEFT_CORNER = '╚'; | ||
private static final char MIDDLE_CORNER = '╟'; | ||
private static final char HORIZONTAL_DOUBLE_LINE = '║'; | ||
private static final String DOUBLE_DIVIDER = "════════════════════════════════════════════"; | ||
private static final String SINGLE_DIVIDER = "────────────────────────────────────────────"; | ||
private static final String TOP_BORDER = TOP_LEFT_CORNER + DOUBLE_DIVIDER + DOUBLE_DIVIDER; | ||
private static final String BOTTOM_BORDER = BOTTOM_LEFT_CORNER + DOUBLE_DIVIDER + DOUBLE_DIVIDER; | ||
private static final String MIDDLE_BORDER = MIDDLE_CORNER + SINGLE_DIVIDER + SINGLE_DIVIDER; | ||
|
||
private final List<ShadowLog.LogItem> items; | ||
private final int priority; | ||
|
||
private String tag; | ||
|
||
private int index = 0; | ||
|
||
LogAssert(List<ShadowLog.LogItem> items, String tag, int priority) { | ||
this.items = items; | ||
this.tag = tag == null ? DEFAULT_TAG : tag; | ||
this.priority = priority; | ||
} | ||
|
||
public LogAssert hasTopBorder() { | ||
return hasLog(priority, tag, TOP_BORDER); | ||
} | ||
|
||
public LogAssert hasBottomBorder() { | ||
return hasLog(priority, tag, BOTTOM_BORDER); | ||
} | ||
|
||
public LogAssert hasMiddleBorder() { | ||
return hasLog(priority, tag, MIDDLE_BORDER); | ||
} | ||
|
||
public LogAssert hasThread(String threadName) { | ||
return hasLog(priority, tag, HORIZONTAL_DOUBLE_LINE + " " + "Thread: " + threadName); | ||
} | ||
|
||
public LogAssert hasMethodInfo(String methodInfo) { | ||
return hasLog(priority, tag, HORIZONTAL_DOUBLE_LINE + " " + methodInfo); | ||
} | ||
|
||
public LogAssert hasMessage(String message) { | ||
return hasLog(priority, tag, HORIZONTAL_DOUBLE_LINE + " " + message); | ||
} | ||
|
||
private LogAssert hasLog(int priority, String tag, String message) { | ||
ShadowLog.LogItem item = items.get(index++); | ||
assertThat(item.type).isEqualTo(priority); | ||
assertThat(item.tag).isEqualTo(tag); | ||
assertThat(item.msg).isEqualTo(message); | ||
return this; | ||
} | ||
|
||
public LogAssert skip() { | ||
index++; | ||
return this; | ||
} | ||
|
||
public LogAssert defaultTag() { | ||
tag = DEFAULT_TAG; | ||
return this; | ||
} | ||
|
||
public LogAssert hasTag(String tag) { | ||
assertThat(tag).isEqualTo(this.tag); | ||
return this; | ||
} | ||
|
||
public void hasNoMoreMessages() { | ||
assertThat(items).hasSize(index); | ||
ShadowLog.getLogs().clear(); | ||
} | ||
|
||
public LogAssert hasMessageWithDefaultSettings(String... messages) { | ||
hasTopBorder(); | ||
skip(); | ||
hasMiddleBorder(); | ||
skip(); | ||
skip(); | ||
hasMiddleBorder(); | ||
|
||
for (String message : messages) { | ||
hasMessage(message); | ||
} | ||
|
||
hasBottomBorder(); | ||
hasNoMoreMessages(); | ||
|
||
return this; | ||
} | ||
} |
Oops, something went wrong.