Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#114] Config.extraInfo now optional #119

Merged
merged 2 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ The format is based on the Steamclock [Release Management Guide](https://github.
## Unreleased
- Allow more than one log to be attached to a Sentry report (#115)
- Fixed issue with log auto rotation (#115)
- Config.extraInfo now optional (#114)

---

## Jitpack v2.3 : Jun 19, 2023
- Added UserReports (#110)
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 @@ -15,20 +15,7 @@ class App : Application() {
fileWritePath = externalCacheDir,
autoRotateConfig = AutoRotateConfig(10L), // Short rotate so we can more easily test
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 @@ -21,6 +21,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 @@ -46,6 +60,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 attachLogFiles = purpose == ExtraInfoPurpose.UserReport && config.detailedLogsOnUserReports

Expand Down