Skip to content

Commit

Permalink
Config.extraInfo now optional (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssawchenko committed Aug 1, 2023
1 parent 4556517 commit 83513eb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on the Steamclock [Release Management Guide](https://github.com/steamclock/labs/wiki/Release-Management-Guide).

## Unlreleased
- Config.extraInfo now optional (#114)


## Jitpack v2.3 : Jun 19, 2023
- Added UserReports (#110)
- Updated Sentry plugin version; added exclusion for "default" Timber/Sentry integration (#111)
Expand Down
15 changes: 1 addition & 14 deletions app/src/main/java/com/steamclock/steamclogsample/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,7 @@ class App : Application() {
isDebug = BuildConfig.DEBUG,
fileWritePath = externalCacheDir,
filtering = appFiltering,
detailedLogsOnUserReports = true,
extraInfo = { purpose ->
when (purpose) {
ExtraInfoPurpose.Error -> {
mapOf("ExtraInfoPurpose" to "Error")
}
ExtraInfoPurpose.Fatal -> {
mapOf("ExtraInfoPurpose" to "Fatal")
}
ExtraInfoPurpose.UserReport -> {
mapOf("ExtraInfoPurpose" to "UserReport")
}
}
}
detailedLogsOnUserReports = true
))
}

Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/steamclock/steamclogsample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding

private fun getExtraInfo(purpose: ExtraInfoPurpose): Map<String, Any> {
return when (purpose) {
ExtraInfoPurpose.Error -> {
mapOf("ExtraInfoPurpose" to "Error")
}
ExtraInfoPurpose.Fatal -> {
mapOf("ExtraInfoPurpose" to "Fatal")
}
ExtraInfoPurpose.UserReport -> {
mapOf("ExtraInfoPurpose" to "UserReport")
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
Expand All @@ -44,6 +58,9 @@ class MainActivity : AppCompatActivity() {
binding.enableUserReportLogs.setOnCheckedChangeListener { _, checked ->
clog.config.detailedLogsOnUserReports = checked
}
binding.enableExtraConfigInfo.setOnCheckedChangeListener { _, checked ->
clog.config.extraInfo = if (checked) { this::getExtraInfo } else null
}

binding.addUserId.setOnClickListener { clog.setUserId("1234") }

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<CheckBox
android:text="Add extra config info"
android:id="@+id/enable_extra_config_info"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<View
android:layout_width="match_parent"
android:layout_height="20dp" />
Expand Down
2 changes: 1 addition & 1 deletion steamclog/src/main/java/com/steamclock/steamclog/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ data class Config(
* extra info passed into individual logging functions, this info is not redacted in any
* way even if requireRedacted is set, the callback must handle and privacy preservation or redaction
*/
var extraInfo: (ExtraInfoPurpose) -> Map<String, Any>
var extraInfo: ((ExtraInfoPurpose) -> Map<String, Any>)? = null
) {
override fun toString(): String {
return "Config(" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object SteamcLog {
obj: Any?,
purpose: ExtraInfoPurpose?
) {
val extraInfo = purpose?.let { config.extraInfo(purpose) }
val extraInfo = purpose?.let { config.extraInfo?.invoke(purpose) }
val redactableObjectData = obj?.getRedactedDescription()
val logUrl = when (purpose == ExtraInfoPurpose.UserReport && config.detailedLogsOnUserReports) {
true -> externalLogFileTree.getExternalFile()
Expand Down

0 comments on commit 83513eb

Please sign in to comment.