diff --git a/src/main/java/com/boatticket/config/ConfigManager.java b/src/main/java/com/boatticket/config/ConfigManager.java index 2910006..786139c 100644 --- a/src/main/java/com/boatticket/config/ConfigManager.java +++ b/src/main/java/com/boatticket/config/ConfigManager.java @@ -67,6 +67,10 @@ public class ConfigManager { // causes PDFs to be generated at a real deployed counter. private static final boolean DEFAULT_DEV_MODE = false; + // Keep this false so a broken/missing config never accidentally pops + // open a console window at a real deployed counter. + private static final boolean DEFAULT_CONSOLE_ENABLED = false; + private static Properties cachedProperties; private ConfigManager() {} @@ -175,6 +179,28 @@ public static boolean isDevMode() { return Boolean.parseBoolean(value.trim()); } + // ------------------------------------------------------------------ + // Console toggle + // ------------------------------------------------------------------ + + /** + * True: a visible log console window is opened at startup, live-showing everything the app logs. + * + *
False (default, and what every shipped tenant config uses): no console window is ever shown, + * regardless of {@link #isDevMode()} — the two flags are independent. The packaged app is always + * a GUI-subsystem executable with no native console, so this is what actually controls whether + * {@link LoggingConfigurator} spawns its own visible log window. + */ + public static boolean isConsoleEnabled() { + String value = getProperties().getProperty("console"); + + if (value == null || value.isBlank()) { + return DEFAULT_CONSOLE_ENABLED; + } + + return Boolean.parseBoolean(value.trim()); + } + // ------------------------------------------------------------------ // Printer // ------------------------------------------------------------------ @@ -285,6 +311,8 @@ private static Properties load() { System.out.println( "[ConfigManager] dev.mode = " + props.getProperty("dev.mode") + + ", console = " + + props.getProperty("console") + ", printer.name = " + props.getProperty("printer.name")); } catch (IOException e) { @@ -345,6 +373,7 @@ private static void writeHardcodedDefaults(Path configFilePath) throws IOExcepti "update.connection.timeout.seconds", String.valueOf(DEFAULT_UPDATE_CONNECTION_TIMEOUT_SECONDS)); defaults.setProperty("dev.mode", String.valueOf(DEFAULT_DEV_MODE)); + defaults.setProperty("console", String.valueOf(DEFAULT_CONSOLE_ENABLED)); defaults.setProperty("printer.name", ""); defaults.setProperty( "printer.left.margin.dots", String.valueOf(DEFAULT_PRINTER_LEFT_MARGIN_DOTS)); diff --git a/src/main/java/com/boatticket/config/LoggingConfigurator.java b/src/main/java/com/boatticket/config/LoggingConfigurator.java new file mode 100644 index 0000000..da27258 --- /dev/null +++ b/src/main/java/com/boatticket/config/LoggingConfigurator.java @@ -0,0 +1,106 @@ +package com.boatticket.config; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.logging.FileHandler; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.logging.SimpleFormatter; + +/** + * Controls, entirely through {@link ConfigManager#isConsoleEnabled()} (backed by each tenant's + * external {@code Config.properties}), whether a visible log console appears at runtime. + * + *
The packaged app is a GUI-subsystem executable (no console window is ever created by Windows + * itself — see {@code publish-release.yaml}, {@code --win-console} was intentionally removed), so + * whether a console-like window shows up can no longer be decided by any OS/packaging setting. This + * class fills that gap at the Java level instead, using its own independent {@code console} + * property (separate from {@code dev.mode}, which only controls the reference-PDF feature): + * + *