This repository has been archived by the owner on Jan 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c936571
commit 2cdeda2
Showing
58 changed files
with
352 additions
and
96 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
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
46 changes: 0 additions & 46 deletions
46
core/common/src/main/java/caios/android/fanbox/core/common/logs/category/NavigationLog.kt
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
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 @@ | ||
/build |
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,18 @@ | ||
plugins { | ||
id("pixiview.library") | ||
id("pixiview.detekt") | ||
id("pixiview.hilt") | ||
id("pixiview.firebase") | ||
alias(libs.plugins.protobuf) | ||
} | ||
|
||
android { | ||
namespace = "caios.android.fanbox.core.logs" | ||
} | ||
|
||
dependencies { | ||
implementation(project(":core:common")) | ||
implementation(project(":core:model")) | ||
|
||
implementation(libs.puree) | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
2 changes: 1 addition & 1 deletion
2
.../fanbox/core/common/logs/CommonPayload.kt → ...android/fanbox/core/logs/CommonPayload.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package caios.android.fanbox.core.common.logs | ||
package caios.android.fanbox.core.logs | ||
|
||
import org.json.JSONObject | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
.../core/common/logs/category/LogCategory.kt → .../fanbox/core/logs/category/LogCategory.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
25 changes: 25 additions & 0 deletions
25
core/logs/src/main/java/caios/android/fanbox/core/logs/category/NavigationLog.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,25 @@ | ||
package caios.android.fanbox.core.logs.category | ||
|
||
import kotlinx.serialization.json.JsonObject | ||
import kotlinx.serialization.json.buildJsonObject | ||
import kotlinx.serialization.json.put | ||
|
||
// This class is automatically generated by generate-log-classes. | ||
sealed class NavigationLog : LogCategory { | ||
class Navigate internal constructor( | ||
private val screenRoute: String | ||
) : NavigationLog() { | ||
override val properties: JsonObject = buildJsonObject { | ||
put("event_category", "navigation") | ||
put("event_name", "navigate") | ||
put("screen_route", screenRoute) | ||
} | ||
} | ||
|
||
companion object { | ||
// 画面遷移したときのログ | ||
fun navigate( | ||
screenRoute: String | ||
) = Navigate(screenRoute) | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
core/logs/src/main/java/caios/android/fanbox/core/logs/puree/PixiViewLogFilter.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,34 @@ | ||
package caios.android.fanbox.core.logs.puree | ||
|
||
import android.os.Build | ||
import caios.android.fanbox.core.common.PixiViewConfig | ||
import caios.android.fanbox.core.logs.CommonPayload | ||
import caios.android.fanbox.core.model.BuildConfig | ||
import caios.android.fanbox.core.model.UserData | ||
import com.cookpad.puree.kotlin.PureeFilter | ||
import org.json.JSONObject | ||
import java.time.ZoneId | ||
|
||
class PixiViewLogFilter( | ||
private val pixiViewConfig: PixiViewConfig, | ||
private val userData: UserData, | ||
private val userAgent: String, | ||
) : PureeFilter { | ||
|
||
override fun applyFilter(log: JSONObject): JSONObject { | ||
val commonPayload = CommonPayload( | ||
pixiviewId = userData.pixiViewId, | ||
userAgent = userAgent, | ||
isPlus = userData.isPlusMode, | ||
isDeveloper = userData.isDeveloperMode, | ||
isTester = userData.isTestUser, | ||
osVersion = Build.VERSION.SDK_INT.toString(), | ||
applicationVariant = BuildConfig.BUILD_TYPE, | ||
applicationVersionCode = pixiViewConfig.versionCode.toLong(), | ||
applicationVersionName = pixiViewConfig.versionName, | ||
timeZone = ZoneId.systemDefault().id | ||
) | ||
|
||
return commonPayload.applyToJsonObject(log) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
core/logs/src/main/java/caios/android/fanbox/core/logs/puree/PixiViewLogOutput.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,16 @@ | ||
package caios.android.fanbox.core.logs.puree | ||
|
||
import com.cookpad.puree.kotlin.output.PureeBufferedOutput | ||
import org.json.JSONObject | ||
import timber.log.Timber | ||
import java.time.Duration | ||
|
||
class PixiViewLogOutput: PureeBufferedOutput("pixiview_activity_log") { | ||
|
||
override val flushInterval: Duration = Duration.ofSeconds(15) | ||
|
||
override fun emit(logs: List<JSONObject>, onSuccess: () -> Unit, onFailed: (Throwable) -> Unit) { | ||
Timber.d("PureeLog: $logs") | ||
onSuccess.invoke() | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
core/logs/src/main/java/caios/android/fanbox/core/logs/puree/PixiViewLogger.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,38 @@ | ||
package caios.android.fanbox.core.logs.puree | ||
|
||
import caios.android.fanbox.core.logs.category.LogCategory | ||
import com.cookpad.puree.kotlin.PureeLog | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.JsonObject | ||
import kotlinx.serialization.json.buildJsonObject | ||
import kotlinx.serialization.json.put | ||
|
||
internal object PixiViewActivityLogger { | ||
fun post(logCategory: LogCategory) = logCategory.run { | ||
PixiViewActivityLog(properties).also { | ||
Puree.send(it) | ||
} | ||
} | ||
} | ||
|
||
@Serializable | ||
data class PixiViewActivityLog internal constructor( | ||
private var properties: JsonObject, | ||
) : PureeLog { | ||
|
||
init { | ||
properties = buildJsonObject { | ||
for (key in properties.keys) { | ||
put(key, properties[key]!!) | ||
} | ||
|
||
put("table_name", tableName) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val tableName: String = "android_pixiview_activity" | ||
} | ||
} | ||
|
||
fun LogCategory.send() = PixiViewActivityLogger.post(this) |
39 changes: 39 additions & 0 deletions
39
core/logs/src/main/java/caios/android/fanbox/core/logs/puree/Puree.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,39 @@ | ||
package caios.android.fanbox.core.logs.puree | ||
|
||
import com.cookpad.puree.kotlin.PureeLog | ||
import com.cookpad.puree.kotlin.PureeLogger | ||
|
||
object Puree { | ||
private var pureeLoggerInstance: LoggerWrapper? = null | ||
private val pureeLogger: LoggerWrapper | ||
get() = checkNotNull(pureeLoggerInstance) { "PureeLogger instance is not set" } | ||
|
||
fun setPureeLogger(pureeLogger: LoggerWrapper) { | ||
pureeLoggerInstance = pureeLogger | ||
} | ||
|
||
@JvmStatic | ||
fun send(log: PureeLog) { | ||
pureeLogger.postLog(log) | ||
} | ||
|
||
@JvmStatic | ||
fun flush() { | ||
pureeLogger.flush() | ||
} | ||
|
||
interface LoggerWrapper { | ||
fun postLog(log: PureeLog) | ||
fun flush() | ||
} | ||
} | ||
|
||
class PureeLoggerWrapper(private val logger: PureeLogger) : Puree.LoggerWrapper { | ||
override fun postLog(log: PureeLog) { | ||
logger.postLog(log) | ||
} | ||
|
||
override fun flush() { | ||
logger.flush() | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
core/logs/src/main/java/caios/android/fanbox/core/logs/puree/PureeConfigurator.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,55 @@ | ||
package caios.android.fanbox.core.logs.puree | ||
|
||
import android.content.Context | ||
import androidx.lifecycle.ProcessLifecycleOwner | ||
import caios.android.fanbox.core.common.PixiViewConfig | ||
import caios.android.fanbox.core.model.UserData | ||
import com.cookpad.puree.kotlin.PureeLogger | ||
import com.cookpad.puree.kotlin.store.DbPureeLogStore | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.json.Json | ||
|
||
object PureeConfigurator { | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
private val formatter = Json { | ||
isLenient = true | ||
prettyPrint = true | ||
ignoreUnknownKeys = true | ||
coerceInputValues = true | ||
encodeDefaults = true | ||
explicitNulls = false | ||
} | ||
|
||
fun configure( | ||
context: Context, | ||
pixiViewConfig: PixiViewConfig, | ||
userData: UserData, | ||
) { | ||
val logger = buildPureeLogger(context, pixiViewConfig, userData) | ||
|
||
Puree.setPureeLogger(PureeLoggerWrapper(logger)) | ||
Puree.flush() | ||
} | ||
|
||
private fun buildPureeLogger( | ||
context: Context, | ||
pixiViewConfig: PixiViewConfig, | ||
userData: UserData, | ||
): PureeLogger { | ||
return PureeLogger.Builder( | ||
lifecycle = ProcessLifecycleOwner.get().lifecycle, | ||
logSerializer = PureeKotlinSerializer(formatter), | ||
logStore = DbPureeLogStore(context, "puree-kotlin.db") | ||
) | ||
.filter( | ||
PixiViewLogFilter(pixiViewConfig, userData, userAgent = "PixiView"), | ||
PixiViewActivityLog::class.java | ||
) | ||
.output( | ||
PixiViewLogOutput(), | ||
PixiViewActivityLog::class.java | ||
) | ||
.build() | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
core/logs/src/main/java/caios/android/fanbox/core/logs/puree/PureeKotlinSerializer.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,15 @@ | ||
package caios.android.fanbox.core.logs.puree | ||
|
||
import com.cookpad.puree.kotlin.PureeLog | ||
import com.cookpad.puree.kotlin.serializer.PureeLogSerializer | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import org.json.JSONObject | ||
|
||
class PureeKotlinSerializer( | ||
private val formatter: Json, | ||
) : PureeLogSerializer { | ||
override fun serialize(log: PureeLog): JSONObject { | ||
return JSONObject(formatter.encodeToString(log as PixiViewActivityLog)) | ||
} | ||
} |
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
Oops, something went wrong.