Skip to content

Commit

Permalink
이벤트 버전 추가 (#24)
Browse files Browse the repository at this point in the history
* docs site 경로 일일이 설정하도록 변경

* refactor: Log 버전 설정 방식 수정

* feat: develop에 push 되었을 때도 문서 사이트 빌드
  • Loading branch information
cometj03 authored Feb 26, 2024
1 parent a4f8fed commit 28d4ba7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 41 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/deployDocsSite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy docs

on:
push:
branches: [ master ]
branches: [ master, develop ]

jobs:
release:
Expand All @@ -12,13 +12,6 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Read versionName property
id: logger_version
uses: christian-draeger/[email protected]
with:
path: './version.properties'
properties: 'versionName'

- name: set up JDK 17
uses: actions/setup-java@v4
with:
Expand All @@ -38,4 +31,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-page
FOLDER: yls/build/dokka/html/
TARGET_FOLDER: 'docs/%{{ steps.logger_version.outputs.versionName }}/' # ex: docx/0.1/
TARGET_FOLDER: 'docs/0.x/'
33 changes: 13 additions & 20 deletions yls/src/main/kotlin/com/yourssu/logging/system/Util.kt
Original file line number Diff line number Diff line change
@@ -1,53 +1,46 @@
package com.yourssu.logging.system

fun logEvent(
fun YLS.Facade.logEvent(
eventName: String,
version: Int = YLS.VERSION,
vararg extra: Pair<String, Any>,
) {
YLS.log(version, "event" to eventName, *extra)
YLS.log("event" to eventName, *extra)
}

fun logAppInitEvent(
version: Int = YLS.VERSION,
vararg extra: Pair<String, Any>,
) {
logEvent("AppInitialEntry", version, *extra)
fun YLS.Facade.logAppInit(vararg extra: Pair<String, Any>) {
logEvent("AppInitialEntry", *extra)
}

fun logDeepLinkEntry(
fun YLS.Facade.logDeepLinkEntry(
screenName: String,
version: Int = YLS.VERSION,
vararg extra: Pair<String, Any>,
) {
logEvent("DeepLinkEntry", version, "screen" to screenName, *extra)
logEvent("DeepLinkEntry", "screen" to screenName, *extra)
}

fun logScreenEntry(
fun YLS.Facade.logScreenEntry(
screenName: String,
version: Int = YLS.VERSION,
vararg extra: Pair<String, Any>,
) {
logEvent("ScreenEntry", version, "screen" to screenName, *extra)
logEvent("ScreenEntry", "screen" to screenName, *extra)
}

fun logScreenExit(
fun YLS.Facade.logScreenExit(
screenName: String,
version: Int = YLS.VERSION,
vararg extra: Pair<String, Any>,
) {
logEvent("ScreenExit", version, "screen" to screenName, *extra)
logEvent("ScreenExit", "screen" to screenName, *extra)
flush()
}

/**
* @param componentName 클릭한 요소의 이름
* @param screenName 클릭한 시점의 화면의 이름
*/
fun logClick(
fun YLS.Facade.logClick(
componentName: String,
screenName: String,
version: Int = YLS.VERSION,
vararg extra: Pair<String, Any>,
) {
logEvent("${componentName}Clicked", version, "screen" to screenName, *extra)
logEvent("${componentName}Clicked", "screen" to screenName, *extra)
}
49 changes: 39 additions & 10 deletions yls/src/main/kotlin/com/yourssu/logging/system/YLS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ class YLS private constructor() {
}
}

companion object {
internal val VERSION = 1
companion object Facade : Logger() {
private const val DEFAULT_VERSION = 1
private var version: Int = DEFAULT_VERSION
get() {
return field.also { field = DEFAULT_VERSION }
}

private lateinit var logger: Logger
private lateinit var defaultEvent: Map<String, Any>
Expand Down Expand Up @@ -130,6 +134,28 @@ class YLS private constructor() {
this.logger = logger
}

/**
* 로깅 될 로그 데이터의 버전을 설정합니다.
* 한 번 [createLog] 메서드가 호출되면 [DEFAULT_VERSION]으로 초기화 됩니다.
*
* ```kotlin
* YLS.version(2).log(...)
* ```
*/
fun version(version: Int): YLS.Facade {
this.version = version
return this
}

fun createLog(eventMap: Map<String, Any>): YLSEventData {
return YLSEventData(
hashedId = hashedUserId,
timestamp = getTimestamp(),
version = this.version,
event = defaultEvent + eventMap,
)
}

/**
* 기본적인 로그 메서드입니다.
*
Expand All @@ -138,28 +164,31 @@ class YLS private constructor() {
* ```
* @param events 이벤트 key-value 쌍
*/
fun log(version: Int = VERSION, vararg events: Pair<String, Any>) {
fun log(vararg events: Pair<String, Any>) {
if (!::logger.isInitialized) {
throw AssertionError("Not initialized! : YLS.init()을 먼저 호출해 주세요.")
}

val eventData = YLSEventData(
hashedId = hashedUserId,
timestamp = getTimestamp(),
version = version,
event = defaultEvent + events.toMap(),
)
val eventData = createLog(events.toMap())
log(eventData)
}

fun log(eventData: YLSEventData) {
logger.enqueue(eventData)
}

/** Logger에 남아있는 로그 데이터를 모두 내보낸 후 큐를 비웁니다. */
fun flush() {
override fun flush() {
if (!::logger.isInitialized) {
throw AssertionError("Not initialized! : YLS.init()을 먼저 호출해 주세요.")
}
logger.flush()
}

override fun log(eventData: List<YLSEventData>) {
throw AssertionError("This method is not available!")
}

/**
* ASCII 33 ~ 126 사이의 문자로 `length`만큼의 길이의 랜덤 문자열을 반환합니다.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class LoggingTest {
fun ylsDebugClickLogging() {
// 버튼 클릭 이벤트
YLS.log(
version = 1,
"event" to "ButtonClicked",
"screen" to "LoginScreen",
)
Expand Down Expand Up @@ -72,7 +71,7 @@ class LoggingTest {
* queue size : 2
*/
repeat(12) {
// YLS.log("event" to "$it")
YLS.log("event" to "$it")
}

// 함수 테스트
Expand Down

0 comments on commit 28d4ba7

Please sign in to comment.