Skip to content
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
3 changes: 2 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
USER_APIKEY=${{ secrets.USER_APIKEY }}
SSL_PASSWORD=${{ secrets.SSL_PASSWORD }}
EC2_PORT=${{ secrets.EC2_PORT }}
APP_ADMIN_EMAIL=${{ secrets.APP_ADMIN_EMAIL }}
ENV_EOF

- name: Build with Gradle
Expand Down Expand Up @@ -107,7 +108,7 @@ jobs:

# 5️⃣ Start Spring Boot on HTTPS port
echo "=== Launching Spring Boot on port $EC2_PORT ==="
nohup sudo java -jar -Dspring.profiles.active=prod $JAR_PATH > /home/ubuntu/app.log 2>&1 &
nohup sudo -E java -jar -Dspring.profiles.active=prod $JAR_PATH > /dev/null 2>> /home/ubuntu/error.log &

sleep 5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public class Member {
@NotBlank
private String username;

@Column(nullable = false, length = 100)
@NotBlank
@Column(length = 100)
private String email;

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@Getter
@RequiredArgsConstructor
public enum CommonError implements CustomError {
INVALID_INPUT_VALUE(400, "유효하지 않은 입력입니다.");
INVALID_INPUT_VALUE(400, "유효하지 않은 입력입니다. %s");

private final int status;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package oneclass.oneclass.global.exception;

import lombok.extern.slf4j.Slf4j;
import oneclass.oneclass.domain.attendance.entity.AttendanceStatus;
import oneclass.oneclass.domain.attendance.error.AttendanceError;
import oneclass.oneclass.global.dto.ApiResponse;
Expand All @@ -13,12 +14,14 @@

import java.util.stream.Collectors;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

// CustomException 처리
@ExceptionHandler(CustomException.class)
public ResponseEntity<ApiResponse<Void>> handleCustomException(CustomException e) {
log.warn("CustomException: {} - {}", e.getStatus(), e.getMessage());
return ResponseEntity.status(e.getStatus())
.body(ApiResponse.error(e));
}
Expand All @@ -32,6 +35,8 @@ public ResponseEntity<ApiResponse<Void>> handleValidationExceptions(MethodArgume
.map(FieldError::getDefaultMessage)
.collect(Collectors.joining(", "));

log.info("Validation Error: {}", errors); // 간단한 정보 로그

CustomException customException =
new CustomException(CommonError.INVALID_INPUT_VALUE, errors);

Expand All @@ -43,6 +48,7 @@ public ResponseEntity<ApiResponse<Void>> handleValidationExceptions(MethodArgume
// Enum 타입 불일치 등 @RequestParam / @PathVariable 타입 오류 처리
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public ResponseEntity<ApiResponse<Void>> handleTypeMismatch(MethodArgumentTypeMismatchException ex) {
log.info("Type Mismatch: {}", ex.getValue()); // 정보 로그
if (ex.getRequiredType() == AttendanceStatus.class) {
CustomException customException =
new CustomException(AttendanceError.INVALID_STATUS, ex.getValue() + "는 올바른 출석 상태가 아닙니다.");
Expand All @@ -64,6 +70,7 @@ public ResponseEntity<ApiResponse<Void>> handleTypeMismatch(MethodArgumentTypeMi
// 그 외 모든 예외 처리
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<Void>> handleException(Exception e) {
log.error("🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 Unhandled Exception occurred: ", e);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

로그 메시지에 이모지를 사용하는 것은 일부 로그 집계 시스템이나 터미널에서 문제를 일으킬 수 있습니다. 호환성을 위해 일반 텍스트를 사용하는 것이 좋습니다.

Suggested change
log.error("🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 Unhandled Exception occurred: ", e);
log.error("Unhandled Exception occurred: ", e);

ErrorResponse errorResponse = new ErrorResponse(
"INTERNAL_SERVER_ERROR",
HttpStatus.INTERNAL_SERVER_ERROR.value(),
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ spring:
starttls.enable: true
ssl.trust: smtp.gmail.com


app:
admin:
email: ${app.admin.email}

server:
port: 8080

Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_PATH" value="/home/ubuntu/logs"/>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

로그 경로를 /home/ubuntu/logs로 하드코딩하면 다른 환경에서 애플리케이션을 실행할 때 문제가 발생할 수 있습니다. 예를 들어, 해당 경로가 없거나 쓰기 권한이 없을 수 있습니다. 이식성을 높이기 위해 상대 경로(예: logs)를 사용하거나 환경 변수를 통해 경로를 설정하는 것을 고려해보세요.

Suggested change
<property name="LOG_PATH" value="/home/ubuntu/logs"/>
<property name="LOG_PATH" value="logs"/>

<property name="LOG_FILE_NAME" value="application"/>

<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/${LOG_FILE_NAME}.log</file>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS, Asia/Seoul} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_PATH}/${LOG_FILE_NAME}-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>

<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>