Skip to content

Commit

Permalink
feat:update log format
Browse files Browse the repository at this point in the history
  • Loading branch information
彭旭锐 committed Sep 22, 2021
1 parent dfcf194 commit a5afd2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions easytrack/src/main/java/com/pengxr/easytrack/core/EasyTrack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,29 @@ internal fun Any.doTrackEvent(eventName: String, otherParams: TrackParams? = nul
return otherParams
}
// 3. Log.
if (EasyTrack.debug) {
val logStr = StringBuilder().apply {
val logStrBuilder = if (EasyTrack.debug) {
StringBuilder().apply {
append(" ")
append("\nonEvent:$eventName")
for ((key, value) in params) {
append("\n$key = $value")
}
append("\n------------------------------------------------------")
}.toString()
Log.d(TAG, logStr)
}
} else {
null
}
// 4. Do event reporting.
for (provider in EasyTrack.providers) {
if (!provider.enabled) {
Log.d(TAG, "Try track event $eventName, but the provider is disabled.")
logStrBuilder?.append("\nTry track event $eventName, but the provider is disabled.")
continue
}
Log.d(TAG, "Try track event $eventName with provider ${provider.name}.")
logStrBuilder?.append("\nTry track event $eventName with provider ${provider.name}.")
provider.onEvent(eventName, params)
}
logStrBuilder?.append("\n------------------------------------------------------")?.also {
Log.d(TAG, it.toString())
}
return params
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ var View.trackModel: ITrackModel?
* Do event track, it will collect event Params around the node tree.
*/
@JvmOverloads
fun ComponentActivity?.trackEvent(eventName: String, params: TrackParams? = null) =
fun Activity?.trackEvent(eventName: String, params: TrackParams? = null) =
findRootView(this)?.doTrackEvent(eventName, params)

@JvmOverloads
Expand Down

0 comments on commit a5afd2c

Please sign in to comment.