Skip to content

Commit

Permalink
Merge pull request #116 from IT-Cotato/feature/92-implement-manage-log
Browse files Browse the repository at this point in the history
Feature: 프로필 별 로그 관리 및 로그 출력 설정(#92)
  • Loading branch information
yooooonshine authored Aug 7, 2024
2 parents 1176995 + 02fdd8a commit 57770ee
Show file tree
Hide file tree
Showing 27 changed files with 724 additions and 492 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ out/
src/main/resources/application-security.properties
### applcation-api ###
src/main/resources/application-api.properties
src/main/resources/application.properties
src/main/resources/application.properties

### log file
/log/
8 changes: 8 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ dependencies {
testImplementation group: 'org.springdoc', name: 'springdoc-openapi-starter-webmvc-api', version: '2.5.0'
//bucket4j
implementation group: 'com.github.vladimir-bukhtoyarov', name: 'bucket4j-core', version: '8.0.1'
//aop
implementation 'org.springframework.boot:spring-boot-starter-aop'
}

tasks.named('test') {
useJUnitPlatform()
}

//profile별로 실행시
bootRun {
String activeProfile = System.properties['spring.profiles.active']
systemProperty "spring.profiles.active", activeProfile
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package middle_point_search.backend;

import java.util.TimeZone;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import jakarta.annotation.PostConstruct;
import middle_point_search.backend.common.filter.RateLimitFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import jakarta.annotation.PostConstruct;
import middle_point_search.backend.common.filter.RateLimitFilter;
import java.util.TimeZone;

@SpringBootApplication
@EnableJpaAuditing
@EnableAspectJAutoProxy
@OpenAPIDefinition(servers = {@Server(url = "/", description = "https://www.api.cotato-midpoint.site")})
public class BackendApplication {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package middle_point_search.backend.common.aop;

import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@Aspect
@Slf4j
@Component
public class LogAspect {

@Pointcut("execution(* middle_point_search.backend..*.*(..)) && !execution(* middle_point_search.backend.common..*(..))")
public void all() {
}

@Pointcut("execution(* middle_point_search.backend..*Controller.*(..))")
public void controller() {
}

@Around("all()")
public Object logging(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
try {
Object result = joinPoint.proceed();
return result;
} finally {
long end = System.currentTimeMillis();
long timeinMs = end - start;
log.info("{} | time = {}ms", joinPoint.getSignature(), timeinMs);
}
}

@Around("controller()")
public Object loggingBefore(ProceedingJoinPoint joinPoint) throws Throwable {
final HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
final String ipAddr = request.getRemoteAddr();
final String method = request.getMethod();
final String requestURI = request.getRequestURI();
final Object[] args = joinPoint.getArgs();

log.info("[REQUEST] {} {} {} args={}", ipAddr, method, requestURI, args);
try {
Object result = joinPoint.proceed();
log.info("[RESPONSE] {}", result);
return result;
} catch (Exception e) {
log.error("[RESPONSE] exception message = {} {}", e.getMessage(), e.getStackTrace()[0]);
throw e;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package middle_point_search.backend.domains.placeVoteRoom.controller;

import static middle_point_search.backend.domains.placeVoteRoom.dto.PlaceVoteRoomDTO.*;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -15,19 +16,16 @@
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import jakarta.validation.Valid;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import middle_point_search.backend.common.dto.BaseResponse;
import middle_point_search.backend.common.dto.DataResponse;
import middle_point_search.backend.common.dto.ErrorResponse;
import middle_point_search.backend.common.util.MemberLoader;
import middle_point_search.backend.domains.placeVoteRoom.service.PlaceVoteRoomService;
import middle_point_search.backend.domains.member.domain.Member;
import middle_point_search.backend.domains.placeVoteRoom.service.PlaceVoteRoomService;
import middle_point_search.backend.domains.room.domain.Room;
import static middle_point_search.backend.domains.placeVoteRoom.dto.PlaceVoteRoomDTO.*;



@Tag(name = "PLACE VOTE ROOM API", description = "장소 투표에 대한 API입니다.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -14,48 +15,49 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PlaceVoteCandidate {

@Id
@Column(name = "place_vote_candidate_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Id
@Column(name = "place_vote_candidate_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String name;
@Column(nullable = false)
private String name;

@Column(nullable = false)
private String siDo;
@Column(nullable = false)
private String siDo;

@Column(nullable = false)
private String siGunGu;
@Column(nullable = false)
private String siGunGu;

@Column(nullable = false)
private String roadNameAddress;
@Column(nullable = false)
private String roadNameAddress;

@Column(nullable = false)
private Double addressLatitude;
@Column(nullable = false)
private Double addressLatitude;

@Column(nullable = false)
private Double addressLongitude;
@Column(nullable = false)
private Double addressLongitude;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "place_vote_room_id")
private PlaceVoteRoom placeVoteRoom;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "place_vote_room_id")
private PlaceVoteRoom placeVoteRoom;

@OneToMany(mappedBy = "placeVoteCandidate", cascade = {CascadeType.PERSIST, CascadeType.MERGE}, orphanRemoval = true)
private List<PlaceVoteCandidateMember> voters = new ArrayList<>();
@OneToMany(mappedBy = "placeVoteCandidate", cascade = {CascadeType.PERSIST,
CascadeType.MERGE}, orphanRemoval = true)
private List<PlaceVoteCandidateMember> voters = new ArrayList<>();

public PlaceVoteCandidate(PlaceCandidateInfo candidate, PlaceVoteRoom placeVoteRoom) {
this.name = candidate.getName();
this.siDo = candidate.getSiDo();
this.siGunGu = candidate.getSiGunGu();
this.roadNameAddress = candidate.getRoadNameAddress();
this.addressLatitude = candidate.getAddressLat();
this.addressLongitude = candidate.getAddressLong();
this.placeVoteRoom = placeVoteRoom;
}
public PlaceVoteCandidate(PlaceCandidateInfo candidate, PlaceVoteRoom placeVoteRoom) {
this.name = candidate.getName();
this.siDo = candidate.getSiDo();
this.siGunGu = candidate.getSiGunGu();
this.roadNameAddress = candidate.getRoadNameAddress();
this.addressLatitude = candidate.getAddressLat();
this.addressLongitude = candidate.getAddressLong();
this.placeVoteRoom = placeVoteRoom;
}

public int getCount() {
return voters.size();
}
public int getCount() {
return voters.size();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PlaceVoteCandidateMember {

@Id
@Column(name = "place_vote_candidate_member_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Id
@Column(name = "place_vote_candidate_member_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "place_vote_candidate_id")
private PlaceVoteCandidate placeVoteCandidate;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "place_vote_candidate_id")
private PlaceVoteCandidate placeVoteCandidate;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;
public PlaceVoteCandidateMember(PlaceVoteCandidate placeVoteCandidate, Member member) {
this.placeVoteCandidate = placeVoteCandidate;
this.member = member;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

public PlaceVoteCandidateMember(PlaceVoteCandidate placeVoteCandidate, Member member) {
this.placeVoteCandidate = placeVoteCandidate;
this.member = member;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PlaceVoteRoom {

@Id
@Column(name = "place_vote_room_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne
@JoinColumn(name = "room_id")
private Room room;

@OneToMany(mappedBy = "placeVoteRoom", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<PlaceVoteCandidate> placeVoteCandidates = new ArrayList<>();

public PlaceVoteRoom(Room room, List<PlaceCandidateInfo> candidates) {
this.room = room;
this.placeVoteCandidates.clear();
for (PlaceCandidateInfo candidate : candidates) {
addPlaceVoteCandidate(candidate);
}
}

public void addPlaceVoteCandidate(PlaceCandidateInfo candidate) {
this.placeVoteCandidates.add(new PlaceVoteCandidate(candidate, this));
}
@Id
@Column(name = "place_vote_room_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne
@JoinColumn(name = "room_id")
private Room room;

@OneToMany(mappedBy = "placeVoteRoom", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<PlaceVoteCandidate> placeVoteCandidates = new ArrayList<>();

public PlaceVoteRoom(Room room, List<PlaceCandidateInfo> candidates) {
this.room = room;
this.placeVoteCandidates.clear();
for (PlaceCandidateInfo candidate : candidates) {
addPlaceVoteCandidate(candidate);
}
}

public void addPlaceVoteCandidate(PlaceCandidateInfo candidate) {
this.placeVoteCandidates.add(new PlaceVoteCandidate(candidate, this));
}
}

Loading

0 comments on commit 57770ee

Please sign in to comment.