Skip to content

Commit

Permalink
[FEAT/#66] Log를 Timber로 변환
Browse files Browse the repository at this point in the history
  • Loading branch information
seongh06 committed Sep 25, 2024
1 parent 8dc4ec6 commit 0a2dac7
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
import com.kakao.sdk.user.UserApiClient
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import umc.everyones.lck.R
import umc.everyones.lck.databinding.FragmentLoginBinding
import umc.everyones.lck.domain.model.response.login.CommonLoginResponseModel
Expand Down Expand Up @@ -43,15 +44,15 @@ class LoginFragment : BaseFragment<FragmentLoginBinding>(R.layout.fragment_login
private fun loginWithKakaoTalk() {
UserApiClient.instance.loginWithKakaoTalk(requireContext()) { token, error ->
if (error != null) {
Log.e(TAG, "카카오톡으로 로그인 실패", error)
Timber.e("카카오톡으로 로그인 실패", error)
if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
// 사용자가 로그인 과정을 취소한 경우
return@loginWithKakaoTalk
}
// 카카오 계정으로 로그인 시도
loginWithKakaoAccount()
} else if (token != null) {
Log.i(TAG, "카카오톡으로 로그인 성공 ${token.accessToken}")
Timber.i("카카오톡으로 로그인 성공 ${token.accessToken}")
handleLoginSuccess()
}
}
Expand All @@ -60,9 +61,9 @@ class LoginFragment : BaseFragment<FragmentLoginBinding>(R.layout.fragment_login
private fun loginWithKakaoAccount() {
UserApiClient.instance.loginWithKakaoAccount(requireContext()) {token, error ->
if (error != null) {
Log.e(TAG, "카카오 계정으로 로그인 실패", error)
Timber.e("카카오 계정으로 로그인 실패", error)
} else if (token != null) {
Log.i(TAG, "카카오 계정으로 로그인 성공 ${token.accessToken}")
Timber.i("카카오 계정으로 로그인 성공 ${token.accessToken}")
handleLoginSuccess()
}
}
Expand All @@ -72,7 +73,7 @@ class LoginFragment : BaseFragment<FragmentLoginBinding>(R.layout.fragment_login
UserApiClient.instance.me { user, error ->
user?.let {
val kakaoUserId = it.id.toString()
Log.d(TAG, "로그인 결과: $kakaoUserId") // 결과 로깅
Timber.d("로그인 결과: $kakaoUserId") // 결과 로깅

// ViewModel에 사용자 ID 설정
viewModel.setKakaoUserId(kakaoUserId)
Expand All @@ -86,7 +87,7 @@ class LoginFragment : BaseFragment<FragmentLoginBinding>(R.layout.fragment_login
handleLoginResult(userInfo) // 로그인 결과에 따라 화면 전환
}
} ?: run {
Log.e(TAG, "사용자 정보가 null입니다.")
Timber.e("사용자 정보가 null입니다.")
navigateToSignupNicknameScreen() // 회원가입 화면으로 이동
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.navigation.fragment.findNavController
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import timber.log.Timber
import umc.everyones.lck.R
import umc.everyones.lck.databinding.DialogMyteamConfirmBinding
import umc.everyones.lck.databinding.DialogProfileConfirmBinding
Expand All @@ -42,14 +43,14 @@ class SignupProfileFragment : BaseFragment<FragmentSignupProfileBinding>(R.layou

override fun initObserver() {
viewModel.profileUri.observe(viewLifecycleOwner) { uri ->
Log.d("SignupProfileFragment", "Observed Profile Image URI: $uri")
Timber.d("Observed Profile Image URI: $uri")
uri?.let {
binding.ivSignupProfilePicture.setImageURI(it)
}
}

viewModel.nickName.observe(viewLifecycleOwner) { nickname ->
Log.d("SignupProfileFragment", "닉네임: $nickname")
Timber.d("닉네임: $nickname")
}
}
override fun initView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import timber.log.Timber
import umc.everyones.lck.R
import umc.everyones.lck.data.SignupUserData
import umc.everyones.lck.data.dto.request.login.SignupAuthUserRequestDto
Expand Down Expand Up @@ -85,7 +86,7 @@ class SignupViewModel @Inject constructor(
val result = try {
repository.nickname(NicknameAuthUserRequestModel(nickName))
} catch (e: Exception) {
Log.e("SignupViewModel", "Error checking nickname availability: ${e.message}")
Timber.e("Error checking nickname availability: ${e.message}")
Result.failure(e) // 예외 발생 시
}

Expand All @@ -111,7 +112,7 @@ class SignupViewModel @Inject constructor(
val requestModel = CommonLoginRequestModel(kakaoUserId)

repository.login(requestModel).onSuccess { response ->
Log.d("loginWithKakao", response.toString())
Timber.d(response.toString())
spf.edit().apply {
putString("jwt", response.accessToken)
putString("refreshToken", response.refreshToken)
Expand All @@ -121,8 +122,8 @@ class SignupViewModel @Inject constructor(
}
_loginResult.value = response // 로그인 결과를 LiveData에 저장
}.onFailure { error ->
Log.d("loginWithKakao Error", error.message.toString())
Log.d("LoginWithKakao", "$requestModel")
Timber.d(error.message.toString())
Timber.d("$requestModel")
_loginResult.value = null // 실패 시 null 설정
}
}
Expand All @@ -132,7 +133,7 @@ class SignupViewModel @Inject constructor(
viewModelScope.launch {
val signupRequest = prepareSignupRequest()

Log.d("SignupViewModel", "Sending API request with data: ${signupRequest.signupUserData}")
Timber.d("Sending API request with data: ${signupRequest.signupUserData}")

val gson = Gson()
val signupUserDataJson = gson.toJson(signupRequest.signupUserData)
Expand All @@ -150,7 +151,7 @@ class SignupViewModel @Inject constructor(
apply()
}
}.onFailure {
Log.e("SignupViewModel", "API call failed: ${it.message}")
Timber.e("API call failed: ${it.message}")
}
}
}
Expand Down Expand Up @@ -178,7 +179,7 @@ class SignupViewModel @Inject constructor(
"profileImage", "profile_image.png", requestBody
)
} catch (e: Exception) {
Log.e("SignupViewModel", "Error creating MultipartBody.Part for profile image: ${e.message}")
Timber.e("Error creating MultipartBody.Part for profile image: ${e.message}")
val emptyImageRequestBody = ByteArray(0).toRequestBody("image/png".toMediaTypeOrNull()) // 빈 이미지 요청
MultipartBody.Part.createFormData(
"profileImage", "profile_image.png", emptyImageRequestBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.navigation.fragment.findNavController
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
import timber.log.Timber
import umc.everyones.lck.R
import umc.everyones.lck.databinding.DialogMyteamConfirmBinding
import umc.everyones.lck.databinding.FragmentMypageMyteamBinding
Expand All @@ -34,7 +35,7 @@ class MyPageMyteamFragment : BaseFragment<FragmentMypageMyteamBinding>(R.layout.
override fun initObserver() {
myPageViewModel.inquiryProfile()
myPageViewModel.teamId.observe(viewLifecycleOwner) { teamId ->
Log.d("MyPageMyteamFragment", "Observed teamId: $teamId") // teamId 로그 추가
Timber.d("Observed teamId: $teamId") // teamId 로그 추가

// 기존 팀 로고와 이름을 반영 (처음 로딩 시)
val teamLogoResId = TeamData.mypageMyteam[teamId] ?: R.drawable.ic_mypage_myteam_empty // 기본 로고 설정
Expand Down Expand Up @@ -71,7 +72,7 @@ class MyPageMyteamFragment : BaseFragment<FragmentMypageMyteamBinding>(R.layout.

// 팀 ID 관찰 (한 번만 등록)
myPageViewModel.teamId.observe(viewLifecycleOwner) { teamId ->
Log.d("MyPageMyteamFragment", "Observed teamId: $teamId") // teamId 로그 추가
Timber.d("Observed teamId: $teamId") // teamId 로그 추가

// 기존 팀 로고를 반영 (처음 로딩 시)
val teamLogoResId = TeamData.mypageMyteam[teamId]
Expand All @@ -91,10 +92,10 @@ class MyPageMyteamFragment : BaseFragment<FragmentMypageMyteamBinding>(R.layout.
// 프로필 조회 (팀 업데이트 후)
myPageViewModel.inquiryProfile()

Log.d("MyPageMyteamFragment", "Navigated to next fragment with team ID: $teamIdToUpdate")
Timber.d( "Navigated to next fragment with team ID: $teamIdToUpdate")

} catch (e: Exception) {
Log.e("MyPageMyteamFragment", "Error navigating", e)
Timber.e("Error navigating", e)
}
}
}
Expand Down Expand Up @@ -131,14 +132,14 @@ class MyPageMyteamFragment : BaseFragment<FragmentMypageMyteamBinding>(R.layout.
updateTeamSelectionUI()

// 로그 찍기: 현재 선택된 팀 ID와 보낼 팀 ID 확인
Log.d("MyPageMyteamFragment", "보내고자 하는 팀 ID: $teamId, 현재 선택된 팀 ID: $selectedTeamId")
Timber.d("보내고자 하는 팀 ID: $teamId, 현재 선택된 팀 ID: $selectedTeamId")

// 팀 이름과 ID를 전달
val teamName = TeamData.teamNames[selectedTeamId]
onTeamSelected(teamName, selectedTeamId!!)
}
} else {
Log.e("MyPageMyteamFragment", "ImageView with ID $imageViewId not found.")
Timber.e("ImageView with ID $imageViewId not found.")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.widget.Toast
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber
import umc.everyones.lck.R
import umc.everyones.lck.databinding.FragmentMypageProfileWithdrawBinding
import umc.everyones.lck.presentation.base.BaseFragment
Expand All @@ -23,10 +24,10 @@ class MyPageProfileWithdrawFragment : BaseFragment<FragmentMypageProfileWithdraw
override fun initObserver() {
myPageViewModel.withdrawResult.observe(viewLifecycleOwner) { success ->
if (success) {
Log.d("MyActivity", "회원 탈퇴 후 로그인 화면으로 이동")
Timber.d("회원 탈퇴 후 로그인 화면으로 이동")
navigateToLoginScreen()
} else {
Log.e("MyActivity", "회원 탈퇴 실패, 오류 처리 필요")
Timber.e("회원 탈퇴 실패, 오류 처리 필요")
Toast.makeText(requireContext(), "계정 탈퇴에 실패했습니다. 다시 시도해주세요.", Toast.LENGTH_SHORT).show()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import kotlinx.coroutines.launch
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.toRequestBody
import timber.log.Timber
import umc.everyones.lck.R
import umc.everyones.lck.data.UpdateProfileRequest
import umc.everyones.lck.data.dto.BaseResponse
Expand Down Expand Up @@ -77,9 +78,9 @@ class MyPageViewModel @Inject constructor(
_profileData.value = response
_nickName.value = response.nickname // 닉네임을 LiveData에 저장
_teamId.value = response.teamId
Log.d("inquiryProfile", response.toString())
Timber.d(response.toString())
}.onFailure {
Log.d("inquiryProfile", it.stackTraceToString())
Timber.d(it.stackTraceToString())
}
}
}
Expand All @@ -88,11 +89,11 @@ class MyPageViewModel @Inject constructor(
viewModelScope.launch {
repository.withdraw().onSuccess {response ->
_withdrawResult.value = true
Log.d("withdraw", "회원 탈퇴 성공: $response")
Timber.d("회원 탈퇴 성공: $response")
spf.edit().putBoolean("isLoggedIn", false).apply()
clearAppCache()
}.onFailure { error ->
Log.e("withdraw", "회원 탈퇴 실패: ${error.message}")
Timber.e("회원 탈퇴 실패: ${error.message}")
_withdrawResult.value = false
}
}
Expand All @@ -104,16 +105,16 @@ class MyPageViewModel @Inject constructor(
viewModelScope.launch {
repository.logout(refreshToken).onSuccess { response ->
_logoutResult.value = true
Log.d("logout", "로그아웃 성공: $response")
Timber.d("로그아웃 성공: $response")
spf.edit().putBoolean("isLoggedIn", false).apply()
clearAppCache()
}.onFailure { error ->
_logoutResult.value = false
Log.e("logout", "로그아웃 실패: ${error.message}")
Timber.e("로그아웃 실패: ${error.message}")
}
}
} else {
Log.e("logout", "refreshToken이 없습니다.")
Timber.e("refreshToken이 없습니다.")
_logoutResult.value = false
}
}
Expand Down Expand Up @@ -150,11 +151,11 @@ class MyPageViewModel @Inject constructor(
runCatching {
repository.updateProfiles(profileImagePart, requestBody)
}.onSuccess { response ->
Log.d("MyPageViewModel", "Response: ${Gson().toJson(response)}") // 응답 전체 로그
Timber.d("Response: ${Gson().toJson(response)}") // 응답 전체 로그

// JSON 응답을 BaseResponse로 파싱
val jsonResponse = Gson().toJson(response)
Log.d("MyPageViewModel", "JSON Response: $jsonResponse") // JSON 문자열 로그
Timber.d("JSON Response: $jsonResponse") // JSON 문자열 로그

// 제네릭 타입을 이용한 BaseResponse 파싱
val type = object : TypeToken<BaseResponse<UpdateProfilesResponseDto>>() {}.type
Expand All @@ -169,12 +170,12 @@ class MyPageViewModel @Inject constructor(
updatedNickname = updatedProfile.updatedNickname
)
} else {
Log.e("MyPageViewModel", "Error in base response: ${baseResponse.message}")
Timber.e("Error in base response: ${baseResponse.message}")
_updateProfileResult.value = null
}
}.onFailure { error ->
_updateProfileResult.value = null
Log.e("MyPageViewModel", "Error updating profile: ${error.message}")
Timber.e("Error updating profile: ${error.message}")
}
}
}
Expand Down

0 comments on commit 0a2dac7

Please sign in to comment.