Skip to content

Commit

Permalink
Use logger instead of println
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbata committed Oct 5, 2023
1 parent b5e473e commit 867b980
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 314 deletions.
13 changes: 9 additions & 4 deletions src/doom/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import m.Settings;
import static m.Settings.SETTINGS_MAP;
import mochadoom.Loggers;
import utils.ParseString;
import utils.QuoteType;
import utils.ResourceIO;
Expand All @@ -38,6 +41,8 @@
*/
public class ConfigManager {

private static final Logger LOGGER = Loggers.getLogger(ConfigManager.class.getName());

private static final Pattern SPLITTER = Pattern.compile("[ \t\n\r\f]+");

private final List<Files> configFiles = ConfigBase.getFiles();
Expand Down Expand Up @@ -224,7 +229,7 @@ private void LoadDefaults() {
configMap.put(setting, setting.defaultValue);
});

System.out.print("M_LoadDefaults: Load system defaults.\n");
LOGGER.log(Level.INFO, "M_LoadDefaults: Load system defaults.");
this.configFiles.forEach(file -> {
final Optional<ResourceIO> maybeRIO = file.firstValidPathIO();

Expand All @@ -240,7 +245,7 @@ private void LoadDefaults() {
}

private boolean readFoundConfig(Files file, ResourceIO rio) {
System.out.print(String.format("M_LoadDefaults: Using config %s.\n", rio.getFileame()));
LOGGER.log(Level.INFO, String.format("M_LoadDefaults: Using config %s.", rio.getFileame()));
if (rio.readLines(line -> {
final String[] split = SPLITTER.split(line, 2);
if (split.length < 2) {
Expand All @@ -256,7 +261,7 @@ private boolean readFoundConfig(Files file, ResourceIO rio) {
.orElse(split[1]);

if (update(setting, value) == UpdateStatus.INVALID) {
System.err.printf("WARNING: invalid config value for: %s in %s \n", name, rio.getFileame());
LOGGER.log(Level.WARNING, String.format("WARNING: invalid config value for: %s in %s", name, rio.getFileame()));
} else {
setting.rebase(file);
}
Expand All @@ -267,7 +272,7 @@ private boolean readFoundConfig(Files file, ResourceIO rio) {
}

// Something went bad, but this won't destroy successfully read values, though.
System.err.printf("Can't read the settings file %s\n", rio.getFileame());
LOGGER.log(Level.SEVERE, String.format("Can't read the settings file %s", rio.getFileame()));
return false;
}

Expand Down
Loading

0 comments on commit 867b980

Please sign in to comment.