-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from Q42/crash-logging
ADD Crashlytics
- Loading branch information
Showing
11 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"project_info": { | ||
"project_number": "1076113435843", | ||
"project_id": "template-android-799ab", | ||
"storage_bucket": "template-android-799ab.appspot.com" | ||
}, | ||
"client": [ | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:1076113435843:android:e2916720b9c98936dc8676", | ||
"android_client_info": { | ||
"package_name": "nl.q42.template" | ||
} | ||
}, | ||
"oauth_client": [], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyDzfsJ_ycKoyci--w_M2hHwvsjk8-zKmzA" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [] | ||
} | ||
} | ||
}, | ||
{ | ||
"client_info": { | ||
"mobilesdk_app_id": "1:1076113435843:android:72065788817f0133dc8676", | ||
"android_client_info": { | ||
"package_name": "nl.q42.template.dev" | ||
} | ||
}, | ||
"oauth_client": [], | ||
"api_key": [ | ||
{ | ||
"current_key": "AIzaSyDzfsJ_ycKoyci--w_M2hHwvsjk8-zKmzA" | ||
} | ||
], | ||
"services": { | ||
"appinvite_service": { | ||
"other_platform_oauth_client": [] | ||
} | ||
} | ||
} | ||
], | ||
"configuration_version": "1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/src/main/kotlin/nl/q42/template/logging/CrashlyticsLogger.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package nl.q42.template.logging | ||
|
||
import com.google.firebase.crashlytics.ktx.crashlytics | ||
import com.google.firebase.ktx.Firebase | ||
import io.github.aakira.napier.Antilog | ||
import io.github.aakira.napier.DebugAntilog | ||
import io.github.aakira.napier.LogLevel | ||
import nl.q42.template.BuildConfig | ||
|
||
/** A value suitable for Crashlytics | ||
* This value is used to truncate the user-defined message and the exception message | ||
* In theory, the message sent to Crashlytics could therefore be 2x this value | ||
*/ | ||
private const val MAX_CHARS_IN_LOG = 1200 | ||
|
||
/** A Crashlytics logger. The name Antilog might be an unfortunate choice by the Napier library; | ||
* this is not a stub | ||
*/ | ||
class CrashlyticsLogger : Antilog() { | ||
|
||
private val logcatLogger = DebugAntilog() | ||
|
||
override fun performLog( | ||
priority: LogLevel, | ||
tag: String?, | ||
throwable: Throwable?, | ||
message: String? | ||
) { | ||
if (message == null && throwable == null) return | ||
|
||
if (BuildConfig.DEBUG || priority > LogLevel.DEBUG) { | ||
// also send to logcat | ||
logcatLogger.log(priority, tag, throwable, message) | ||
} | ||
|
||
val limitedMessage = message?.take(MAX_CHARS_IN_LOG) ?: "(no message)" // to avoid OutOfMemoryError's | ||
|
||
if (priority < LogLevel.ERROR) { | ||
// at least one of message or throwable is not null | ||
val errorMessage = throwable?.let { | ||
" with error: ${throwable}: ${throwable.message}".take(MAX_CHARS_IN_LOG) | ||
} ?: "" | ||
Firebase.crashlytics.log(limitedMessage + errorMessage) | ||
} else { | ||
Firebase.crashlytics.log("recordException with message: $limitedMessage") | ||
Firebase.crashlytics.recordException(throwable ?: Exception(message)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters