From 0a2dac7a1fdad867cb5bac5b18669072da7c6a61 Mon Sep 17 00:00:00 2001 From: seongh06 Date: Wed, 25 Sep 2024 17:54:00 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT/#66]=20Log=EB=A5=BC=20Timber=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lck/presentation/login/LoginFragment.kt | 13 ++++++----- .../login/SignupProfileFragment.kt | 5 ++-- .../lck/presentation/login/SignupViewModel.kt | 15 ++++++------ .../mypage/MyPageMyteamFragment.kt | 13 ++++++----- .../mypage/MyPageProfileWithdrawFragment.kt | 5 ++-- .../presentation/mypage/MyPageViewModel.kt | 23 ++++++++++--------- 6 files changed, 40 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/umc/everyones/lck/presentation/login/LoginFragment.kt b/app/src/main/java/umc/everyones/lck/presentation/login/LoginFragment.kt index 5a61fca5..1944331a 100644 --- a/app/src/main/java/umc/everyones/lck/presentation/login/LoginFragment.kt +++ b/app/src/main/java/umc/everyones/lck/presentation/login/LoginFragment.kt @@ -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 @@ -43,7 +44,7 @@ class LoginFragment : BaseFragment(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 @@ -51,7 +52,7 @@ class LoginFragment : BaseFragment(R.layout.fragment_login // 카카오 계정으로 로그인 시도 loginWithKakaoAccount() } else if (token != null) { - Log.i(TAG, "카카오톡으로 로그인 성공 ${token.accessToken}") + Timber.i("카카오톡으로 로그인 성공 ${token.accessToken}") handleLoginSuccess() } } @@ -60,9 +61,9 @@ class LoginFragment : BaseFragment(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() } } @@ -72,7 +73,7 @@ class LoginFragment : BaseFragment(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) @@ -86,7 +87,7 @@ class LoginFragment : BaseFragment(R.layout.fragment_login handleLoginResult(userInfo) // 로그인 결과에 따라 화면 전환 } } ?: run { - Log.e(TAG, "사용자 정보가 null입니다.") + Timber.e("사용자 정보가 null입니다.") navigateToSignupNicknameScreen() // 회원가입 화면으로 이동 } } diff --git a/app/src/main/java/umc/everyones/lck/presentation/login/SignupProfileFragment.kt b/app/src/main/java/umc/everyones/lck/presentation/login/SignupProfileFragment.kt index 34d07ac1..e5d7d4d7 100644 --- a/app/src/main/java/umc/everyones/lck/presentation/login/SignupProfileFragment.kt +++ b/app/src/main/java/umc/everyones/lck/presentation/login/SignupProfileFragment.kt @@ -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 @@ -42,14 +43,14 @@ class SignupProfileFragment : BaseFragment(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() { diff --git a/app/src/main/java/umc/everyones/lck/presentation/login/SignupViewModel.kt b/app/src/main/java/umc/everyones/lck/presentation/login/SignupViewModel.kt index 0740a268..77a0a74c 100644 --- a/app/src/main/java/umc/everyones/lck/presentation/login/SignupViewModel.kt +++ b/app/src/main/java/umc/everyones/lck/presentation/login/SignupViewModel.kt @@ -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 @@ -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) // 예외 발생 시 } @@ -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) @@ -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 설정 } } @@ -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) @@ -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}") } } } @@ -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 diff --git a/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageMyteamFragment.kt b/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageMyteamFragment.kt index dda84010..8d8e3b8e 100644 --- a/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageMyteamFragment.kt +++ b/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageMyteamFragment.kt @@ -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 @@ -34,7 +35,7 @@ class MyPageMyteamFragment : BaseFragment(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 // 기본 로고 설정 @@ -71,7 +72,7 @@ class MyPageMyteamFragment : BaseFragment(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] @@ -91,10 +92,10 @@ class MyPageMyteamFragment : BaseFragment(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) } } } @@ -131,14 +132,14 @@ class MyPageMyteamFragment : BaseFragment(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.") } } } diff --git a/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageProfileWithdrawFragment.kt b/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageProfileWithdrawFragment.kt index 135c6226..50ebf5a9 100644 --- a/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageProfileWithdrawFragment.kt +++ b/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageProfileWithdrawFragment.kt @@ -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 @@ -23,10 +24,10 @@ class MyPageProfileWithdrawFragment : BaseFragment if (success) { - Log.d("MyActivity", "회원 탈퇴 후 로그인 화면으로 이동") + Timber.d("회원 탈퇴 후 로그인 화면으로 이동") navigateToLoginScreen() } else { - Log.e("MyActivity", "회원 탈퇴 실패, 오류 처리 필요") + Timber.e("회원 탈퇴 실패, 오류 처리 필요") Toast.makeText(requireContext(), "계정 탈퇴에 실패했습니다. 다시 시도해주세요.", Toast.LENGTH_SHORT).show() } } diff --git a/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageViewModel.kt b/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageViewModel.kt index 60933bfe..f37f91b4 100644 --- a/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageViewModel.kt +++ b/app/src/main/java/umc/everyones/lck/presentation/mypage/MyPageViewModel.kt @@ -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 @@ -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()) } } } @@ -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 } } @@ -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 } } @@ -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>() {}.type @@ -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}") } } }