-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Overview
This issue addresses the need to replace all instances of printStackTrace() and System.out.println()/print() with proper logging using SLF4J Logger.
Implementation
The following instances need to be replaced:
printStackTrace() Occurrences
-
src/main/java/botcommons/utilities/JsonUtils.java:60
- Current:
e.printStackTrace(); - Replace with:
logger.error("Failed to read cache file {}: {}", file.getName(), e.getMessage(), e);
- Current:
-
src/main/java/botcommons/utilities/JsonUtils.java:76
- Current:
e.printStackTrace(); - Replace with:
logger.error("Failed to write cache file {}: {}", file.getName(), e.getMessage(), e);
- Current:
-
src/main/java/botcommons/config/ConfigManager.java:77
- Current:
e.printStackTrace(); - Replace with:
logger.error("Failed to write config file for server {}: {}", serverId, e.getMessage(), e);
- Current:
-
src/main/java/botcommons/config/ConfigManager.java:106
- Current:
e.printStackTrace(); - Replace with:
logger.error("Error loading configuration for guild {}: {}", event.getGuild().getId(), e.getMessage(), e);
- Current:
-
src/main/java/botcommons/config/Config.java:32
- Current:
e.printStackTrace(); - Replace with:
logger.error("Failed to load configuration from file: {}", e.getMessage(), e);
- Current:
-
src/main/java/botcommons/config/Config.java:48
- Current:
e.printStackTrace(); - Replace with:
logger.error("Failed to write configuration to file: {}", e.getMessage(), e);
- Current:
-
src/main/java/botcommons/commands/ReplyContext.java:196
- Current:
e.printStackTrace(); - Replace with:
logger.error("Failed to execute menu action: {}", e.getMessage(), e);
- Current:
-
src/main/java/botcommons/commands/CommandManager.java:168
- Current:
e.printStackTrace(); - Replace with:
logger.error("Error during command execution: {}", e.getMessage(), e);
- Current:
-
src/main/java/botcommons/commands/CommandManager.java:194
- Current:
e.printStackTrace(); - Replace with:
logger.error("Error handling button event: {}", e.getMessage(), e);
- Current:
System.out.println/print Occurrences
-
src/main/java/botcommons/utilities/JsonUtils.java:57
- Current:
System.out.println("Loaded existing data from " + file.getName()); - Replace with:
logger.debug("Loaded existing data from {}", file.getName());
- Current:
-
src/main/java/botcommons/config/ConfigManager.java:69
- Current:
System.out.println("[ConfigManager] Successfully wrote config for server " + serverId); - Replace with:
logger.info("Successfully wrote config for server {}", serverId);
- Current:
-
src/main/java/botcommons/commands/impl/ConfigCommand.java:55
- Current:
System.out.println("Yes"); - Replace with:
logger.debug("User confirmed config key creation");
- Current:
-
src/main/java/botcommons/commands/impl/ConfigCommand.java:61
- Current:
System.out.println("No"); - Replace with:
logger.debug("User declined config key creation");
- Current:
-
src/main/java/botcommons/commands/ReplyContext.java:175
- Current:
System.out.println("Timeout duration must be positive, defaulting to 1 second"); - Replace with:
logger.warn("Timeout duration must be positive, defaulting to 1 second");
- Current:
-
src/main/java/botcommons/commands/GenericCommandEvent.java:195
- Current:
System.out.println("Registered menu with id: " + id); - Replace with:
logger.debug("Registered menu with id: {}", id);
- Current:
-
src/main/java/botcommons/cache/CacheManager.java:80
- Current:
System.out.printf("Loaded %d members for guild %s%n", members.size(), event.getGuild().getName()); - Replace with:
logger.info("Loaded {} members for guild {}", members.size(), event.getGuild().getName());
- Current:
Guide for Implementation
-
Add the following imports if not already present:
-
Initialize the logger at the class level:
-
Replace each occurrence with the suggested logger statement.
Best Practices
-
Use appropriate log levels:
- ERROR: For errors that affect application functionality
- WARN: For important issues that don't break functionality
- INFO: For informational messages about application progress
- DEBUG: For detailed debugging information
- TRACE: For the most detailed information
-
Use parameterized logging (e.g.,
logger.info("Message {}", value);) instead of string concatenation to avoid unnecessary string creation when logging is disabled. -
Include the exception object as the last parameter in error logs for stack trace information.