Skip to content

Commit

Permalink
merge: slf4j ์ถ”๊ฐ€ #124
Browse files Browse the repository at this point in the history
[FEAT] slf4j ์ถ”๊ฐ€ #124
  • Loading branch information
sjk4618 authored Jan 22, 2025
2 parents 92f0cde + fd4074a commit d1c5851
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
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>

0 comments on commit d1c5851

Please sign in to comment.