Skip to content

Commit d83d35c

Browse files
authored
[automation] Add logging to script actions/conditions pre-compilation (#4893)
Signed-off-by: Florian Hotze <dev@florianhotze.com>
1 parent a625d84 commit d83d35c

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal

bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleEngineImpl.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,11 +888,17 @@ private boolean activateRule(final WrappedRule rule) {
888888
* @return true if compilation succeeded, otherwise false
889889
*/
890890
private boolean compileRule(final WrappedRule rule) {
891+
logger.debug("Compiling rule {}", rule.getUID());
891892
try {
892893
compileConditions(rule);
893894
compileActions(rule);
894895
return true;
895896
} catch (Throwable t) {
897+
if (logger.isDebugEnabled()) {
898+
logger.error("Failed to compile rule: {}", rule.getUID(), t);
899+
} else {
900+
logger.error("Failed to compile rule {}: {}", rule.getUID(), t.getMessage());
901+
}
896902
setStatus(rule.getUID(), new RuleStatusInfo(RuleStatus.UNINITIALIZED,
897903
RuleStatusDetail.HANDLER_INITIALIZING_ERROR, t.getMessage()));
898904
unregister(rule);
@@ -1215,14 +1221,15 @@ private void compileConditions(WrappedRule rule) {
12151221
if (conditions.isEmpty()) {
12161222
return;
12171223
}
1224+
logger.trace("Compiling conditions of {}", rule.getUID());
12181225
for (WrappedCondition wrappedCondition : conditions) {
12191226
final Condition condition = wrappedCondition.unwrap();
12201227
ConditionHandler cHandler = wrappedCondition.getModuleHandler();
12211228
if (cHandler != null) {
12221229
try {
12231230
cHandler.compile();
12241231
} catch (Throwable t) {
1225-
String errMessage = "Failed to pre-compile condition: " + condition.getId() + "(" + t.getMessage()
1232+
String errMessage = "Failed to compile condition: " + condition.getId() + "(" + t.getMessage()
12261233
+ ")";
12271234
throw new RuntimeException(errMessage, t);
12281235
}
@@ -1270,14 +1277,15 @@ private void compileActions(WrappedRule rule) {
12701277
if (actions.isEmpty()) {
12711278
return;
12721279
}
1280+
logger.trace("Compiling actions of rule {}", rule.getUID());
12731281
for (WrappedAction wrappedAction : actions) {
12741282
final Action action = wrappedAction.unwrap();
12751283
ActionHandler aHandler = wrappedAction.getModuleHandler();
12761284
if (aHandler != null) {
12771285
try {
12781286
aHandler.compile();
12791287
} catch (Throwable t) {
1280-
String errMessage = "Failed to pre-compile action: " + action.getId() + "(" + t.getMessage() + ")";
1288+
String errMessage = "Failed to compile action: " + action.getId() + "(" + t.getMessage() + ")";
12811289
throw new RuntimeException(errMessage, t);
12821290
}
12831291
}
@@ -1571,6 +1579,7 @@ public void onReadyMarkerRemoved(ReadyMarker readyMarker) {
15711579
* handlers weren't available when the rule was added to the rule engine.
15721580
*/
15731581
private void compileRules() {
1582+
logger.debug("Compiling all enabled rules");
15741583
getScheduledExecutor().submit(() -> {
15751584
ruleRegistry.stream() //
15761585
.filter(r -> isEnabled(r.getUID())) //

0 commit comments

Comments
 (0)