Skip to content

Commit

Permalink
Merge pull request #68 from gosopt-LionHeart/feat/#67
Browse files Browse the repository at this point in the history
Feat/#67 LogBack 설정
  • Loading branch information
PgmJun authored Jul 28, 2023
2 parents 8d102ae + 1f34182 commit 9ab21d7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ out/
### VS Code ###
.vscode/

firebase_service_key.json
firebase_service_key.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ public class AdminCheckHandler {
private final JwtUtils jwtUtils;
private final MemberRepository memberRepository;

public void validateMemberRole(HttpServletRequest request) {
public boolean hasRole(HttpServletRequest request) {
String bearerToken = request.getHeader("Authorization");
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
String accessToken = bearerToken.substring("Bearer ".length());
if (hasAdminAuthority(accessToken)) {
return;
}
return hasAdminAuthority(accessToken);
}
throw new ForbiddenException(ADMIN_ERROR_MESSAGE, FORBIDDEN_ADMIN_EXCEPTION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
if (admin.isEmpty()) {
return true;
}
adminCheckHandler.validateMemberRole(request);
return true;

return adminCheckHandler.hasRole(request);
}
}
69 changes: 69 additions & 0 deletions lionheart-common/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>

<property name="CONSOLE_LOG_PATTERN"
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %clr(%5level) %cyan(%logger) - %msg%n"/>
<property name="FILE_LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %5level %logger - %msg%n"/>

<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>

<appender name="API-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/home/ubuntu/api-server/logs/%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>

<appender name="NOTIFICATION-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/home/ubuntu/notification-server/logs/%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>


<springProfile name="local">
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
<logger name="com.chiwawa.lionheart" level="TRACE" />
</springProfile>

<springProfile name="dev">
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
<logger name="com.chiwawa.lionheart.api" level="INFO">
<appender-ref ref="API-FILE"/>
</logger>
<logger name="com.chiwawa.lionheart.notification" level="INFO">
<appender-ref ref="NOTIFICATION-FILE"/>
</logger>
</springProfile>

<springProfile name="prod">
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
<logger name="com.chiwawa.lionheart.api" level="INFO">
<appender-ref ref="API-FILE"/>
</logger>
<logger name="com.chiwawa.lionheart.notification" level="INFO">
<appender-ref ref="NOTIFICATION-FILE"/>
</logger>
</springProfile>

</configuration>

0 comments on commit 9ab21d7

Please sign in to comment.