Skip to content

Commit

Permalink
logEvent() 수정 및 DTO version 프로퍼티 추가 (#26)
Browse files Browse the repository at this point in the history
* chore: DTO에 version 추가

* chore: logEvent "name"으로 변경

* chore: Timestamp 수정

* chore: 자잘한 수정

* version 0.1.1

* chore: timestamp desugaring 삭제

* 테스트 url 삭제
  • Loading branch information
cometj03 authored Mar 5, 2024
1 parent 310fa01 commit 2505cce
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
versionName=0.1.0
versionName=0.1.1
3 changes: 0 additions & 3 deletions yls/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ android {
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
isCoreLibraryDesugaringEnabled = true
}
kotlinOptions {
jvmTarget = "17"
Expand Down Expand Up @@ -72,8 +71,6 @@ dependencies {
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
}

tasks.withType<DokkaTask>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class WorkerTest {
val eventData = YLSEventData(
hashedId = "aaaabbbbccccddddaaaabbbbccccdddd",
timestamp = "2023-12-04T10:30:00Z",
version = 1,
event = mapOf("platform" to "android", "event" to "AppInitialEntry"),
)

Expand All @@ -49,7 +50,7 @@ class WorkerTest {
val worker = TestListenableWorkerBuilder<RemoteLoggingWorker>(
context = context,
inputData = workDataOf(
RemoteLoggingWorker.KEY_LOGGING_URL to "http://52.78.169.59:8085/",
RemoteLoggingWorker.KEY_LOGGING_URL to "your api url",
RemoteLoggingWorker.KEY_LOGGING_SINGLE_DATA to json,
),
).build()
Expand All @@ -66,6 +67,7 @@ class WorkerTest {
YLSEventData(
hashedId = "aaaabbbbccccddddaaaabbbbccccdddd",
timestamp = "2023-12-04T10:30:00Z",
version = 1,
event = mapOf("platform" to "android", "event" to "AppInitialEntry"),
),
)
Expand Down
2 changes: 1 addition & 1 deletion yls/src/main/kotlin/com/yourssu/logging/system/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fun YLS.Facade.logEvent(
eventName: String,
vararg extra: Pair<String, Any>,
) {
YLS.log("event" to eventName, *extra)
YLS.log("name" to eventName, *extra)
}

fun YLS.Facade.logAppInit(vararg extra: Pair<String, Any>) {
Expand Down
18 changes: 16 additions & 2 deletions yls/src/main/kotlin/com/yourssu/logging/system/YLS.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.yourssu.logging.system

import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.util.Log
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.workDataOf
import com.google.gson.Gson
import com.yourssu.logging.system.remote.RemoteLoggingWorker
import java.security.MessageDigest
import java.text.SimpleDateFormat
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.util.Date
import java.util.TimeZone

/**
* Yourssu Logging System, inspired by [Timber](https://github.com/JakeWharton/timber)
Expand Down Expand Up @@ -222,11 +227,20 @@ class YLS private constructor() {
/**
* 현재 시각을 ISO 8601 포맷의 문자열을 반환합니다.
*
* "yyyy-MM-dd'T'HH:mm:ss'Z'"
*
* @return ISO 8601 format string of current
*/
@SuppressLint("SimpleDateFormat")
fun getTimestamp(): String {
return OffsetDateTime.now(ZoneOffset.UTC)
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"))
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
OffsetDateTime.now(ZoneOffset.UTC)
.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)
} else {
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").apply {
timeZone = TimeZone.getTimeZone("UTC")
}.format(Date())
}
}

/** SHA-256 알고리즘으로 `origin`을 암호화 한 문자열을 반환합니다. */
Expand Down
3 changes: 3 additions & 0 deletions yls/src/main/kotlin/com/yourssu/logging/system/remote/Dto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fun YLSEventData.toLoggingRequest(): LoggingRequest {
return LoggingRequest(
hashedId = hashedId,
timestamp = timestamp,
version = version,
event = event,
)
}
Expand All @@ -16,6 +17,8 @@ data class LoggingRequest(
val hashedId: String,
@SerializedName("timestamp")
val timestamp: String,
@SerializedName("version")
val version: Int,
@SerializedName("event")
val event: Map<String, Any>,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.coroutines.withContext
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

internal class RemoteLoggingWorker(
class RemoteLoggingWorker(
appContext: Context,
params: WorkerParameters,
) : CoroutineWorker(appContext, params) {
Expand Down
7 changes: 3 additions & 4 deletions yls/src/test/kotlin/com/yourssu/logging/system/ApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class ApiTest {
.build()

retrofit = Retrofit.Builder()
.baseUrl("http://52.78.169.59:8085/") // 실제 Api 테스트
// .baseUrl(server.url("/")) // 가짜 Response 테스트
.baseUrl(server.url("/")) // 가짜 Response 테스트
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
Expand All @@ -46,7 +45,7 @@ class ApiTest {

val eventData = YLSEventData(
hashedId = "testtest",
timestamp = "2023-12-04T10:30:00Z",
timestamp = YLS.getTimestamp(),
version = 1,
event = mapOf("event" to "test"),
)
Expand All @@ -63,7 +62,7 @@ class ApiTest {
val eventDataList = listOf(
YLSEventData(
hashedId = "testtest",
timestamp = "2023-12-04T10:30:00Z",
timestamp = YLS.getTimestamp(),
version = 1,
event = mapOf("event" to "test"),
),
Expand Down

0 comments on commit 2505cce

Please sign in to comment.