Bläddra i källkod

LogHelper.kt

日志工具
master
xuqm 1 år sedan
förälder
incheckning
37f2fe8469
8 ändrade filer med 158 tillägg och 0 borttagningar
  1. +6
    -0
      .idea/vcs.xml
  2. +1
    -0
      app/build.gradle
  3. +5
    -0
      app/src/main/java/cn/org/bjca/trust/pushdemo/MainActivity.kt
  4. +1
    -0
      app/src/main/res/layout/activity_main.xml
  5. +6
    -0
      push/src/main/AndroidManifest.xml
  6. +13
    -0
      push/src/main/java/cn/org/bjca/trust/push/common/FileHelper.kt
  7. +81
    -0
      push/src/main/java/cn/org/bjca/trust/push/common/LogHelper.kt
  8. +45
    -0
      push/src/main/java/cn/org/bjca/trust/push/provider/PushProvider.kt

+ 6
- 0
.idea/vcs.xml Visa fil

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 1
- 0
app/build.gradle Visa fil

@@ -38,6 +38,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation project(path: ':push')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

+ 5
- 0
app/src/main/java/cn/org/bjca/trust/pushdemo/MainActivity.kt Visa fil

@@ -2,10 +2,15 @@ package cn.org.bjca.trust.pushdemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import cn.org.bjca.trust.push.common.FileHelper

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
findViewById<TextView>(R.id.tv).setOnClickListener {
FileHelper.openFile()
}
}
}

+ 1
- 0
app/src/main/res/layout/activity_main.xml Visa fil

@@ -7,6 +7,7 @@
tools:context=".MainActivity">

<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"


+ 6
- 0
push/src/main/AndroidManifest.xml Visa fil

@@ -1,4 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<provider
android:name=".provider.PushProvider"
android:authorities="${applicationId}.szyx.push"
android:exported="false" />
</application>
</manifest>

+ 13
- 0
push/src/main/java/cn/org/bjca/trust/push/common/FileHelper.kt Visa fil

@@ -0,0 +1,13 @@
package cn.org.bjca.trust.push.common

class FileHelper {
companion object {
private const val TAG = "FileHelper"
fun openFile() {
LogHelper.e("openFile")
LogHelper.e("openFile","tag")
LogHelper.e("openFile",Throwable("报错了"))
LogHelper.e("openFile",Throwable("报错了"),"这是TAG")
}
}
}

+ 81
- 0
push/src/main/java/cn/org/bjca/trust/push/common/LogHelper.kt Visa fil

@@ -0,0 +1,81 @@
package cn.org.bjca.trust.push.common

import android.util.Log

class LogHelper {
companion object {
const val TAG = "=====>SZYX_PUSH<====="
var showLog = true

/**
* e
*/
fun e(message: String) {
e(message, null, null)
}

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

fun e(message: String, tr: Throwable) {
e(message, tr, null)
}

fun e(message: String, tr: Throwable?, tag: String?) {
println(tr, tag) {
if (tr != null) {
Log.e(TAG, message, tr)
} else {
Log.e(TAG, message)
}
}
}

/**
* d
*/
fun d(message: String, tag: String? = null) {
d(message, null, tag)
}

fun d(message: String, tr: Throwable?, tag: String? = null) {
println(tr, tag) {
if (tr != null) {
Log.d(TAG, message, tr)
} else {
Log.e(TAG, message)
}
}
}

private fun println(tr: Throwable?, tag: String?, log: () -> Unit) {
if (!showLog) return
Log.e(
TAG, ""
)
Log.e(
TAG, "======================================================================"
)
Log.e(
TAG, getTag(tr, tag)
)
Log.e(
TAG, "----------------${tag ?: "-"}----------------"
)
log()
Log.e(
TAG, "======================================================================"
)
Log.e(
TAG, ""
)
}

fun getTag(tr: Throwable?, tag: String?): String {
val caller: StackTraceElement =
Thread.currentThread().stackTrace[if (tr != null && tag != null) 5 else 6]
return "${caller.methodName}(${caller.fileName}:${caller.lineNumber})"
}
}
}

+ 45
- 0
push/src/main/java/cn/org/bjca/trust/push/provider/PushProvider.kt Visa fil

@@ -0,0 +1,45 @@
package cn.org.bjca.trust.push.provider

import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri
import cn.org.bjca.trust.push.common.LogHelper

class PushProvider : ContentProvider() {
override fun onCreate(): Boolean {
LogHelper.e("ContentProvider")
return true
}

override fun query(
uri: Uri,
projection: Array<out String>?,
selection: String?,
selectionArgs: Array<out String>?,
sortOrder: String?
): Cursor? {
TODO("Not yet implemented")
}

override fun getType(uri: Uri): String? {
TODO("Not yet implemented")
}

override fun insert(uri: Uri, values: ContentValues?): Uri? {
TODO("Not yet implemented")
}

override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int {
TODO("Not yet implemented")
}

override fun update(
uri: Uri,
values: ContentValues?,
selection: String?,
selectionArgs: Array<out String>?
): Int {
TODO("Not yet implemented")
}
}

Laddar…
Avbryt
Spara