Skip to content

Commit 17aa0df

Browse files
committed
More loggin
1 parent a0030fb commit 17aa0df

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
2020
COPY src ./src
2121
COPY client ./client
2222
COPY gradle ./gradle
23+
COPY newrelic ./newrelic
2324
COPY build.gradle settings.gradle browserMonitoringTemplate.js ./
2425
COPY --chmod=0755 gradlew ./
2526

@@ -35,12 +36,13 @@ ENV BROWSER_TRUST_KEY=$BROWSER_TRUST_KEY
3536
ENV BROWSER_AGENT_ID=$BROWSER_AGENT_ID
3637
ENV BROWSER_APPLICATION_ID=$BROWSER_APPLICATION_ID
3738

39+
RUN --mount=type=cache,target=/root/.gradle ./gradlew downloadNewRelicAgent --console=plain --info --no-daemon --no-watch-fs
3840
RUN --mount=type=cache,target=/root/.gradle ./gradlew build --console=plain --info --no-daemon --no-watch-fs
3941

4042
FROM base AS final
4143
WORKDIR /app
4244
COPY --from=build /src/build/libs/petclinic-backend-1.0.0.jar .
43-
COPY ["newrelic/", "./newrelic"]
45+
COPY --from=build /src/newrelic/ ./newrelic/
4446

4547
COPY --chmod=0755 entrypoint.sh /
4648
COPY --chmod=0755 tester.sh /app
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package org.springframework.samples.petclinic;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
35
import org.springframework.scheduling.annotation.Scheduled;
46
import org.springframework.stereotype.Component;
57

68
@Component
79
public class MetricDumper {
10+
private static final Logger logger = LoggerFactory.getLogger(MetricDumper.class);
11+
812
@Scheduled(fixedDelay = 60000)
913
public void dump() {
14+
logger.info("MetricDumper - Dumping All Metrics");
1015
MetricService.dumpMetrics();
1116
}
1217
}

src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void setAllowedFields(WebDataBinder dataBinder) {
6666
@ModelAttribute("owner")
6767
public Owner findOwner(@PathVariable(name = "ownerId", required = false) Integer ownerId) {
6868
if(ownerId == null) {
69-
logger.info("OwnerId NULL");
69+
logger.info("OwnerId=NULL");
7070
return new Owner();
7171
}
7272

@@ -89,6 +89,7 @@ public String processCreationForm(@Valid Owner owner, BindingResult result, Redi
8989
}
9090

9191
this.owners.save(owner);
92+
logger.info("Created New Owner={}", owner);
9293
redirectAttributes.addFlashAttribute("message", "New Owner Created");
9394
return "redirect:/owners/" + owner.getId();
9495
}
@@ -104,6 +105,7 @@ public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner
104105

105106
// allow parameterless GET request for /owners to return all records
106107
if (owner.getLastName() == null) {
108+
logger.info("Retrieving ALL Owners");
107109
owner.setLastName(""); // empty string signifies broadest possible search
108110
}
109111

@@ -160,6 +162,7 @@ public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @
160162

161163
owner.setId(ownerId);
162164
this.owners.save(owner);
165+
logger.info("Updated Owner={}", owner);
163166
redirectAttributes.addFlashAttribute("message", "Owner Values Updated");
164167
return "redirect:/owners/{ownerId}";
165168
}

src/main/java/org/springframework/samples/petclinic/owner/OwnerRestController.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.springframework.samples.petclinic.owner;
22

3-
import java.util.ArrayList;
43
import java.util.List;
54

5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
67
import org.springframework.http.HttpStatus;
78
import org.springframework.http.ResponseEntity;
89
import org.springframework.samples.petclinic.dto.OwnerDto;
@@ -21,6 +22,8 @@
2122
@RequestMapping("/rest")
2223
public class OwnerRestController {
2324

25+
private static final Logger logger = LoggerFactory.getLogger(OwnerRestController.class);
26+
2427
private final OwnerRepository owners;
2528

2629
private final OwnerMapper mapper;
@@ -32,12 +35,13 @@ public OwnerRestController(OwnerRepository clinicService, OwnerMapper mapper) {
3235

3336
@GetMapping("/owners")
3437
private List<Owner> findListForOwnersLastName(String lastName) {
35-
List<Owner> ownersResult = new ArrayList<>();
3638
if (lastName != null) {
37-
ownersResult = owners.findByLastName(lastName);
39+
logger.info("Searching Owners By Last Name='{}'", lastName);
40+
return owners.findByLastName(lastName);
3841
}
39-
return ownersResult.isEmpty() ? owners.findAll() : ownersResult;
4042

43+
logger.info("Retrieving ALL Owners");
44+
return owners.findAll();
4145
}
4246

4347
@GetMapping("/owners/{ownerId}")
@@ -48,6 +52,7 @@ public Owner findOwnerById(@PathVariable int ownerId) {
4852
@PostMapping("/owners/new")
4953
public ResponseEntity processCreationForm(@Valid @RequestBody Owner owner) {
5054
this.owners.save(owner);
55+
logger.info("Created New Owner={}", owner);
5156
return new ResponseEntity<>(HttpStatus.CREATED);
5257
}
5358

@@ -57,6 +62,8 @@ public ResponseEntity<Owner> updateOwner(@PathVariable int ownerId, @RequestBody
5762
mapper.updateOwnerFromDto(ownerDto, owner);
5863
owners.save(owner);
5964

65+
logger.info("Updated Owner={}", owner);
66+
6067
return new ResponseEntity<>(owner, HttpStatus.OK);
6168
}
6269

src/main/java/org/springframework/samples/petclinic/vet/VetRestController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.Collection;
44

5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
57
import org.springframework.web.bind.annotation.GetMapping;
68
import org.springframework.web.bind.annotation.RequestMapping;
79
import org.springframework.web.bind.annotation.RestController;
@@ -11,13 +13,15 @@
1113
public class VetRestController {
1214

1315
private final VetRepository vets;
16+
private static final Logger logger = LoggerFactory.getLogger(VetRestController.class);
1417

1518
public VetRestController(VetRepository clinicService) {
1619
this.vets = clinicService;
1720
}
1821

1922
@GetMapping("/vets")
2023
private Collection<Vet> findListForOwnersLastName() {
24+
logger.info("Searching ALL Vets");
2125
return vets.findAll();
2226
}
2327

0 commit comments

Comments
 (0)