Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ import com.google.genai.types.GenerateContentConfig
import com.google.genai.types.Part
import com.google.genai.types.Schema
import com.google.genai.types.ThinkingConfig
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.stereotype.Component
import tools.jackson.core.JacksonException
import tools.jackson.core.type.TypeReference
import tools.jackson.databind.ObjectMapper
import java.util.concurrent.atomic.AtomicInteger

private val logger = KotlinLogging.logger {}

/** 애플리케이션 전체에서 generateContent를 실제로 몇 번 호출했는지 세는 카운터 — 로그의 호출 순번(callNo)으로 쓴다. */
private val callCounter = AtomicInteger(0)

/** 일시적 HTTP 실패(타임아웃·5xx·429) — 호출부가 작업 전체를 실패시키고 큐 재시도에 맡긴다. */
class GeminiRequestException(
Expand Down Expand Up @@ -68,14 +75,31 @@ class GeminiClient(
.thinkingConfig(ThinkingConfig.builder().thinkingLevel(geminiProperties.thinkingLevel).build())
.build()

val callNo = callCounter.incrementAndGet()
logger.info {
"[Gemini] call #$callNo 요청 — model=${geminiProperties.model}\n" +
"--- systemInstruction ---\n$systemInstruction\n" +
"--- userContent ---\n$userContent"
}
Comment on lines +79 to +83

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Kotlin의 다중 행 문자열(Raw String) 사용을 고려해 보세요.

현재 여러 줄의 로그 메시지를 작성할 때 + 연산자와 \n을 사용해 문자열을 결합하고 있습니다. Kotlin에서 제공하는 다중 행 문자열("""...""".trimIndent())을 활용하면 가독성을 높이고 더 깔끔하게 코드를 작성할 수 있습니다.

  • infrastructure/client/src/main/kotlin/kr/dongchimi/client/ai/GeminiClient.kt#L79-L83: 요청 로그 문자열을 """...""".trimIndent() 형태의 다중 행 문자열로 변경합니다.
  • infrastructure/client/src/main/kotlin/kr/dongchimi/client/ai/GeminiClient.kt#L93-L96: 응답 로그 문자열을 """...""".trimIndent() 형태의 다중 행 문자열로 변경합니다.
💡 다중 행 문자열 적용 예시

요청 로그:

logger.info {
    """
    [Gemini] call #$callNo 요청 — model=${geminiProperties.model}
    --- systemInstruction ---
    $systemInstruction
    --- userContent ---
    $userContent
    """.trimIndent()
}

응답 로그:

logger.info {
    """
    [Gemini] call #$callNo 응답 — ${System.currentTimeMillis() - startedAt}ms
    --- output ---
    $text
    """.trimIndent()
}
📍 Affects 1 file
  • infrastructure/client/src/main/kotlin/kr/dongchimi/client/ai/GeminiClient.kt#L79-L83 (this comment)
  • infrastructure/client/src/main/kotlin/kr/dongchimi/client/ai/GeminiClient.kt#L93-L96
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@infrastructure/client/src/main/kotlin/kr/dongchimi/client/ai/GeminiClient.kt`
around lines 79 - 83, Update the request log in GeminiClient.kt lines 79-83 to
use a Kotlin raw multiline string with trimIndent() instead of + concatenation
and explicit \n characters; likewise update the response log in GeminiClient.kt
lines 93-96 to the same format, preserving all existing interpolated values and
log content.


val startedAt = System.currentTimeMillis()
try {
genAiClient.models
.generateContent(geminiProperties.model, userContent, config)
.text()
?: throw GeminiResponseFormatException("Gemini 응답에 text가 없음")
val text =
genAiClient.models
.generateContent(geminiProperties.model, userContent, config)
.text()
?: throw GeminiResponseFormatException("Gemini 응답에 text가 없음")

logger.info {
"[Gemini] call #$callNo 응답 — ${System.currentTimeMillis() - startedAt}ms\n" +
"--- output ---\n$text"
}
text
} catch (e: ApiException) {
logger.warn(e) { "[Gemini] call #$callNo 실패(ApiException) — ${System.currentTimeMillis() - startedAt}ms" }
throw GeminiRequestException(e)
} catch (e: GenAiIOException) {
logger.warn(e) { "[Gemini] call #$callNo 실패(GenAiIOException) — ${System.currentTimeMillis() - startedAt}ms" }
throw GeminiRequestException(e)
}
}
Expand Down
Loading