Skip to content

Commit a0030fb

Browse files
committed
Adding logging
1 parent 814383c commit a0030fb

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

client/src/pages/Error.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import pets from '/src/assets/images/pets.png';
22

33
export const Error = () => {
4+
5+
6+
const numbers = [0,1,2];
7+
const theNumber = numbers[10];
8+
49
return (
510
<>
611
<div className="row">
@@ -9,6 +14,7 @@ export const Error = () => {
914
</div>
1015
</div>
1116
<h2>Something happened...</h2>
17+
<h3>{theNumber}</h3>
1218
</>
1319
);
1420
};

src/main/java/org/springframework/samples/petclinic/clm/RandomExceptionGenerator.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.springframework.samples.petclinic.clm;
22

33
import com.newrelic.api.agent.Trace;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
46

57
import java.util.List;
68
import java.util.Random;
@@ -9,6 +11,8 @@
911

1012
public class RandomExceptionGenerator {
1113

14+
private static final Logger logger = LoggerFactory.getLogger(RandomExceptionGenerator.class);
15+
1216
private static final String[] words = {
1317
"Quantum", "Flux", "Anomaly", "Paradox", "Entropy", "Singularity", "Nebula", "Vortex", "Pulsar", "Quasar",
1418
"Eclipse", "Galaxy", "Meteor", "Orbit", "Blackhole", "Asteroid", "Comet", "Supernova", "Cosmos", "Universe",
@@ -63,6 +67,9 @@ private static String generateRandomMessage(Random random) {
6367
message.append(" ");
6468
}
6569
}
66-
return message.toString();
70+
String finalMessage = message.toString();
71+
logger.info("Generated Random Message: {}", finalMessage);
72+
73+
return finalMessage;
6774
}
6875
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020

2121
import jakarta.validation.Valid;
2222

23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
2325
import org.springframework.data.domain.Page;
2426
import org.springframework.data.domain.PageRequest;
2527
import org.springframework.data.domain.Pageable;
28+
import org.springframework.samples.petclinic.clm.ClmController;
2629
import org.springframework.stereotype.Controller;
2730
import org.springframework.ui.Model;
2831
import org.springframework.validation.BindingResult;
@@ -49,6 +52,7 @@ class OwnerController {
4952
private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
5053

5154
private final OwnerRepository owners;
55+
private static final Logger logger = LoggerFactory.getLogger(OwnerController.class);
5256

5357
public OwnerController(OwnerRepository clinicService) {
5458
this.owners = clinicService;
@@ -61,7 +65,12 @@ public void setAllowedFields(WebDataBinder dataBinder) {
6165

6266
@ModelAttribute("owner")
6367
public Owner findOwner(@PathVariable(name = "ownerId", required = false) Integer ownerId) {
64-
return ownerId == null ? new Owner() : this.owners.findById(ownerId);
68+
if(ownerId == null) {
69+
logger.info("OwnerId NULL");
70+
return new Owner();
71+
}
72+
73+
return this.owners.findById(ownerId);
6574
}
6675

6776
@GetMapping("/owners/new")
@@ -74,6 +83,7 @@ public String initCreationForm(Map<String, Object> model) {
7483
@PostMapping("/owners/new")
7584
public String processCreationForm(@Valid Owner owner, BindingResult result, RedirectAttributes redirectAttributes) {
7685
if (result.hasErrors()) {
86+
logger.error("Error Creating New Owner; Validation Failed");
7787
redirectAttributes.addFlashAttribute("error", "There was an error in creating the owner.");
7888
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
7989
}
@@ -143,6 +153,7 @@ public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model mo
143153
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @PathVariable("ownerId") int ownerId,
144154
RedirectAttributes redirectAttributes) {
145155
if (result.hasErrors()) {
156+
logger.error("Error Updating Owner; Validation Failed");
146157
redirectAttributes.addFlashAttribute("error", "There was an error in updating the owner.");
147158
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
148159
}

0 commit comments

Comments
 (0)