提交 1af80d2a 编写于 作者: Z zhaokaiqiang

update to 1.5.0

1.add support for global tag
2.bug fixed:can't link line when in the inner class
3.update simple code
上级 227064b9
......@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.socks.klog.sample"
......@@ -29,9 +29,9 @@ android {
}
dependencies {
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'cz.msebera.android:httpclient:4.3.6'
compile 'com.github.zhaokaiqiang.klog:library:1.4.0'
compile 'com.github.zhaokaiqiang.klog:library:1.5.0'
// compile project(':library')
}
......@@ -12,6 +12,7 @@ public class KLogApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
KLog.init(BuildConfig.LOG_DEBUG);
// KLog.init(BuildConfig.LOG_DEBUG);
KLog.init(BuildConfig.LOG_DEBUG, "Kai");
}
}
package com.socks.sample;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
......@@ -26,14 +30,34 @@ public class MainActivity extends AppCompatActivity {
private static String STRING_LONG;
private AsyncHttpClient httpClient;
private static Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
KLog.d("handleMessage");
handler.sendEmptyMessageDelayed(0, 3000);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
initView();
initData();
handler.sendEmptyMessageDelayed(0, 3000);
}
private void initView() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolBar);
if (toolbar != null) {
toolbar.setTitleTextColor(Color.WHITE);
setSupportActionBar(toolbar);
}
}
private void init() {
private void initData() {
httpClient = new AsyncHttpClient();
JSON_LONG = getResources().getString(R.string.json_long);
JSON = getResources().getString(R.string.json);
......@@ -147,7 +171,7 @@ public class MainActivity extends AppCompatActivity {
case R.id.action_github:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/ZhaoKaiQiang/KLog")));
break;
case R.id.action_csdn:
case R.id.action_blog:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://blog.csdn.net/zhaokaiqiang1992")));
break;
}
......
......@@ -2,78 +2,100 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<Button
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="log"
android:text="Log.d()" />
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:theme="@style/ToolbarTheme"/>
<Button
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithNull"
android:text="Log.d(NULL)" />
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithMsg"
android:text="Log.d(Object)" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithLong"
android:text="Log.d(Long String)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="log"
android:text="Log.d()" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithTag"
android:text="Log.d(TAG,Object)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithNull"
android:text="Log.d(NULL)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithParams"
android:text="Log.d(TAG,Object,Params)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithMsg"
android:text="Log.d(Object)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithJson"
android:text="Log.json(JSON)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithLong"
android:text="Log.d(Long String)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithLongJson"
android:text="Log.json(LONG JSON)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithTag"
android:text="Log.d(TAG,Object)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithJsonTag"
android:text="Log.json(TAG,JSON)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithParams"
android:text="Log.d(TAG,Object,Params)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithFile"
android:text="Log.file(File)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithJson"
android:text="Log.json(JSON)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithXml"
android:text="Log.xml(XML)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithXmlFromNet"
android:text="Log.xml(FROM NET)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithLongJson"
android:text="Log.json(LONG JSON)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithJsonTag"
android:text="Log.json(TAG,JSON)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithFile"
android:text="Log.file(File)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithXml"
android:text="Log.xml(XML)" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="logWithXmlFromNet"
android:text="Log.xml(FROM NET)" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_github"
android:orderInCategory="100"
android:title="GITHUB"
app:showAsAction="always" />
android:title="@string/github"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_csdn"
android:orderInCategory="100"
android:title="CSDN"
app:showAsAction="always" />
android:id="@+id/action_blog"
android:title="@string/blog"
app:showAsAction="ifRoom" />
</menu>
......@@ -519,4 +519,6 @@ public class StickyNavLayout extends LinearLayout {
演示代码下载:https://github.com/ZhaoKaiQiang/ScrollerDemo
</string>
<string name="github">GITHUB</string>
<string name="blog">BLOG</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<item name="actionMenuTextColor">@android:color/white</item>
</style>
</resources>
......@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.android.tools.build:gradle:2.2.0-alpha3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
// NOTE: Do not place your application dependencies here; they belong
......
#Wed Oct 21 11:34:03 PDT 2015
#Sun Jun 12 23:20:37 CST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
无法预览此类型文件
......@@ -4,7 +4,7 @@ apply plugin: 'com.jfrog.bintray'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
......@@ -23,7 +23,11 @@ android {
}
}
version = "1.4.0"
dependencies {
compile 'com.android.support:support-annotations:23.4.0'
}
version = "1.5.0"
def siteUrl = 'https://github.com/ZhaoKaiQiang/KLog'
def gitUrl = 'https://github.com/ZhaoKaiQiang/KLog.git'
group = "com.github.zhaokaiqiang.klog"
......
package com.socks.library;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import com.socks.library.klog.BaseLog;
......@@ -24,35 +25,47 @@ import java.io.File;
* 15/11/18 扩展功能,增加对XML的支持,修复BUG
* 15/12/8 扩展功能,添加对任意参数的支持
* 15/12/11 扩展功能,增加对无限长字符串支持
* 16/6/13 扩展功能,添加对自定义全局Tag的支持
*/
public class KLog {
public static final String DEFAULT_MESSAGE = "execute";
public static final String LINE_SEPARATOR = System.getProperty("line.separator");
public static final String NULL_TIPS = "Log with null object";
public static final String PARAM = "Param";
public static final String NULL = "null";
public static final String TAG_DEFAULT = "KLog";
public static final String SUFFIX = ".java";
public static final int JSON_INDENT = 4;
private static final String DEFAULT_MESSAGE = "execute";
private static final String PARAM = "Param";
private static final String NULL = "null";
private static final String TAG_DEFAULT = "KLog";
private static final String SUFFIX = ".java";
public static final int JSON_INDENT = 4;
public static final int V = 0x1;
public static final int D = 0x2;
public static final int I = 0x3;
public static final int W = 0x4;
public static final int E = 0x5;
public static final int A = 0x6;
public static final int JSON = 0x7;
public static final int XML = 0x8;
private static boolean IS_SHOW_LOG = true;
private static final int JSON = 0x7;
private static final int XML = 0x8;
private static final int STACK_TRACE_INDEX = 5;
private static String mGlobalTag;
private static boolean mIsGlobalTagEmpty = true;
private static boolean IS_SHOW_LOG = true;
public static void init(boolean isShowLog) {
IS_SHOW_LOG = isShowLog;
}
public static void init(boolean isShowLog, @Nullable String tag) {
IS_SHOW_LOG = isShowLog;
mGlobalTag = tag;
mIsGlobalTagEmpty = TextUtils.isEmpty(mGlobalTag);
}
public static void v() {
printLog(V, null, DEFAULT_MESSAGE);
}
......@@ -207,6 +220,11 @@ public class KLog {
if (classNameInfo.length > 0) {
className = classNameInfo[classNameInfo.length - 1] + SUFFIX;
}
if (className.contains("$")) {
className = className.split("\\$")[0] + SUFFIX;
}
String methodName = targetElement.getMethodName();
int lineNumber = targetElement.getLineNumber();
......@@ -217,9 +235,13 @@ public class KLog {
String methodNameShort = methodName.substring(0, 1).toUpperCase() + methodName.substring(1);
String tag = (tagStr == null ? className : tagStr);
if (TextUtils.isEmpty(tag)) {
if (mIsGlobalTagEmpty && TextUtils.isEmpty(tag)) {
tag = TAG_DEFAULT;
} else if (!mIsGlobalTagEmpty) {
tag = mGlobalTag;
}
String msg = (objects == null) ? NULL_TIPS : getObjectsString(objects);
String headString = "[ (" + className + ":" + lineNumber + ")#" + methodNameShort + " ] ";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册