Skip to content

Enhance CLI output with ASCII sun art and suppress INFO log messages #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/art/sun.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
\ | /
\ | /
--- \ | / ---
\ | /
--- \|/ ---
====== * ======
--- /|\ ---
/ | \
--- / | \ ---
/ | \
/ | \

β˜€οΈ β˜€οΈ β˜€οΈ β˜€οΈ β˜€οΈ β˜€οΈ β˜€οΈ
49 changes: 42 additions & 7 deletions src/main/java/com/weather/app/WeatherApp.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.weather.app;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
Expand Down Expand Up @@ -54,18 +56,53 @@ private static boolean exit(int status) {
return true;
}

/**
* Load ASCII art from a resource file
*
* @param filename the name of the art file to load
* @return the ASCII art as a string, or empty string if not found
*/
private static String loadAsciiArt(String filename) {
StringBuilder art = new StringBuilder();
try (InputStream is = WeatherApp.class.getClassLoader().getResourceAsStream("art/" + filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {

String line;
while ((line = reader.readLine()) != null) {
art.append(line).append(System.lineSeparator());
}
} catch (IOException | NullPointerException e) {
LOGGER.log(Level.FINE, "Could not load ASCII art file: " + filename, e);
}
return art.toString();
}

/**
* Display weather data with ASCII sun art
*
* @param weatherData the weather data to display
*/
private static void displayWeatherWithArt(WeatherData weatherData) {
System.out.println();
System.out.println(loadAsciiArt("sun.txt"));
System.out.println("Current Weather for " + weatherData.getCity() + ":");
System.out.println("========================================");
System.out.println(weatherData);
System.out.println();
}

public static void main(String[] args) {
// Validate command line arguments
if (args.length < 1) {
LOGGER.log(Level.INFO, "Usage: java -jar WeatherApp.jar <city-name>");
LOGGER.log(Level.INFO, "Example: java -jar WeatherApp.jar London");
System.out.println("Usage: java -jar WeatherApp.jar <city-name>");
System.out.println("Example: java -jar WeatherApp.jar London");
exit(1);
return;
}

// Get the city name from command line arguments
String city = args[0];
LOGGER.log(Level.INFO, "Weather request for city: {0}", city);
LOGGER.log(Level.FINE, "Weather request for city: {0}", city);

try {
// Get API key from environment or config file
Expand All @@ -79,10 +116,8 @@ public static void main(String[] args) {
WeatherData weatherData = weatherService.getWeather(city);
LOGGER.log(Level.FINE, weatherData.toString());

// Display weather data to the user
System.out.println("Current Weather for " + city + ":");
System.out.println("-------------------------------------");
System.out.println(weatherData);
// Display weather data to the user with ASCII art
displayWeatherWithArt(weatherData);

} catch (ConfigUtil.ConfigException e) {
LOGGER.log(Level.SEVERE, "Configuration error: " + e.getMessage(), e);
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/art/sun.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
\ | /
\ | /
--- \ | / ---
\ | /
--- \|/ ---
====== * ======
--- /|\ ---
/ | \
--- / | \ ---
/ | \
/ | \

β˜€οΈ β˜€οΈ β˜€οΈ β˜€οΈ β˜€οΈ β˜€οΈ β˜€οΈ
10 changes: 5 additions & 5 deletions src/main/resources/logging.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Default global logging level
.level=INFO
.level=SEVERE

# Root logger handlers
handlers=java.util.logging.ConsoleHandler

# ConsoleHandler configuration
java.util.logging.ConsoleHandler.level=INFO
# ConsoleHandler configuration - only show SEVERE and WARNING messages
java.util.logging.ConsoleHandler.level=WARNING
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

# SimpleFormatter configuration
java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%4$-7s] %2$s - %5$s %n

# Application specific logging levels
com.weather.app.level=INFO
# Application specific logging levels - suppress INFO messages from console
com.weather.app.level=WARNING