Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Feb 3, 2021
2 parents 45d0dec + 13237e1 commit 9b4be48
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package network.xyo.helpers

import android.os.Debug
import com.jaredrummler.android.device.DeviceName
import network.xyo.base.XYBase

val currentThreadName : String
get() = Thread.currentThread().name
Expand All @@ -13,11 +12,7 @@ val deviceName: String
val hasDebugger: Boolean
get() = Debug.isDebuggerConnected()

fun sourceNameFromAny(source: Any): String {
return (source as? String) ?: classNameFromObject(source)
}

fun classNameFromObject(objectToCheck: Any): String {
internal fun classNameFromObject(objectToCheck: Any): String {
val parts = objectToCheck.javaClass.kotlin.simpleName?.split('.') ?: return "Unknown"
return parts[parts.lastIndex]
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package network.xyo.logging

import android.util.Log
import network.xyo.base.XYBase
import network.xyo.helpers.classNameFromObject
import network.xyo.helpers.currentThreadName
import network.xyo.helpers.hasDebugger
import network.xyo.helpers.sourceNameFromAny

/* We have everyone of these functions returning 'this' to allow for chaining */

open class XYLogging(private val source: XYBase) {
open class XYLogging(sourceAny: Any) {
private val source = classNameFromObject(sourceAny)

fun error(message: String, reThrow: Boolean): XYLogging {
Log.e(source.className, message)
Log.e(source, message)
val stackTrace = Thread.currentThread().stackTrace
if (!stackTrace.isNullOrEmpty()) {
Log.e(source.className, stackTrace.contentDeepToString().replace(", ", ",\r\n"))
Log.e(source, stackTrace.contentDeepToString().replace(", ", ",\r\n"))
}
if (reThrow) {
throw RuntimeException()
Expand All @@ -29,10 +29,10 @@ open class XYLogging(private val source: XYBase) {
}

fun error(ex: Throwable, reThrow: Boolean): XYLogging {
Log.e(source.className, classNameFromObject(ex))
Log.e(source, classNameFromObject(ex))
val stackTrace = ex.stackTrace
if (!stackTrace.isNullOrEmpty()) {
Log.e(source.className, stackTrace.contentDeepToString().replace(", ", ",\r\n"))
Log.e(source, stackTrace.contentDeepToString().replace(", ", ",\r\n"))
}

if (hasDebugger) {
Expand All @@ -44,31 +44,31 @@ open class XYLogging(private val source: XYBase) {
}

fun error(message: String): XYLogging {
Log.e(sourceNameFromAny(source), "$message:${currentThreadName}")
Log.e(source, "$message:${currentThreadName}")
return this
}

//Normal information used for debugging. Items should be less noisy than Extreme items
fun info(function: String, message: String): XYLogging {
Log.i(sourceNameFromAny(source), "$source:$function:$message [${currentThreadName}]")
Log.i(source, "$source:$function:$message [${currentThreadName}]")
return this
}

fun info(message: String): XYLogging {
Log.i(sourceNameFromAny(source), "$message [${currentThreadName}]")
Log.i(source, "$message [${currentThreadName}]")
return this
}

//Actions are events that are generated by the user, like pushing a button
fun action(action: String): XYLogging {
Log.i(sourceNameFromAny(source), action)
Log.i(source, action)
return this
}

//Status are Large Scale Events, Such As Startup, or Shutdown,
//that may or may not be a result of a user action
fun status(status: String): XYLogging {
Log.i(sourceNameFromAny(source), "App Status: $status")
Log.i(source, "App Status: $status")
return this
}
}
4 changes: 2 additions & 2 deletions base-android-library/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Wed Feb 03 17:55:52 UTC 2021
VERSION_PATCH=10
#Wed Feb 03 19:27:56 UTC 2021
VERSION_PATCH=11

0 comments on commit 9b4be48

Please sign in to comment.