Skip to content

Commit

Permalink
Merge pull request orhanobut#32 from orhanobut/oo/method-offset
Browse files Browse the repository at this point in the history
method count offset
  • Loading branch information
orhanobut committed May 30, 2015
2 parents 5abbc15 + c527157 commit 0cd51f5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Logger provides :

### Gradle
```groovy
compile 'com.orhanobut:logger:1.9'
compile 'com.orhanobut:logger:1.10'
```

### Current Log system
Expand Down Expand Up @@ -72,6 +72,7 @@ public class MyApplication extends Application {
.setMethodCount(3) // default 2
.hideThreadInfo() // default shown
.setLogLevel(LogLevel.NONE); // default LogLevel.FULL
.setMethodOffset(2) // default 0
}
}
```
Expand Down Expand Up @@ -111,6 +112,11 @@ Logger.t(1).d("hello");

<img src='https://github.com/orhanobut/logger/blob/master/images/one-method-with-thread.png'/>

### Change method stack offset (Default: 0)
To integrate logger with other libraries, you can set the offset in order to avoid that library's methods.
```java
Logger.init().setMethodOffset(5);
```

### Hide thread information
```java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Logger.init("test").hideThreadInfo().setMethodCount(0);
Logger.init("test").hideThreadInfo().setMethodCount(3).setMethodOffset(2);

printNormalLog();
printPretty();
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
# org.gradle.parallel=true

#VERSION_NAME=1.0-SNAPSHOT
VERSION_NAME=1.9
VERSION_CODE=10
VERSION_NAME=1.10
VERSION_CODE=11
GROUP=com.orhanobut

POM_DESCRIPTION=Simple,pretty and powerful log
Expand Down
23 changes: 23 additions & 0 deletions logger/src/androidTest/java/com/orhanobut/logger/LoggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,27 @@ public void testStackTraceWithHugeMethodCount() {
fail();
}
}

public void testSetMethodOffset() {
try {
Logger.init().setMethodOffset(100);
Assert.assertTrue(true);
} catch (Exception e) {
fail();
}
try {
Logger.init().setMethodOffset(0);
Assert.assertTrue(true);
} catch (Exception e) {
fail();
}
try {
Logger.init()
.setMethodCount(100)
.setMethodOffset(100);
Assert.assertTrue(true);
} catch (Exception e) {
fail();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private void logHeaderContent(int logType, String tag, int methodCount) {
}
String level = "";

int stackOffset = getStackOffset(trace);
int stackOffset = getStackOffset(trace) + settings.getMethodOffset();

//corresponding method count with the current stack may exceeds the stack trace. Trims the count
if (methodCount + stackOffset > trace.length) {
Expand Down
10 changes: 10 additions & 0 deletions logger/src/main/java/com/orhanobut/logger/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public final class Settings {

private int methodCount = 2;
private boolean showThreadInfo = true;
private int methodOffset = 0;

/**
* Determines how logs will printed
Expand All @@ -28,6 +29,11 @@ public Settings setLogLevel(LogLevel logLevel) {
return this;
}

public Settings setMethodOffset(int offset) {
this.methodOffset = offset;
return this;
}

public int getMethodCount() {
return methodCount;
}
Expand All @@ -39,4 +45,8 @@ public boolean isShowThreadInfo() {
public LogLevel getLogLevel() {
return logLevel;
}

public int getMethodOffset() {
return methodOffset;
}
}

0 comments on commit 0cd51f5

Please sign in to comment.