@@ -21,8 +21,9 @@ public class ConfigAccess {
2121
2222 private static final int DEFAULT_OUTPUT_INTERVAL_SECONDS = 5 ;
2323 private static final boolean DEFAULT_CHAT_ENABLED = true ;
24- private static final boolean DEFAULT_CSV_ENABLED = true ;
25- private static final String DEFAULT_CSV_DIRECTORY = "performance_data" ;
24+ private static final boolean DEFAULT_EXPORT_ENABLED = true ;
25+ private static final String DEFAULT_EXPORT_DIRECTORY = "performance_data" ;
26+ private static final String DEFAULT_OUTPUT_FORMAT = "csv" ;
2627 private static final boolean DEFAULT_NETWORK_ENABLED = false ;
2728 private static final String DEFAULT_NETWORK_ENDPOINT = "http://localhost:31415" ;
2829 private static final String API_PATH = "/api/metrics" ;
@@ -42,8 +43,9 @@ public class ConfigAccess {
4243 private static class ConfigData {
4344 int outputIntervalSeconds = DEFAULT_OUTPUT_INTERVAL_SECONDS ;
4445 boolean chatEnabled = DEFAULT_CHAT_ENABLED ;
45- boolean csvEnabled = DEFAULT_CSV_ENABLED ;
46- String csvDirectory = DEFAULT_CSV_DIRECTORY ;
46+ boolean exportEnabled = DEFAULT_EXPORT_ENABLED ;
47+ String exportDirectory = DEFAULT_EXPORT_DIRECTORY ;
48+ String outputFormat = DEFAULT_OUTPUT_FORMAT ;
4749 boolean networkEnabled = DEFAULT_NETWORK_ENABLED ;
4850 String networkEndpoint = DEFAULT_NETWORK_ENDPOINT ;
4951 boolean collectFps = DEFAULT_COLLECT_FPS ;
@@ -71,11 +73,16 @@ public static void init() {
7173 if (configData .networkEndpoint == null ) {
7274 configData .networkEndpoint = DEFAULT_NETWORK_ENDPOINT ;
7375 }
76+ if (!isValidOutputFormat (configData .outputFormat )) {
77+ LOGGER .warn ("Invalid outputFormat '{}' in config, falling back to csv" , configData .outputFormat );
78+ configData .outputFormat = DEFAULT_OUTPUT_FORMAT ;
79+ save ();
80+ }
7481 LOGGER .info ("Loaded config from {}" , configFilePath );
7582 return ;
7683 }
77- } catch (IOException e ) {
78- LOGGER .error ("Failed to read config file" , e );
84+ } catch (Exception e ) {
85+ LOGGER .error ("Failed to read or parse config file, falling back to defaults " , e );
7986 }
8087 }
8188
@@ -107,12 +114,12 @@ public static boolean isChatEnabled() {
107114 return configData != null ? configData .chatEnabled : DEFAULT_CHAT_ENABLED ;
108115 }
109116
110- public static boolean isCsvEnabled () {
111- return configData != null ? configData .csvEnabled : DEFAULT_CSV_ENABLED ;
117+ public static boolean isExportEnabled () {
118+ return configData != null ? configData .exportEnabled : DEFAULT_EXPORT_ENABLED ;
112119 }
113120
114- public static String getCsvDirectory () {
115- return configData != null ? configData .csvDirectory : DEFAULT_CSV_DIRECTORY ;
121+ public static String getExportDirectory () {
122+ return configData != null ? configData .exportDirectory : DEFAULT_EXPORT_DIRECTORY ;
116123 }
117124
118125 public static boolean isNetworkEnabled () {
@@ -181,20 +188,45 @@ public static void setChatEnabled(boolean enabled) {
181188 }
182189 }
183190
184- public static void setCsvEnabled (boolean enabled ) {
191+ public static void setExportEnabled (boolean enabled ) {
185192 if (configData != null ) {
186- configData .csvEnabled = enabled ;
193+ configData .exportEnabled = enabled ;
187194 save ();
188195 }
189196 }
190197
191- public static void setCsvDirectory (String directory ) {
198+ public static void setExportDirectory (String directory ) {
192199 if (configData != null ) {
193- configData .csvDirectory = (directory != null && !directory .isBlank ()) ? directory : DEFAULT_CSV_DIRECTORY ;
200+ configData .exportDirectory = (directory != null && !directory .isBlank ()) ? directory : DEFAULT_EXPORT_DIRECTORY ;
194201 save ();
195202 }
196203 }
197-
204+
205+ public static String getOutputFormat () {
206+ return configData != null ? configData .outputFormat : DEFAULT_OUTPUT_FORMAT ;
207+ }
208+
209+ public static void setOutputFormat (String format ) {
210+ if (configData != null ) {
211+ String normalized = normalizeOutputFormat (format );
212+ configData .outputFormat = normalized != null ? normalized : DEFAULT_OUTPUT_FORMAT ;
213+ save ();
214+ }
215+ }
216+
217+ private static String normalizeOutputFormat (String format ) {
218+ if (format == null ) return null ;
219+ String lower = format .toLowerCase ().trim ();
220+ if (lower .equals ("csv" ) || lower .equals ("json" ) || lower .equals ("yaml" )) {
221+ return lower ;
222+ }
223+ return null ;
224+ }
225+
226+ public static boolean isValidOutputFormat (String format ) {
227+ return normalizeOutputFormat (format ) != null ;
228+ }
229+
198230 public static void setNetworkEnabled (boolean enabled ) {
199231 if (configData != null ) {
200232 configData .networkEnabled = enabled ;
@@ -300,14 +332,18 @@ public static boolean getDefaultChatEnabled() {
300332 return DEFAULT_CHAT_ENABLED ;
301333 }
302334
303- public static boolean getDefaultCsvEnabled () {
304- return DEFAULT_CSV_ENABLED ;
335+ public static boolean getDefaultExportEnabled () {
336+ return DEFAULT_EXPORT_ENABLED ;
305337 }
306-
307- public static String getDefaultCsvDirectory () {
308- return DEFAULT_CSV_DIRECTORY ;
338+
339+ public static String getDefaultExportDirectory () {
340+ return DEFAULT_EXPORT_DIRECTORY ;
309341 }
310-
342+
343+ public static String getDefaultOutputFormat () {
344+ return DEFAULT_OUTPUT_FORMAT ;
345+ }
346+
311347 public static boolean getDefaultNetworkEnabled () {
312348 return DEFAULT_NETWORK_ENABLED ;
313349 }
0 commit comments