-
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 #113 from Infomaniak/sentry-module
feat: Add Core2 & SentryLog modules
- Loading branch information
Showing
14 changed files
with
227 additions
and
11 deletions.
There are no files selected for viewing
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,34 @@ | ||
plugins { | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.kotlin.android) | ||
} | ||
|
||
android { | ||
namespace = "com.infomaniak.sentry" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
minSdk = 24 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
api(core2.sentry.android) | ||
} |
Empty file.
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
103 changes: 103 additions & 0 deletions
103
Core2/Sentry/src/main/java/com/infomaniak/sentry/SentryLog.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,103 @@ | ||
/* | ||
* Infomaniak Core - Android | ||
* Copyright (C) 2024 Infomaniak Network SA | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.sentry | ||
|
||
import android.util.Log | ||
import io.sentry.Breadcrumb | ||
import io.sentry.Sentry | ||
import io.sentry.SentryEvent | ||
import io.sentry.SentryLevel | ||
import io.sentry.protocol.Message | ||
|
||
object SentryLog { | ||
|
||
private val TAG = SentryLog::class.java.simpleName | ||
|
||
fun v(tag: String, msg: String, throwable: Throwable? = null) { | ||
val formattedMessage = formatLogMessage(tag, msg) | ||
Log.v(TAG, formattedMessage, throwable) | ||
SentryLevel.DEBUG.addBreadcrumb(formattedMessage, throwable) | ||
} | ||
|
||
fun d(tag: String, msg: String, throwable: Throwable? = null) { | ||
val formattedMessage = formatLogMessage(tag, msg) | ||
Log.d(TAG, formattedMessage, throwable) | ||
SentryLevel.DEBUG.addBreadcrumb(formattedMessage, throwable) | ||
} | ||
|
||
fun i(tag: String, msg: String, throwable: Throwable? = null) { | ||
val formattedMessage = formatLogMessage(tag, msg) | ||
Log.i(TAG, formattedMessage, throwable) | ||
SentryLevel.INFO.addBreadcrumb(formattedMessage, throwable) | ||
} | ||
|
||
fun w(tag: String, msg: String, throwable: Throwable? = null) { | ||
val formattedMessage = formatLogMessage(tag, msg) | ||
Log.w(TAG, formattedMessage, throwable) | ||
SentryLevel.WARNING.addBreadcrumb(formattedMessage, throwable) | ||
} | ||
|
||
fun e(tag: String, msg: String, throwable: Throwable? = null) { | ||
val formattedMessage = formatLogMessage(tag, msg) | ||
Log.e(TAG, formattedMessage, throwable) | ||
SentryLevel.ERROR.apply { | ||
addBreadcrumb(formattedMessage, throwable) | ||
captureEvent(tag, msg, throwable) | ||
} | ||
} | ||
|
||
fun wtf(tag: String, msg: String, throwable: Throwable? = null) { | ||
val formattedMessage = formatLogMessage(tag, msg) | ||
Log.wtf(TAG, formattedMessage, throwable) | ||
SentryLevel.FATAL.apply { | ||
addBreadcrumb(formattedMessage, throwable) | ||
captureEvent(tag, msg, throwable) | ||
} | ||
} | ||
|
||
private fun SentryLevel.captureEvent(tag: String, msg: String, throwable: Throwable?) { | ||
val sentryEvent = SentryEvent().apply { | ||
setTag("SentryLogTag", tag) | ||
level = this@captureEvent | ||
logger = TAG | ||
message = Message().apply { this.message = msg } | ||
throwable?.let(::setThrowable) | ||
} | ||
|
||
Sentry.captureEvent(sentryEvent) | ||
} | ||
|
||
private fun SentryLevel.addBreadcrumb(msg: String, throwable: Throwable?) { | ||
|
||
val throwableMsg = throwable?.message | ||
val breadCrumb = when { | ||
throwableMsg != null -> Breadcrumb.error(throwableMsg).apply { | ||
category = "exception" | ||
} | ||
else -> Breadcrumb().apply { | ||
level = this@addBreadcrumb | ||
category = TAG | ||
message = msg | ||
} | ||
} | ||
|
||
Sentry.addBreadcrumb(breadCrumb) | ||
} | ||
|
||
private fun formatLogMessage(tag: String, msg: String) = "($tag): $msg" | ||
} |
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,34 @@ | ||
plugins { | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.kotlin.android) | ||
} | ||
|
||
android { | ||
namespace = "com.infomaniak.core2" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
minSdk = 24 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
} |
Empty file.
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,5 @@ | ||
[versions] | ||
sentry-android = "7.15.0" | ||
|
||
[libraries] | ||
sentry-android = { module = "io.sentry:sentry-android", version.ref = "sentry-android" } |
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file was deleted.
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
File renamed without changes.
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