001package com.studentgui.bootstrap; 002 003/** 004 * Lightweight bootstrapper that sets early system properties required by 005 * the logging subsystem (APP_HOME and LOG_TS) before delegating to the 006 * real application entry point. This ensures Logback picks up a stable 007 * per-run filename for the rolling file appender. 008 */ 009public final class Bootstrap { 010 private Bootstrap() { throw new AssertionError("not instantiable"); } 011 012 /** 013 * Bootstrap main entry. 014 * 015 * Sets early system properties required for logging (APP_HOME and 016 * LOG_TS) and ensures the logs directory exists, then delegates to 017 * the real application entry point. 018 * 019 * @param args command-line arguments forwarded to the application 020 */ 021 public static void main(final String[] args) { 022 try { 023 String appHome = com.studentgui.apphelpers.Helpers.APP_HOME.toString(); 024 System.setProperty("APP_HOME", appHome); 025 } catch (Throwable t) { 026 // Best-effort: if Helpers isn't available, fall back to a relative path 027 System.setProperty("APP_HOME", "app_home"); 028 } 029 // Ensure a stable per-run timestamp for Logback file naming. Use 030 // the same yyyyMMddHHmmss pattern that logback's <timestamp> 031 // element uses so filenames match when possible. 032 try { 033 java.time.format.DateTimeFormatter df = java.time.format.DateTimeFormatter.ofPattern("yyyyMMddHHmmss").withZone(java.time.ZoneOffset.UTC); 034 String ts = df.format(java.time.Instant.now()); 035 System.setProperty("LOG_TS", ts); 036 } catch (Exception ex) { 037 System.setProperty("LOG_TS", String.valueOf(java.time.Instant.now().getEpochSecond())); 038 } 039 040 // Create logs directory early to avoid races when Logback opens the file 041 try { 042 java.nio.file.Path logs = java.nio.file.Paths.get(System.getProperty("APP_HOME")).resolve("logs"); 043 java.nio.file.Files.createDirectories(logs); 044 } catch (Exception ex) { 045 // ignore - best effort 046 } 047 048 // Delegate to the main application 049 com.studentgui.app.Main.main(args); 050 } 051}