Skip to content

[feat]: Enhanced API Logging in StockService #6

@0PrashantYadav0

Description

@0PrashantYadav0

Description

  • Detailed Description:
    The current logging in StockService is minimal, using System.out.println statements. Enhanced logging (e.g., including the request URL, HTTP status, and error details) can significantly help in debugging API interactions with Finnhub.
  • How to Solve:
    1. Integrate a Logging Framework:
      Replace System.out.println with a proper logging framework such as SLF4J with Logback.
    2. Add Detailed Logs:
      In the makeFinnhubApiRequest method, log key details:
      private static final Logger logger = LoggerFactory.getLogger(StockService.class);
      
      private String makeFinnhubApiRequest(String url) {
          try {
              logger.info("Making API request to: {}", url);
              ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(new HttpHeaders()), String.class);
              logger.info("Response Status: {}", response.getStatusCode());
              logger.debug("Response Body: {}", response.getBody());
              return response.getBody();
          } catch (Exception e) {
              logger.error("Error during API request to {}: {}", url, e.getMessage());
              return "{\"error\": \"An error occurred while making the API request.\"}";
          }
      }
    3. Test Logging:
      Run the application and monitor logs to ensure the information is logged appropriately.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions