Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
yamin-elmakis committed Jan 11, 2018
1 parent d451897 commit 00c793b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Then add the dependency

dependencies {
...
compile 'com.github.yamin-elmakis:EasyLog:v1.4'
compile 'com.github.yamin-elmakis:EasyLog:v1.5'
}

```
Expand All @@ -43,6 +43,19 @@ enable and init the logger

```

set a custom formatter

``` java

EasyLog.setFormatter(new EasyLogFormatter() {
@Override
public String format(String classname, String methodName, int lineNumber) {
return String.format("[%s] %s.%s() => ", lineNumber, classname, methodName);
}
});

```

examples:

``` java
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/dev/yamin/easylog/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.util.Locale;

import lib.yamin.easylog.EasyLog;
import lib.yamin.easylog.EasyLogFormatter;

public class MainActivity extends AppCompatActivity {

private EasyLogFormatter easyLogFormatter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -28,6 +33,20 @@ public void onClick(View view) {
EasyLog.d();
}
});

findViewById(R.id.main_btn_format).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (easyLogFormatter == null)
easyLogFormatter = new EasyLogFormatter() {
@Override
public String format(String classname, String methodName, int lineNumber) {
return String.format(Locale.getDefault(), "[%d] %s.%s() => ", lineNumber, classname, methodName);
}
};
EasyLog.setFormatter(easyLogFormatter);
}
});
}

private class InnerClass {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
android:layout_height="wrap_content"
android:text="anonymous inner class example"/>

<Button
android:id="@+id/main_btn_format"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Update Formatter"/>

</LinearLayout>
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package lib.yamin.easylog;

import java.util.Locale;

/**
* Created by Yamin on 13-Dec-17.
*/
public class DefaultFormatter extends EasyLogFormatter {

@Override
public String format(String classname, String methodName, int lineNumber) {
return String.format("%s: %s(): %s => ", classname, methodName, lineNumber);
return String.format(Locale.getDefault(), "[%s][%s()][%d]=> ", classname, methodName, lineNumber);
}
}

0 comments on commit 00c793b

Please sign in to comment.