Skip to content

Commit

Permalink
add log i v e ...
Browse files Browse the repository at this point in the history
  • Loading branch information
allens committed Jul 17, 2020
1 parent 096fe05 commit f5bb6ae
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'


// implementation project(':xlog')
implementation 'com.github.JiangHaiYang01:XLogHelper:0.0.1'
implementation project(':xlog')
// implementation 'com.github.JiangHaiYang01:XLogHelper:0.0.1'
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/allens/xloghelper/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)


//添加日志
add.setOnClickListener {

for (i in 1..10) {
Expand All @@ -24,5 +25,17 @@ class MainActivity : AppCompatActivity() {
}
}


//close 之后不能写入
close.setOnClickListener {
XLogHelper.close()
}


//flush 之后 还能够再次写入
flush.setOnClickListener {
XLogHelper.flush(true)
}

}
}
18 changes: 15 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">


<Button
android:id="@+id/add"
android:text="add log"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
android:text="add log" />


<Button
android:id="@+id/close"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="close" />

<Button
android:id="@+id/flush"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="flush" />

</LinearLayout>
3 changes: 0 additions & 3 deletions xlog/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,4 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'


// implementation 'com.tencent.mars:mars-xlog:1.2.3'

}
82 changes: 76 additions & 6 deletions xlog/src/main/java/com/allens/xlog/XLogHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.allens.xlog

import android.content.Context
import com.tencent.mars.xlog.Log
import com.tencent.mars.xlog.Xlog

object XLogHelper {

Expand All @@ -12,67 +13,136 @@ object XLogHelper {
}


//创建
fun create(context: Context): Builder {
return Builder(context)
}

//=====================================================================================
// v
//=====================================================================================
fun v(msg: String) {
v(msg, null)
}

fun v(tag: String, msg: String) {
v(tag, msg, null)
}

fun v(format: String, vararg obj: Any?) {
Log.v(Builder.tag, format, *obj)
v(Builder.tag, format, *obj)
}

fun v(tag: String, format: String, vararg obj: Any?) {
Log.v(tag, format, *obj)
}

//=====================================================================================
// f
//=====================================================================================
fun f(msg: String) {
f(msg, null)
}

fun f(tag: String, msg: String) {
f(tag, msg, null)
}

fun f(format: String, vararg obj: Any?) {
Log.f(Builder.tag, format, *obj)
f(Builder.tag, format, *obj)
}

fun f(tag: String, format: String, vararg obj: Any?) {
Log.f(tag, format, *obj)
}


//=====================================================================================
// e
//=====================================================================================
fun e(msg: String) {
e(msg, null)
}

fun e(tag: String, msg: String) {
e(tag, msg, null)
}

fun e(format: String, vararg obj: Any?) {
Log.e(Builder.tag, format, *obj)
e(Builder.tag, format, *obj)
}

fun e(tag: String, format: String, vararg obj: Any?) {
Log.e(tag, format, *obj)
}

//=====================================================================================
// w
//=====================================================================================
fun w(msg: String) {
w(msg, null)
}

fun w(tag: String, msg: String) {
w(tag, msg, null)
}

fun w(format: String, vararg obj: Any?) {
Log.w(Builder.tag, format, *obj)
w(Builder.tag, format, *obj)
}

fun w(tag: String, format: String, vararg obj: Any?) {
Log.w(tag, format, *obj)
}

//=====================================================================================
// w
//=====================================================================================
fun i(msg: String) {
i(msg, null)
}

fun i(tag: String, msg: String) {
i(tag, msg, null)
}

fun i(format: String, vararg obj: Any?) {
Log.i(Builder.tag, format, *obj)
i(Builder.tag, format, *obj)
}

fun i(tag: String, format: String, vararg obj: Any?) {
Log.i(tag, format, *obj)
}

//=====================================================================================
// d
//=====================================================================================
fun d(msg: String) {
d(msg, null)
}

fun d(tag: String, msg: String) {
d(tag, msg, null)
}

fun d(format: String, vararg obj: Any?) {
Log.d(Builder.tag, format, *obj)
d(Builder.tag, format, *obj)
}

fun d(tag: String, format: String, vararg obj: Any?) {
Log.d(tag, format, *obj)
}

//关闭日志,不再写入
fun close() {
Log.appenderClose()
}

//当日志写入模式为异步时,调用该接口会把内存中的日志写入到文件。
//isSync : true 为同步 flush,flush 结束后才会返回。
//isSync : false 为异步 flush,不等待 flush 结束就返回。
fun flush(isSync: Boolean) {
Log.appenderFlush(isSync)
}


Expand Down

0 comments on commit f5bb6ae

Please sign in to comment.