Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] hotfix/log 로그인 버그로 인한 인터셉터 수정 및 로그백 일부 수정 #337

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
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 @@ -50,12 +50,11 @@ public boolean preHandle(
}

Long memberId = extractMemberIdFromToken(request);

if (isLoginRequired((HandlerMethod) handler)) {
validateMember(memberId);
}
if (!(isLoginRequired((HandlerMethod) handler)) && Objects.nonNull(memberId)) {
validateMember(memberId);
}

request.setAttribute("memberId", memberId);

return true;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ logging:
BasicBinder: TRACE
file:
# jar 파일 실행 시, jar 파일과 동일한 디렉토리 내 log 디렉토리에 생성됨
path: ./log
path: /home/ubuntu/backend/build/log
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} %msg %n"
file: "%d{yyyy-MM-dd HH:mm:ss.SSS} %msg %n"
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spring:
logging:
file:
# jar 파일 실행 시, jar 파일과 동일한 디렉토리 내 log 디렉토리에 생성됨
path: ./log
path: /home/ubuntu/backend/build/log
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} %msg %n"
file: "%d{yyyy-MM-dd HH:mm:ss.SSS} %msg %n"
Expand Down
35 changes: 11 additions & 24 deletions backend/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,37 @@

<!-- 콘솔 로그 설정 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
${LOG_PATTERN}
</Pattern>
</layout>
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
${LOG_PATTERN}
</Pattern>
</layout>
</encoder>
</appender>

<!-- WARN 레벨 파일 로그 설정 -->
<appender name="FILE_WARN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<appender name="FILE_WARN" class="ch.qos.logback.core.FileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>

<file>${LOG_PATH}/${DateFormat}/warn.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>
${LOG_PATH}/%d{yyyy-MM-dd}/warn_%i.log
</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
Comment on lines -23 to -30
Copy link
Collaborator

Choose a reason for hiding this comment

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

가무사합니다~

</rollingPolicy>
<file>${LOG_PATH}/warn.log</file>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>

<!-- ERROR 레벨 파일 로그 설정 -->
<appender name="FILE_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<appender name="FILE_ERROR" class="ch.qos.logback.core.FileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>

<file>${LOG_PATH}/${DateFormat}/error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>
${LOG_PATH}/%d{yyyy-MM-dd}/error_%i.log
</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<file>${LOG_PATH}/error.log</file>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
import com.mapbefine.mapbefine.topic.dto.request.TopicUpdateRequest;
import com.mapbefine.mapbefine.topic.dto.response.TopicDetailResponse;
import com.mapbefine.mapbefine.topic.dto.response.TopicResponse;
import io.restassured.RestAssured;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import io.restassured.*;
import io.restassured.response.*;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -417,4 +416,19 @@ void findAllTopicsByMemberId_Success() {
assertThat(responses).hasSize(1);
}

@Test
@DisplayName("게스트일 때도 모든 토픽을 조회할 수 있다.")
void findAllTopicsWhenGuest() {
// when
ExtractableResponse<Response> response = RestAssured
.given().log().all()
.accept(MediaType.APPLICATION_JSON_VALUE)
.when().get("/topics")
.then().log().all()
.extract();

// then
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
}

}
Loading