Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ChayChan
KLog
提交
2ce3b5bd
K
KLog
项目概览
ChayChan
/
KLog
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
KLog
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2ce3b5bd
编写于
11月 14, 2016
作者:
Z
zkq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add debug and trace method
上级
f3940563
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
139 addition
and
58 deletion
+139
-58
KLog.iml
KLog.iml
+0
-19
app/build.gradle
app/build.gradle
+2
-2
app/src/main/java/com/socks/sample/MainActivity.java
app/src/main/java/com/socks/sample/MainActivity.java
+11
-2
app/src/main/java/com/socks/sample/TestTraceUtil.java
app/src/main/java/com/socks/sample/TestTraceUtil.java
+15
-0
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/activity_main.xml
+14
-2
build.gradle
build.gradle
+2
-2
gradle/wrapper/gradle-wrapper.properties
gradle/wrapper/gradle-wrapper.properties
+2
-2
library/src/main/java/com/socks/library/KLog.java
library/src/main/java/com/socks/library/KLog.java
+68
-11
library/src/main/java/com/socks/library/KLogUtil.java
library/src/main/java/com/socks/library/KLogUtil.java
+1
-1
library/src/main/java/com/socks/library/klog/BaseLog.java
library/src/main/java/com/socks/library/klog/BaseLog.java
+7
-5
library/src/main/java/com/socks/library/klog/FileLog.java
library/src/main/java/com/socks/library/klog/FileLog.java
+9
-4
library/src/main/java/com/socks/library/klog/JsonLog.java
library/src/main/java/com/socks/library/klog/JsonLog.java
+3
-3
library/src/main/java/com/socks/library/klog/XmlLog.java
library/src/main/java/com/socks/library/klog/XmlLog.java
+5
-5
未找到文件。
KLog.iml
已删除
100644 → 0
浏览文件 @
f3940563
<?xml version="1.0" encoding="UTF-8"?>
<module
external.linked.project.id=
"KLog"
external.linked.project.path=
"$MODULE_DIR$"
external.root.project.path=
"$MODULE_DIR$"
external.system.id=
"GRADLE"
external.system.module.group=
""
external.system.module.version=
"unspecified"
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"FacetManager"
>
<facet
type=
"java-gradle"
name=
"Java-Gradle"
>
<configuration>
<option
name=
"BUILD_FOLDER_PATH"
value=
"$MODULE_DIR$/build"
/>
<option
name=
"BUILDABLE"
value=
"false"
/>
</configuration>
</facet>
</component>
<component
name=
"NewModuleRootManager"
LANGUAGE_LEVEL=
"JDK_1_7"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<excludeFolder
url=
"file://$MODULE_DIR$/.gradle"
/>
</content>
<orderEntry
type=
"inheritedJdk"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
app/build.gradle
浏览文件 @
2ce3b5bd
...
@@ -32,6 +32,6 @@ dependencies {
...
@@ -32,6 +32,6 @@ dependencies {
compile
'com.android.support:appcompat-v7:23.4.0'
compile
'com.android.support:appcompat-v7:23.4.0'
compile
'com.loopj.android:android-async-http:1.4.9'
compile
'com.loopj.android:android-async-http:1.4.9'
compile
'cz.msebera.android:httpclient:4.3.6'
compile
'cz.msebera.android:httpclient:4.3.6'
compile
'com.github.zhaokaiqiang.klog:library:1.5.0'
//
compile 'com.github.zhaokaiqiang.klog:library:1.5.0'
//
compile project(':library')
compile
project
(
':library'
)
}
}
app/src/main/java/com/socks/sample/MainActivity.java
浏览文件 @
2ce3b5bd
...
@@ -34,8 +34,7 @@ public class MainActivity extends AppCompatActivity {
...
@@ -34,8 +34,7 @@ public class MainActivity extends AppCompatActivity {
@Override
@Override
public
void
handleMessage
(
Message
msg
)
{
public
void
handleMessage
(
Message
msg
)
{
KLog
.
d
(
"handleMessage"
);
KLog
.
d
(
"Inner Class Test"
);
handler
.
sendEmptyMessageDelayed
(
0
,
3000
);
}
}
};
};
...
@@ -64,6 +63,16 @@ public class MainActivity extends AppCompatActivity {
...
@@ -64,6 +63,16 @@ public class MainActivity extends AppCompatActivity {
STRING_LONG
=
getString
(
R
.
string
.
string_long
);
STRING_LONG
=
getString
(
R
.
string
.
string_long
);
}
}
public
void
logTraceStack
(
View
view
)
{
TestTraceUtil
.
testTrace
();
}
public
void
logDebug
(
View
view
)
{
KLog
.
debug
();
KLog
.
debug
(
"This is a debug message"
);
KLog
.
debug
(
"DEBUG"
,
"params1"
,
"params2"
,
this
);
}
public
void
log
(
View
view
)
{
public
void
log
(
View
view
)
{
KLog
.
v
();
KLog
.
v
();
KLog
.
d
();
KLog
.
d
();
...
...
app/src/main/java/com/socks/sample/TestTraceUtil.java
0 → 100644
浏览文件 @
2ce3b5bd
package
com.socks.sample
;
import
com.socks.library.KLog
;
/**
* Created by zhao on 16/6/16.
*/
class
TestTraceUtil
{
static
void
testTrace
()
{
KLog
.
trace
();
}
}
app/src/main/res/layout/activity_main.xml
浏览文件 @
2ce3b5bd
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
<android.support.v7.widget.Toolbar
<android.support.v7.widget.Toolbar
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"?attr/actionBarSize"
android:layout_height=
"?attr/actionBarSize"
android:background=
"@color/colorPrimary"
android:background=
"@color/colorPrimary"
app:theme=
"@style/ToolbarTheme"
/>
app:theme=
"@style/ToolbarTheme"
/>
<ScrollView
<ScrollView
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
...
@@ -23,6 +23,12 @@
...
@@ -23,6 +23,12 @@
android:paddingLeft=
"16dp"
android:paddingLeft=
"16dp"
android:paddingRight=
"16dp"
>
android:paddingRight=
"16dp"
>
<Button
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:onClick=
"logDebug"
android:text=
"Log.debug()"
/>
<Button
<Button
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
...
@@ -95,6 +101,12 @@
...
@@ -95,6 +101,12 @@
android:onClick=
"logWithXmlFromNet"
android:onClick=
"logWithXmlFromNet"
android:text=
"Log.xml(FROM NET)"
/>
android:text=
"Log.xml(FROM NET)"
/>
<Button
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:onClick=
"logTraceStack"
android:text=
"Log.trace()"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</ScrollView>
...
...
build.gradle
浏览文件 @
2ce3b5bd
...
@@ -5,9 +5,9 @@ buildscript {
...
@@ -5,9 +5,9 @@ buildscript {
jcenter
()
jcenter
()
}
}
dependencies
{
dependencies
{
classpath
'com.android.tools.build:gradle:2.2.
0-alpha3
'
classpath
'com.android.tools.build:gradle:2.2.
2
'
classpath
'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath
'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath
'com.github.dcendents:android-maven-gradle-plugin:1.
3
'
classpath
'com.github.dcendents:android-maven-gradle-plugin:1.
5
'
// NOTE: Do not place your application dependencies here; they belong
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// in the individual module build.gradle files
}
}
...
...
gradle/wrapper/gradle-wrapper.properties
浏览文件 @
2ce3b5bd
#
Sun Jun 12 23:20:37
CST 2016
#
Fri Sep 09 19:39:04
CST 2016
distributionBase
=
GRADLE_USER_HOME
distributionBase
=
GRADLE_USER_HOME
distributionPath
=
wrapper/dists
distributionPath
=
wrapper/dists
zipStoreBase
=
GRADLE_USER_HOME
zipStoreBase
=
GRADLE_USER_HOME
zipStorePath
=
wrapper/dists
zipStorePath
=
wrapper/dists
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-2.1
0
-all.zip
distributionUrl
=
https
\:
//services.gradle.org/distributions/gradle-2.1
4.1
-all.zip
library/src/main/java/com/socks/library/KLog.java
浏览文件 @
2ce3b5bd
...
@@ -10,6 +10,8 @@ import com.socks.library.klog.JsonLog;
...
@@ -10,6 +10,8 @@ import com.socks.library.klog.JsonLog;
import
com.socks.library.klog.XmlLog
;
import
com.socks.library.klog.XmlLog
;
import
java.io.File
;
import
java.io.File
;
import
java.io.PrintWriter
;
import
java.io.StringWriter
;
/**
/**
* This is a Log tool,with this you can the following
* This is a Log tool,with this you can the following
...
@@ -25,9 +27,11 @@ import java.io.File;
...
@@ -25,9 +27,11 @@ import java.io.File;
* 15/11/18 扩展功能,增加对XML的支持,修复BUG
* 15/11/18 扩展功能,增加对XML的支持,修复BUG
* 15/12/8 扩展功能,添加对任意参数的支持
* 15/12/8 扩展功能,添加对任意参数的支持
* 15/12/11 扩展功能,增加对无限长字符串支持
* 15/12/11 扩展功能,增加对无限长字符串支持
* 16/6/13 扩展功能,添加对自定义全局Tag的支持
* 16/6/13 扩展功能,添加对自定义全局Tag的支持,修复内部类不能点击跳转的BUG
* 16/6/15 扩展功能,添加不能关闭的KLog.debug(),用于发布版本的Log打印,优化部分代码
* 16/6/20 扩展功能,添加堆栈跟踪功能KLog.trace()
*/
*/
public
class
KLog
{
public
final
class
KLog
{
public
static
final
String
LINE_SEPARATOR
=
System
.
getProperty
(
"line.separator"
);
public
static
final
String
LINE_SEPARATOR
=
System
.
getProperty
(
"line.separator"
);
public
static
final
String
NULL_TIPS
=
"Log with null object"
;
public
static
final
String
NULL_TIPS
=
"Log with null object"
;
...
@@ -39,8 +43,8 @@ public class KLog {
...
@@ -39,8 +43,8 @@ public class KLog {
private
static
final
String
SUFFIX
=
".java"
;
private
static
final
String
SUFFIX
=
".java"
;
public
static
final
int
JSON_INDENT
=
4
;
public
static
final
int
JSON_INDENT
=
4
;
public
static
final
int
V
=
0x1
;
public
static
final
int
V
=
0x1
;
public
static
final
int
D
=
0x2
;
public
static
final
int
D
=
0x2
;
public
static
final
int
I
=
0x3
;
public
static
final
int
I
=
0x3
;
public
static
final
int
W
=
0x4
;
public
static
final
int
W
=
0x4
;
...
@@ -50,7 +54,8 @@ public class KLog {
...
@@ -50,7 +54,8 @@ public class KLog {
private
static
final
int
JSON
=
0x7
;
private
static
final
int
JSON
=
0x7
;
private
static
final
int
XML
=
0x8
;
private
static
final
int
XML
=
0x8
;
private
static
final
int
STACK_TRACE_INDEX
=
5
;
private
static
final
int
STACK_TRACE_INDEX_5
=
5
;
private
static
final
int
STACK_TRACE_INDEX_4
=
4
;
private
static
String
mGlobalTag
;
private
static
String
mGlobalTag
;
private
static
boolean
mIsGlobalTagEmpty
=
true
;
private
static
boolean
mIsGlobalTagEmpty
=
true
;
...
@@ -166,13 +171,58 @@ public class KLog {
...
@@ -166,13 +171,58 @@ public class KLog {
printFile
(
tag
,
targetDirectory
,
fileName
,
msg
);
printFile
(
tag
,
targetDirectory
,
fileName
,
msg
);
}
}
public
static
void
debug
()
{
printDebug
(
null
,
DEFAULT_MESSAGE
);
}
public
static
void
debug
(
Object
msg
)
{
printDebug
(
null
,
msg
);
}
public
static
void
debug
(
String
tag
,
Object
...
objects
)
{
printDebug
(
tag
,
objects
);
}
public
static
void
trace
()
{
printStackTrace
();
}
private
static
void
printStackTrace
()
{
if
(!
IS_SHOW_LOG
)
{
return
;
}
Throwable
tr
=
new
Throwable
();
StringWriter
sw
=
new
StringWriter
();
PrintWriter
pw
=
new
PrintWriter
(
sw
);
tr
.
printStackTrace
(
pw
);
pw
.
flush
();
String
message
=
sw
.
toString
();
String
traceString
[]
=
message
.
split
(
"\\n\\t"
);
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"\n"
);
for
(
String
trace
:
traceString
)
{
if
(
trace
.
contains
(
"at com.socks.library.KLog"
))
{
continue
;
}
sb
.
append
(
trace
).
append
(
"\n"
);
}
String
[]
contents
=
wrapperContent
(
STACK_TRACE_INDEX_4
,
null
,
sb
.
toString
());
String
tag
=
contents
[
0
];
String
msg
=
contents
[
1
];
String
headString
=
contents
[
2
];
BaseLog
.
printDefault
(
D
,
tag
,
headString
+
msg
);
}
private
static
void
printLog
(
int
type
,
String
tagStr
,
Object
...
objects
)
{
private
static
void
printLog
(
int
type
,
String
tagStr
,
Object
...
objects
)
{
if
(!
IS_SHOW_LOG
)
{
if
(!
IS_SHOW_LOG
)
{
return
;
return
;
}
}
String
[]
contents
=
wrapperContent
(
tagStr
,
objects
);
String
[]
contents
=
wrapperContent
(
STACK_TRACE_INDEX_5
,
tagStr
,
objects
);
String
tag
=
contents
[
0
];
String
tag
=
contents
[
0
];
String
msg
=
contents
[
1
];
String
msg
=
contents
[
1
];
String
headString
=
contents
[
2
];
String
headString
=
contents
[
2
];
...
@@ -193,6 +243,15 @@ public class KLog {
...
@@ -193,6 +243,15 @@ public class KLog {
XmlLog
.
printXml
(
tag
,
msg
,
headString
);
XmlLog
.
printXml
(
tag
,
msg
,
headString
);
break
;
break
;
}
}
}
private
static
void
printDebug
(
String
tagStr
,
Object
...
objects
)
{
String
[]
contents
=
wrapperContent
(
STACK_TRACE_INDEX_5
,
tagStr
,
objects
);
String
tag
=
contents
[
0
];
String
msg
=
contents
[
1
];
String
headString
=
contents
[
2
];
BaseLog
.
printDefault
(
D
,
tag
,
headString
+
msg
);
}
}
...
@@ -202,7 +261,7 @@ public class KLog {
...
@@ -202,7 +261,7 @@ public class KLog {
return
;
return
;
}
}
String
[]
contents
=
wrapperContent
(
tagStr
,
objectMsg
);
String
[]
contents
=
wrapperContent
(
STACK_TRACE_INDEX_5
,
tagStr
,
objectMsg
);
String
tag
=
contents
[
0
];
String
tag
=
contents
[
0
];
String
msg
=
contents
[
1
];
String
msg
=
contents
[
1
];
String
headString
=
contents
[
2
];
String
headString
=
contents
[
2
];
...
@@ -210,11 +269,11 @@ public class KLog {
...
@@ -210,11 +269,11 @@ public class KLog {
FileLog
.
printFile
(
tag
,
targetDirectory
,
fileName
,
headString
,
msg
);
FileLog
.
printFile
(
tag
,
targetDirectory
,
fileName
,
headString
,
msg
);
}
}
private
static
String
[]
wrapperContent
(
String
tagStr
,
Object
...
objects
)
{
private
static
String
[]
wrapperContent
(
int
stackTraceIndex
,
String
tagStr
,
Object
...
objects
)
{
StackTraceElement
[]
stackTrace
=
Thread
.
currentThread
().
getStackTrace
();
StackTraceElement
[]
stackTrace
=
Thread
.
currentThread
().
getStackTrace
();
StackTraceElement
targetElement
=
stackTrace
[
STACK_TRACE_INDEX
];
StackTraceElement
targetElement
=
stackTrace
[
stackTraceIndex
];
String
className
=
targetElement
.
getClassName
();
String
className
=
targetElement
.
getClassName
();
String
[]
classNameInfo
=
className
.
split
(
"\\."
);
String
[]
classNameInfo
=
className
.
split
(
"\\."
);
if
(
classNameInfo
.
length
>
0
)
{
if
(
classNameInfo
.
length
>
0
)
{
...
@@ -232,8 +291,6 @@ public class KLog {
...
@@ -232,8 +291,6 @@ public class KLog {
lineNumber
=
0
;
lineNumber
=
0
;
}
}
String
methodNameShort
=
methodName
.
substring
(
0
,
1
).
toUpperCase
()
+
methodName
.
substring
(
1
);
String
tag
=
(
tagStr
==
null
?
className
:
tagStr
);
String
tag
=
(
tagStr
==
null
?
className
:
tagStr
);
if
(
mIsGlobalTagEmpty
&&
TextUtils
.
isEmpty
(
tag
))
{
if
(
mIsGlobalTagEmpty
&&
TextUtils
.
isEmpty
(
tag
))
{
...
@@ -243,7 +300,7 @@ public class KLog {
...
@@ -243,7 +300,7 @@ public class KLog {
}
}
String
msg
=
(
objects
==
null
)
?
NULL_TIPS
:
getObjectsString
(
objects
);
String
msg
=
(
objects
==
null
)
?
NULL_TIPS
:
getObjectsString
(
objects
);
String
headString
=
"[ ("
+
className
+
":"
+
lineNumber
+
")#"
+
methodName
Short
+
" ] "
;
String
headString
=
"[ ("
+
className
+
":"
+
lineNumber
+
")#"
+
methodName
+
" ] "
;
return
new
String
[]{
tag
,
msg
,
headString
};
return
new
String
[]{
tag
,
msg
,
headString
};
}
}
...
...
library/src/main/java/com/socks/library/Util.java
→
library/src/main/java/com/socks/library/
KLog
Util.java
浏览文件 @
2ce3b5bd
...
@@ -6,7 +6,7 @@ import android.util.Log;
...
@@ -6,7 +6,7 @@ import android.util.Log;
/**
/**
* Created by zhaokaiqiang on 15/12/11.
* Created by zhaokaiqiang on 15/12/11.
*/
*/
public
class
Util
{
public
class
KLog
Util
{
public
static
boolean
isEmpty
(
String
line
)
{
public
static
boolean
isEmpty
(
String
line
)
{
return
TextUtils
.
isEmpty
(
line
)
||
line
.
equals
(
"\n"
)
||
line
.
equals
(
"\t"
)
||
TextUtils
.
isEmpty
(
line
.
trim
());
return
TextUtils
.
isEmpty
(
line
)
||
line
.
equals
(
"\n"
)
||
line
.
equals
(
"\t"
)
||
TextUtils
.
isEmpty
(
line
.
trim
());
...
...
library/src/main/java/com/socks/library/klog/BaseLog.java
浏览文件 @
2ce3b5bd
...
@@ -9,19 +9,21 @@ import com.socks.library.KLog;
...
@@ -9,19 +9,21 @@ import com.socks.library.KLog;
*/
*/
public
class
BaseLog
{
public
class
BaseLog
{
private
static
final
int
MAX_LENGTH
=
4000
;
public
static
void
printDefault
(
int
type
,
String
tag
,
String
msg
)
{
public
static
void
printDefault
(
int
type
,
String
tag
,
String
msg
)
{
int
index
=
0
;
int
index
=
0
;
int
maxLength
=
4000
;
int
length
=
msg
.
length
()
;
int
countOfSub
=
msg
.
length
()
/
maxLength
;
int
countOfSub
=
length
/
MAX_LENGTH
;
if
(
countOfSub
>
0
)
{
if
(
countOfSub
>
0
)
{
for
(
int
i
=
0
;
i
<
countOfSub
;
i
++)
{
for
(
int
i
=
0
;
i
<
countOfSub
;
i
++)
{
String
sub
=
msg
.
substring
(
index
,
index
+
maxLength
);
String
sub
=
msg
.
substring
(
index
,
index
+
MAX_LENGTH
);
printSub
(
type
,
tag
,
sub
);
printSub
(
type
,
tag
,
sub
);
index
+=
maxLength
;
index
+=
MAX_LENGTH
;
}
}
printSub
(
type
,
tag
,
msg
.
substring
(
index
,
msg
.
length
()
));
printSub
(
type
,
tag
,
msg
.
substring
(
index
,
length
));
}
else
{
}
else
{
printSub
(
type
,
tag
,
msg
);
printSub
(
type
,
tag
,
msg
);
}
}
...
...
library/src/main/java/com/socks/library/klog/FileLog.java
浏览文件 @
2ce3b5bd
package
com.socks.library.klog
;
package
com.socks.library.klog
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.util.Log
;
import
android.util.Log
;
import
java.io.File
;
import
java.io.File
;
...
@@ -16,7 +18,10 @@ import java.util.Random;
...
@@ -16,7 +18,10 @@ import java.util.Random;
*/
*/
public
class
FileLog
{
public
class
FileLog
{
public
static
void
printFile
(
String
tag
,
File
targetDirectory
,
String
fileName
,
String
headString
,
String
msg
)
{
private
static
final
String
FILE_PREFIX
=
"KLog_"
;
private
static
final
String
FILE_FORMAT
=
".log"
;
public
static
void
printFile
(
String
tag
,
File
targetDirectory
,
@Nullable
String
fileName
,
String
headString
,
String
msg
)
{
fileName
=
(
fileName
==
null
)
?
getFileName
()
:
fileName
;
fileName
=
(
fileName
==
null
)
?
getFileName
()
:
fileName
;
if
(
save
(
targetDirectory
,
fileName
,
msg
))
{
if
(
save
(
targetDirectory
,
fileName
,
msg
))
{
...
@@ -26,7 +31,7 @@ public class FileLog {
...
@@ -26,7 +31,7 @@ public class FileLog {
}
}
}
}
private
static
boolean
save
(
File
dic
,
String
fileName
,
String
msg
)
{
private
static
boolean
save
(
File
dic
,
@NonNull
String
fileName
,
String
msg
)
{
File
file
=
new
File
(
dic
,
fileName
);
File
file
=
new
File
(
dic
,
fileName
);
...
@@ -36,6 +41,7 @@ public class FileLog {
...
@@ -36,6 +41,7 @@ public class FileLog {
outputStreamWriter
.
write
(
msg
);
outputStreamWriter
.
write
(
msg
);
outputStreamWriter
.
flush
();
outputStreamWriter
.
flush
();
outputStream
.
close
();
outputStream
.
close
();
return
true
;
}
catch
(
FileNotFoundException
e
)
{
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
return
false
;
return
false
;
...
@@ -50,12 +56,11 @@ public class FileLog {
...
@@ -50,12 +56,11 @@ public class FileLog {
return
false
;
return
false
;
}
}
return
true
;
}
}
private
static
String
getFileName
()
{
private
static
String
getFileName
()
{
Random
random
=
new
Random
();
Random
random
=
new
Random
();
return
"KLog_"
+
Long
.
toString
(
System
.
currentTimeMillis
()
+
random
.
nextInt
(
10000
)).
substring
(
4
)
+
".txt"
;
return
FILE_PREFIX
+
Long
.
toString
(
System
.
currentTimeMillis
()
+
random
.
nextInt
(
10000
)).
substring
(
4
)
+
FILE_FORMAT
;
}
}
}
}
library/src/main/java/com/socks/library/klog/JsonLog.java
浏览文件 @
2ce3b5bd
...
@@ -3,7 +3,7 @@ package com.socks.library.klog;
...
@@ -3,7 +3,7 @@ package com.socks.library.klog;
import
android.util.Log
;
import
android.util.Log
;
import
com.socks.library.KLog
;
import
com.socks.library.KLog
;
import
com.socks.library.Util
;
import
com.socks.library.
KLog
Util
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
...
@@ -32,12 +32,12 @@ public class JsonLog {
...
@@ -32,12 +32,12 @@ public class JsonLog {
message
=
msg
;
message
=
msg
;
}
}
Util
.
printLine
(
tag
,
true
);
KLog
Util
.
printLine
(
tag
,
true
);
message
=
headString
+
KLog
.
LINE_SEPARATOR
+
message
;
message
=
headString
+
KLog
.
LINE_SEPARATOR
+
message
;
String
[]
lines
=
message
.
split
(
KLog
.
LINE_SEPARATOR
);
String
[]
lines
=
message
.
split
(
KLog
.
LINE_SEPARATOR
);
for
(
String
line
:
lines
)
{
for
(
String
line
:
lines
)
{
Log
.
d
(
tag
,
"║ "
+
line
);
Log
.
d
(
tag
,
"║ "
+
line
);
}
}
Util
.
printLine
(
tag
,
false
);
KLog
Util
.
printLine
(
tag
,
false
);
}
}
}
}
library/src/main/java/com/socks/library/klog/XmlLog.java
浏览文件 @
2ce3b5bd
...
@@ -4,7 +4,7 @@ import android.util.Log;
...
@@ -4,7 +4,7 @@ import android.util.Log;
import
com.socks.library.KLog
;
import
com.socks.library.KLog
;
import
com.socks.library.Util
;
import
com.socks.library.
KLog
Util
;
import
java.io.StringReader
;
import
java.io.StringReader
;
import
java.io.StringWriter
;
import
java.io.StringWriter
;
...
@@ -30,17 +30,17 @@ public class XmlLog {
...
@@ -30,17 +30,17 @@ public class XmlLog {
xml
=
headString
+
KLog
.
NULL_TIPS
;
xml
=
headString
+
KLog
.
NULL_TIPS
;
}
}
Util
.
printLine
(
tag
,
true
);
KLog
Util
.
printLine
(
tag
,
true
);
String
[]
lines
=
xml
.
split
(
KLog
.
LINE_SEPARATOR
);
String
[]
lines
=
xml
.
split
(
KLog
.
LINE_SEPARATOR
);
for
(
String
line
:
lines
)
{
for
(
String
line
:
lines
)
{
if
(!
Util
.
isEmpty
(
line
))
{
if
(!
KLog
Util
.
isEmpty
(
line
))
{
Log
.
d
(
tag
,
"║ "
+
line
);
Log
.
d
(
tag
,
"║ "
+
line
);
}
}
}
}
Util
.
printLine
(
tag
,
false
);
KLog
Util
.
printLine
(
tag
,
false
);
}
}
p
ublic
static
String
formatXML
(
String
inputXML
)
{
p
rivate
static
String
formatXML
(
String
inputXML
)
{
try
{
try
{
Source
xmlInput
=
new
StreamSource
(
new
StringReader
(
inputXML
));
Source
xmlInput
=
new
StreamSource
(
new
StringReader
(
inputXML
));
StreamResult
xmlOutput
=
new
StreamResult
(
new
StringWriter
());
StreamResult
xmlOutput
=
new
StreamResult
(
new
StringWriter
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录