Skip to content

Commit 6202ac9

Browse files
committed
refactor: logging is consistent and respectfully to console output
1 parent 79b7fe0 commit 6202ac9

25 files changed

+105
-99
lines changed

app/queue-server/src/main/java/org/phoebus/applications/queueserver/QueueServerApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@SuppressWarnings("nls")
1717
public final class QueueServerApp implements AppResourceDescriptor {
1818

19-
public static final Logger LOGGER = Logger.getLogger(QueueServerApp.class.getPackageName());
19+
public static final Logger logger = Logger.getLogger(QueueServerApp.class.getPackageName());
2020

2121
public static final String NAME = "queue-server";
2222
private static final String DISPLAY_NAME = "Queue Server";

app/queue-server/src/main/java/org/phoebus/applications/queueserver/client/RunEngineHttpClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static RunEngineHttpClient get() {
4848
private final String base;
4949
private final String apiKey;
5050
private final RateLimiter limiter;
51-
private static final Logger LOG = HttpSupport.LOG;
51+
private static final Logger logger = HttpSupport.logger;
5252

5353
private RunEngineHttpClient(String baseUrl, String apiKey, double permitsPerSecond) {
5454
this.http = HttpClient.newBuilder()
@@ -118,14 +118,14 @@ private <T> T executeWithRetry(HttpRequest req, ApiEndpoint ep,
118118
limiter.acquire();
119119
long t0 = System.nanoTime();
120120
try {
121-
LOG.log(Level.FINEST, ep + " attempt " + attempt);
121+
logger.log(Level.FINEST, ep + " attempt " + attempt);
122122
HttpResponse<String> rsp = http.send(req, HttpResponse.BodyHandlers.ofString());
123-
LOG.log(Level.FINEST, ep + " " + rsp.statusCode() + " " + HttpSupport.elapsed(t0) + " ms");
123+
logger.log(Level.FINEST, ep + " " + rsp.statusCode() + " " + HttpSupport.elapsed(t0) + " ms");
124124
check(rsp, ep);
125125
return reader.apply(rsp);
126126
} catch (java.io.IOException ex) {
127127
if (!HttpSupport.isRetryable(req) || attempt >= HttpSupport.MAX_RETRIES) throw ex;
128-
LOG.log(Level.WARNING, ep + " transport error (" + ex.getClass().getSimpleName() +
128+
logger.log(Level.WARNING, ep + " transport error (" + ex.getClass().getSimpleName() +
129129
"), retry in " + back + " ms (attempt " + attempt + ")");
130130
Thread.sleep(back);
131131
back = Math.round(back * HttpSupport.BACKOFF_MULTIPLIER);

app/queue-server/src/main/java/org/phoebus/applications/queueserver/client/RunEngineService.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
public final class RunEngineService {
3030

3131
private final RunEngineHttpClient http = RunEngineHttpClient.get();
32-
private static final Logger LOG = Logger.getLogger(RunEngineService.class.getName());
32+
private static final Logger logger = Logger.getLogger(RunEngineService.class.getPackageName());
3333

3434
/* ---- Ping & status --------------------------------------------------- */
3535

3636
public Envelope<?> ping() throws Exception { return http.call(ApiEndpoint.PING, NoBody.INSTANCE); }
3737
public StatusResponse status() throws Exception {
38-
LOG.log(Level.FINEST, "Fetching status");
38+
logger.log(Level.FINEST, "Fetching status");
3939
return http.send(ApiEndpoint.STATUS, NoBody.INSTANCE, StatusResponse.class);
4040
}
4141
public Envelope<?> configGet() throws Exception { return http.call(ApiEndpoint.CONFIG_GET, NoBody.INSTANCE); }
@@ -168,7 +168,7 @@ public Envelope<?> queueItemUpdate(QueueItem item) throws Exception {
168168
/* ───────── Console monitor ───────── */
169169

170170
public InputStream streamConsoleOutput() throws Exception {
171-
LOG.info("Opening console output stream");
171+
logger.log(Level.FINE, "Opening console output stream");
172172
HttpRequest req = HttpRequest.newBuilder()
173173
.uri(URI.create(http.getBaseUrl() + ApiEndpoint.STREAM_CONSOLE_OUTPUT.endpoint().path()))
174174
.header("Authorization", "ApiKey " + http.getApiKey())
@@ -178,10 +178,10 @@ public InputStream streamConsoleOutput() throws Exception {
178178
HttpResponse<InputStream> rsp =
179179
http.httpClient().send(req, HttpResponse.BodyHandlers.ofInputStream());
180180
if (rsp.statusCode() < 200 || rsp.statusCode() >= 300) {
181-
LOG.log(Level.WARNING, "Console stream failed with HTTP " + rsp.statusCode());
181+
logger.log(Level.WARNING, "Console stream failed with HTTP " + rsp.statusCode());
182182
throw new IOException("console stream - HTTP " + rsp.statusCode());
183183
}
184-
LOG.info("Console output stream opened successfully");
184+
logger.log(Level.FINE, "Console output stream opened successfully");
185185
return rsp.body();
186186
}
187187

@@ -251,7 +251,7 @@ public Envelope<?> rePause(String option) throws Exception {
251251

252252
public Envelope<?> plansAllowed() throws Exception { return http.call(ApiEndpoint.PLANS_ALLOWED, NoBody.INSTANCE); }
253253
public Map<String, Object> plansAllowedRaw() throws Exception {
254-
LOG.log(Level.FINE, "Fetching plans allowed (raw)");
254+
logger.log(Level.FINE, "Fetching plans allowed (raw)");
255255
return http.send(ApiEndpoint.PLANS_ALLOWED, NoBody.INSTANCE);
256256
}
257257
public Envelope<?> devicesAllowed() throws Exception { return http.call(ApiEndpoint.DEVICES_ALLOWED, NoBody.INSTANCE); }

app/queue-server/src/main/java/org/phoebus/applications/queueserver/controller/ApplicationController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import java.net.URL;
1313
import java.util.ResourceBundle;
14+
import java.util.logging.Level;
1415
import java.util.logging.Logger;
1516

1617
public final class ApplicationController implements Initializable {
@@ -19,18 +20,18 @@ public final class ApplicationController implements Initializable {
1920
@FXML private Tab editAndControlQueueTab;
2021
@FXML private TabPane tabPane;
2122

22-
private static final Logger LOG = Logger.getLogger(ApplicationController.class.getName());
23+
private static final Logger logger = Logger.getLogger(ApplicationController.class.getPackageName());
2324

2425
@Override public void initialize(URL url, ResourceBundle rb) {
25-
LOG.info("Initializing ApplicationController");
26+
logger.log(Level.FINE, "Initializing ApplicationController");
2627
monitorQueueTab.setContent(ViewFactory.MONITOR_QUEUE.get());
2728
editAndControlQueueTab.setContent(ViewFactory.EDIT_AND_CONTROL_QUEUE.get());
2829

2930
// Disable focus traversal on all components
3031
disableFocusTraversal(monitorQueueTab.getContent());
3132
disableFocusTraversal(editAndControlQueueTab.getContent());
3233

33-
LOG.info("ApplicationController initialization complete");
34+
logger.log(Level.FINE, "ApplicationController initialization complete");
3435
}
3536

3637
/**

app/queue-server/src/main/java/org/phoebus/applications/queueserver/controller/EditAndControlQueueController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public class EditAndControlQueueController implements Initializable {
1818
@FXML private AnchorPane planQueueContainer;
1919
@FXML private AnchorPane planHistoryContainer;
2020

21-
private static final Logger LOG = Logger.getLogger(EditAndControlQueueController.class.getName());
21+
private static final Logger logger = Logger.getLogger(EditAndControlQueueController.class.getPackageName());
2222

2323
@Override
2424
public void initialize(URL url, ResourceBundle resourceBundle) {
25-
LOG.info("Initializing EditAndControlQueueController");
25+
logger.log(Level.FINE, "Initializing EditAndControlQueueController");
2626
loadInto(runningPlanContainer, "/org/phoebus/applications/queueserver/view/ReRunningPlan.fxml", new ReRunningPlanController(false));
2727
loadInto(planQueueContainer, "/org/phoebus/applications/queueserver/view/RePlanQueue.fxml", new RePlanQueueController(false));
2828
loadInto(planHistoryContainer, "/org/phoebus/applications/queueserver/view/RePlanHistory.fxml", new RePlanHistoryController(false));
@@ -40,7 +40,7 @@ private void loadInto(AnchorPane container, String fxml, Object controller) {
4040
AnchorPane.setLeftAnchor(view, 0.0);
4141
AnchorPane.setRightAnchor(view, 0.0);
4242
} catch (IOException e) {
43-
LOG.log(Level.SEVERE, "Failed to load FXML: " + fxml, e);
43+
logger.log(Level.SEVERE, "Failed to load FXML: " + fxml, e);
4444
}
4545
}
4646

app/queue-server/src/main/java/org/phoebus/applications/queueserver/controller/MonitorQueueController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class MonitorQueueController implements Initializable {
2525
@FXML private VBox stack;
2626

2727
private final Map<TitledPane, Double> savedHeights = new HashMap<>();
28-
private static final Logger LOG = Logger.getLogger(MonitorQueueController.class.getName());
28+
private static final Logger logger = Logger.getLogger(MonitorQueueController.class.getPackageName());
2929

3030
private static final String BAR_NORMAL =
3131
"-fx-background-color: linear-gradient(to bottom, derive(-fx-base,15%) 0%, derive(-fx-base,-5%) 100%);" +
@@ -34,7 +34,7 @@ public class MonitorQueueController implements Initializable {
3434

3535
@Override
3636
public void initialize(URL url, ResourceBundle resourceBundle) {
37-
LOG.info("Initializing MonitorQueueController");
37+
logger.log(Level.FINE, "Initializing MonitorQueueController");
3838
loadInto(runningPlanContainer, "/org/phoebus/applications/queueserver/view/ReRunningPlan.fxml", new ReRunningPlanController(true));
3939
loadInto(planQueueContainer, "/org/phoebus/applications/queueserver/view/RePlanQueue.fxml", new RePlanQueueController(true));
4040
loadInto(planHistoryContainer, "/org/phoebus/applications/queueserver/view/RePlanHistory.fxml", new RePlanHistoryController(true));
@@ -76,7 +76,7 @@ private void loadInto(AnchorPane container, String fxml, Object controller) {
7676
AnchorPane.setLeftAnchor(view, 0.0);
7777
AnchorPane.setRightAnchor(view, 0.0);
7878
} catch (IOException e) {
79-
LOG.log(Level.SEVERE, "Failed to load FXML: " + fxml, e);
79+
logger.log(Level.SEVERE, "Failed to load FXML: " + fxml, e);
8080
}
8181
}
8282

app/queue-server/src/main/java/org/phoebus/applications/queueserver/controller/ReEnvironmentControlsController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.net.URL;
1515
import java.util.Map;
1616
import java.util.ResourceBundle;
17+
import java.util.logging.Level;
1718
import java.util.logging.Logger;
1819

1920
public final class ReEnvironmentControlsController implements Initializable {
@@ -23,7 +24,7 @@ public final class ReEnvironmentControlsController implements Initializable {
2324
@FXML private Button destroyBtn;
2425

2526
private final RunEngineService svc = new RunEngineService();
26-
private final Logger LOG = Logger.getLogger(getClass().getName());
27+
private static final Logger logger = Logger.getLogger(ReEnvironmentControlsController.class.getPackageName());
2728

2829
@Override public void initialize(URL url, ResourceBundle rb) {
2930
StatusBus.latest().addListener(this::onStatus);
@@ -57,12 +58,12 @@ private void refreshButtons(Object statusObj) {
5758

5859
@FXML private void open() {
5960
try { svc.environmentOpen(); }
60-
catch (Exception ex) { LOG.warning("environmentOpen: " + ex); }
61+
catch (Exception ex) { logger.log(Level.WARNING, "environmentOpen: " + ex); }
6162
}
6263

6364
@FXML private void close() {
6465
try { svc.environmentClose(); }
65-
catch (Exception ex) { LOG.warning("environmentClose: " + ex); }
66+
catch (Exception ex) { logger.log(Level.WARNING, "environmentClose: " + ex); }
6667
}
6768

6869
@FXML private void destroy() {
@@ -75,9 +76,9 @@ private void refreshButtons(Object statusObj) {
7576
if (response == ButtonType.OK) {
7677
try {
7778
svc.environmentDestroy();
78-
LOG.info("Environment destroyed successfully");
79+
logger.log(Level.FINE, "Environment destroyed successfully");
7980
} catch (Exception ex) {
80-
LOG.warning("environmentDestroy: " + ex);
81+
logger.log(Level.WARNING, "environmentDestroy: " + ex);
8182
}
8283
}
8384
});

app/queue-server/src/main/java/org/phoebus/applications/queueserver/controller/ReExecutionControlsController.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.net.URL;
1313
import java.util.Map;
1414
import java.util.ResourceBundle;
15+
import java.util.logging.Level;
1516
import java.util.logging.Logger;
1617

1718
public final class ReExecutionControlsController implements Initializable {
@@ -20,7 +21,7 @@ public final class ReExecutionControlsController implements Initializable {
2021
stopBtn, abortBtn, haltBtn;
2122

2223
private final RunEngineService svc = new RunEngineService();
23-
private final Logger LOG = Logger.getLogger(getClass().getName());
24+
private static final Logger logger = Logger.getLogger(ReExecutionControlsController.class.getPackageName());
2425

2526
@Override public void initialize(URL url, ResourceBundle rb) {
2627

@@ -109,6 +110,6 @@ else if (statusObj instanceof Map<?,?> m) {
109110

110111
private void call(String label, Runnable r) {
111112
try { r.run(); }
112-
catch (Exception ex) { LOG.warning(label + ": " + ex); }
113+
catch (Exception ex) { logger.log(Level.WARNING, label + ": " + ex); }
113114
}
114115
}

app/queue-server/src/main/java/org/phoebus/applications/queueserver/controller/ReManagerConnectionController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public final class ReManagerConnectionController {
2121
private final RunEngineService svc = new RunEngineService();
2222
private ScheduledFuture<?> pollTask;
2323
private static final int PERIOD_SEC = 1;
24-
private static final Logger LOG = Logger.getLogger(ReManagerConnectionController.class.getName());
24+
private static final Logger logger = Logger.getLogger(ReManagerConnectionController.class.getPackageName());
2525

2626
@FXML private void connect() { startPolling(); }
2727
@FXML private void disconnect() { stopPolling(); }
2828

2929
private void startPolling() {
3030
if (pollTask != null && !pollTask.isDone()) return; // already running
31-
LOG.info("Starting connection polling every " + PERIOD_SEC + " seconds");
31+
logger.log(Level.FINE, "Starting connection polling every " + PERIOD_SEC + " seconds");
3232
showPending(); // UI while waiting
3333

3434
updateWidgets(queryStatusOnce());
@@ -42,13 +42,13 @@ private StatusResponse queryStatusOnce() {
4242
try {
4343
return svc.status();
4444
} catch (Exception ex) {
45-
LOG.log(Level.FINE, "Status query failed: " + ex.getMessage());
45+
logger.log(Level.FINE, "Status query failed: " + ex.getMessage());
4646
return null;
4747
}
4848
}
4949

5050
private void stopPolling() {
51-
LOG.info("Stopping connection polling");
51+
logger.log(Level.FINE, "Stopping connection polling");
5252
if (pollTask != null) pollTask.cancel(true);
5353
pollTask = null;
5454
StatusBus.push(null);
@@ -74,7 +74,7 @@ private void showOnline() {
7474
private void updateWidgets(StatusResponse s) {
7575
StatusBus.push((s));
7676
if (s != null) {
77-
LOG.log(Level.FINEST, "Status update: manager_state=" + s.managerState());
77+
logger.log(Level.FINEST, "Status update: manager_state=" + s.managerState());
7878
showOnline();
7979
} else {
8080
showPending(); // keep polling; user may Disconnect

app/queue-server/src/main/java/org/phoebus/applications/queueserver/controller/RePlanEditorController.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class RePlanEditorController implements Initializable {
5151
@FXML private TableColumn<ParameterRow, String> valueCol;
5252

5353
private final RunEngineService svc = new RunEngineService();
54-
private static final Logger LOG = Logger.getLogger(RePlanEditorController.class.getName());
54+
private static final Logger logger = Logger.getLogger(RePlanEditorController.class.getPackageName());
5555
private final ObservableList<ParameterRow> parameterRows = FXCollections.observableArrayList();
5656
private final Map<String, Map<String, Object>> allowedPlans = new HashMap<>();
5757
private final Map<String, Map<String, Object>> allowedInstructions = new HashMap<>();
@@ -389,10 +389,10 @@ private void loadAllowedPlansAndInstructions() {
389389
allowedPlans.put(planName, planInfo);
390390
}
391391
} else {
392-
LOG.log(Level.WARNING, "No 'plans_allowed' key in response. Keys: " + responseMap.keySet());
392+
logger.log(Level.WARNING, "No 'plans_allowed' key in response. Keys: " + responseMap.keySet());
393393
}
394394
} else {
395-
LOG.log(Level.WARNING, "Plans response failed. Response: " + responseMap);
395+
logger.log(Level.WARNING, "Plans response failed. Response: " + responseMap);
396396
}
397397

398398
allowedInstructions.clear();
@@ -407,7 +407,7 @@ private void loadAllowedPlansAndInstructions() {
407407
});
408408

409409
} catch (Exception e) {
410-
LOG.log(Level.WARNING, "Failed to load plans", e);
410+
logger.log(Level.WARNING, "Failed to load plans", e);
411411
}
412412
}).start();
413413
}
@@ -711,7 +711,7 @@ private void addItemToQueue() {
711711
}
712712
});
713713
} catch (Exception e) {
714-
LOG.log(Level.WARNING, "Failed to add item to queue", e);
714+
logger.log(Level.WARNING, "Failed to add item to queue", e);
715715
Platform.runLater(() -> {
716716
String errorMsg = e.getMessage();
717717
if (errorMsg == null || errorMsg.isEmpty()) {
@@ -723,7 +723,7 @@ private void addItemToQueue() {
723723
}).start();
724724

725725
} catch (Exception e) {
726-
LOG.log(Level.SEVERE, "Failed to add item to queue", e);
726+
logger.log(Level.SEVERE, "Failed to add item to queue", e);
727727
Platform.runLater(() -> {
728728
showValidationError("Failed to add item: " + e.getMessage());
729729
});
@@ -790,7 +790,7 @@ private void saveItem() {
790790
}
791791
});
792792
} catch (Exception e) {
793-
LOG.log(Level.WARNING, "Failed to save item", e);
793+
logger.log(Level.WARNING, "Failed to save item", e);
794794
Platform.runLater(() -> {
795795
String errorMsg = e.getMessage();
796796
if (errorMsg == null || errorMsg.isEmpty()) {
@@ -802,7 +802,7 @@ private void saveItem() {
802802
}).start();
803803

804804
} catch (Exception e) {
805-
LOG.log(Level.SEVERE, "Failed to save item", e);
805+
logger.log(Level.SEVERE, "Failed to save item", e);
806806
Platform.runLater(() -> {
807807
showValidationError("Failed to save item: " + e.getMessage());
808808
});
@@ -966,7 +966,7 @@ private void processBatchFile(String filePath, String fileType) {
966966
}
967967

968968
} catch (Exception e) {
969-
LOG.log(Level.WARNING, "Batch file processing error", e);
969+
logger.log(Level.WARNING, "Batch file processing error", e);
970970
Platform.runLater(() -> {
971971
Alert alert = new Alert(Alert.AlertType.ERROR);
972972
alert.setTitle("Error");

0 commit comments

Comments
 (0)