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

[FEAT] slf4j 추가 #124 #127

Merged
merged 3 commits into from
Jan 22, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: create application.yml
run: |
## create application.yml
mkdir ./cakey-api/src/main/resources
mkdir -p ./cakey-api/src/main/resources
cd ./cakey-api/src/main/resources

# application.yml 파일 생성
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fasterxml.jackson.databind.JsonMappingException;
import jakarta.persistence.EntityNotFoundException;
import jakarta.validation.ConstraintViolationException;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.support.DefaultMessageSourceResolvable;
Expand All @@ -28,6 +29,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.stream.Collectors;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

Expand Down Expand Up @@ -198,6 +200,7 @@ public ResponseEntity<BaseResponse<?>> handleDataIntegrityViolationException(fin
public ResponseEntity<BaseResponse<?>> handleInvocationTargetException(final InvocationTargetException e) {
Throwable cause = e.getCause();
System.out.println(cause.getMessage());
log.error(cause.getMessage());
return ApiResponseUtil.failure(ErrorBaseCode.INTERNAL_SERVER_ERROR, cause.getMessage());
}

Expand All @@ -206,8 +209,7 @@ public ResponseEntity<BaseResponse<?>> handleInvocationTargetException(final Inv
*/
@ExceptionHandler(Exception.class)
public ResponseEntity<BaseResponse<?>> handleAllExceptions(final Exception e) {
// log.error(e.getMessage());

log.error("e.getMessage() + e.getCause().getMessage()");
return ApiResponseUtil.failure(ErrorBaseCode.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
37 changes: 37 additions & 0 deletions cakey-api/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 로컬 - console-->
<springProfile name="local">
<appender name="LOCALCONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{0}) - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="LOCALCONSOLE"/>
</root>
</springProfile>

<!-- ec2 - rollingFile-->
<springProfile name="dev">
<appender name="DEVROLLFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %logger{0} - %msg%n</pattern>
</encoder>
<file>/home/ubuntu/CAKEY-ERROR-LOG.log</file>

<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/home/ubuntu/CAKEY-ERROR-LOG-%d{yyyy-MM-dd}-%i-log.zip</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
</appender>
<root level="ERROR">
<appender-ref ref="DEVROLLFILE"/>
</root>
</springProfile>

</configuration>