Logging is critical to implement to identify problems in
distributed architecture.
▪ Elastic Stack used to collect, store, and analyze log data from
multiple service instances in a microservices architecture.
▪ Useful for understanding the behavior of the system over time,
identifying patterns and trends, and troubleshooting issues.
▪ Elastic Stack might be used to collect log data from each
service instance.
▪ Kibana to visualize and analyze the data in order to identify
patterns or trends
xxxxxxxxxx
RestController
class ELKController {
private static final Logger LOG = Logger.getLogger(ELKController.class.getName());
@Autowired
RestTemplate restTemplete;
@Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
@RequestMapping(value = "/elk")
public String helloWorld() {
String response = "Welcome to JavaInUse" + new Date();
LOG.log(Level.INFO, response);
return response;
}
@RequestMapping(value = "/exception")
public String exception() {
String response = "";
try {
throw new Exception("Exception has occured....");
} catch (Exception e) {
e.printStackTrace();
LOG.error(e);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String stackTrace = sw.toString();
LOG.error("Exception - " + stackTrace);
response = stackTrace;
}
return response;
}
}