Skip to content

Commit f084ad5

Browse files
authored
fix: improve logging (#62)
1 parent 3a4d2d5 commit f084ad5

File tree

7 files changed

+25
-33
lines changed

7 files changed

+25
-33
lines changed

src/main/java/at/ac/uibk/dps/cirrina/cirrina/Cirrina.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ class Cirrina {
8686
}
8787
}
8888
} catch (e: EnvironmentVariableError) {
89-
logger.error("There is an error in the current configuration, because: '${e.message}'", e)
89+
logger.error("There is an error in the current configuration", e)
9090
} catch (e: Exception) {
91-
logger.error("There was an unknown in the runtime execution, because: '${e.message}'", e)
91+
logger.error("There was an unknown in the runtime execution", e)
9292
}
9393
}
9494

src/main/java/at/ac/uibk/dps/cirrina/execution/command/ActionAssignCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public List<ActionCommand> execute() throws UnsupportedOperationException {
6565
)
6666
);
6767
} catch (IOException e) {
68-
logger.error("Data assignment failed: {}", e.getMessage());
68+
logger.error("Data assignment failed", e);
6969
}
7070

7171
return commands;

src/main/java/at/ac/uibk/dps/cirrina/execution/command/ActionCreateCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public List<ActionCommand> execute() throws UnsupportedOperationException {
6969
gauges.attributesForData("create", !isPersistent ? "local" : "persistent", size)
7070
);
7171
} catch (Exception e) {
72-
logger.error("Data creation failed: {}", e.getMessage());
72+
logger.error("Data creation failed", e);
7373
}
7474

7575
return commands;

src/main/java/at/ac/uibk/dps/cirrina/execution/command/ActionInvokeCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ public List<ActionCommand> execute() throws UnsupportedOperationException {
6464
.invoke(input, executionContext.scope().getId())
6565
.exceptionally(e -> {
6666
logger.error(
67-
"Service invocation failed for service '{}': {}",
67+
"Service invocation failed for service '{}'",
6868
serviceImplementation.getInformationString(),
69-
e.getMessage(),
7069
e
7170
);
7271
return null;
@@ -143,9 +142,8 @@ private void assignServiceOutput(List<ContextVariable> output, Extent extent) {
143142
extent.trySet(outputReference.getReference(), outputVariable.value());
144143
} catch (Exception e) {
145144
logger.error(
146-
"Failed to assign service output to variable '{}': {}",
145+
"Failed to assign service output to variable '{}'",
147146
outputReference.getReference(),
148-
e.getMessage(),
149147
e
150148
);
151149
}

src/main/java/at/ac/uibk/dps/cirrina/execution/command/ActionMatchCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public List<ActionCommand> execute() throws UnsupportedOperationException {
4040
}
4141
}
4242
} catch (UnsupportedOperationException e) {
43-
logger.error("Could not execute match action: {}", e.getMessage());
43+
logger.error("Could not execute match action", e);
4444
}
4545

4646
return commands;

src/main/java/at/ac/uibk/dps/cirrina/execution/object/context/NatsContext.kt

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,45 +56,34 @@ class NatsContext(
5656
keyValue = getOrCreateBucket(conn)
5757
connection = conn
5858
} catch (e: Exception) {
59-
logger.error("Failed to setup bucket", e)
59+
logger.error("Failed to setup the persistent context bucket", e)
6060
} finally {
6161
connectedLatch.countDown()
6262
}
6363
}
64-
logger.info("(Re)connected to NATS for persistent context")
64+
logger.info("(Re)connected to the NATS server for persistent context")
6565
}
6666

6767
ConnectionListener.Events.DISCONNECTED -> {
6868
synchronized(lock) {
6969
connection = null
7070
keyValue = null
7171
}
72-
logger.warn("NATS disconnected for persistent context")
72+
logger.warn("Disconnected from the NATS server for persistent context")
7373
}
7474

7575
else -> {}
7676
}
7777
}
7878
}
7979
)
80-
.errorListener(
81-
object : ErrorListener {
82-
override fun errorOccurred(conn: Connection?, error: String?) {
83-
logger.error("NATS error: $error")
84-
}
85-
86-
override fun exceptionOccurred(conn: Connection?, e: Exception?) {
87-
logger.error("NATS exception", e)
88-
}
89-
}
90-
)
9180
.build()
9281

9382
try {
9483
Nats.connectAsynchronously(options, true)
95-
} catch (e: InterruptedException) {
84+
} catch (_: InterruptedException) {
9685
Thread.currentThread().interrupt()
97-
logger.error("Interrupted while initiating NATS connection, will never connect", e)
86+
logger.error("Interrupted while initiating NATS connection, will never connect")
9887
}
9988
}
10089

@@ -103,7 +92,7 @@ class NatsContext(
10392
runCatching {
10493
conn.keyValueManagement().apply {
10594
if (!bucketNames.contains(bucketName)) {
106-
logger.warn("Bucket '$bucketName' does not exist, creating it")
95+
logger.warn("Persistent bucket '$bucketName' does not exist, creating it")
10796
create(KeyValueConfiguration.Builder().name(bucketName).build())
10897
}
10998
}
@@ -128,7 +117,8 @@ class NatsContext(
128117
override fun get(name: String): Any =
129118
synchronized(lock) {
130119
runCatching {
131-
val kv = keyValue ?: throw IOException("Not connected to NATS for persistent context")
120+
val kv =
121+
keyValue ?: throw IOException("Not connected to the NATS server for persistent context")
132122
if (!kv.keys().contains(name)) {
133123
throw IOException("A variable with the name '$name' does not exist")
134124
}
@@ -151,7 +141,8 @@ class NatsContext(
151141
override fun create(name: String, value: Any?): Int =
152142
synchronized(lock) {
153143
runCatching {
154-
val kv = keyValue ?: throw IOException("Not connected to NATS for persistent context")
144+
val kv =
145+
keyValue ?: throw IOException("Not connected to the NATS server for persistent context")
155146
if (kv.keys().contains(name)) {
156147
throw IOException("A variable with the name '$name' already exists")
157148
}
@@ -175,7 +166,8 @@ class NatsContext(
175166
override fun assign(name: String, value: Any?): Int =
176167
synchronized(lock) {
177168
runCatching {
178-
val kv = keyValue ?: throw IOException("Not connected to NATS for persistent context")
169+
val kv =
170+
keyValue ?: throw IOException("Not connected to the NATS server for persistent context")
179171
if (!kv.keys().contains(name)) {
180172
throw IOException("A variable with the name '$name' does not exist")
181173
}
@@ -197,7 +189,8 @@ class NatsContext(
197189
override fun delete(name: String) {
198190
synchronized(lock) {
199191
runCatching {
200-
val kv = keyValue ?: throw IOException("Not connected to NATS for persistent context")
192+
val kv =
193+
keyValue ?: throw IOException("Not connected to the NATS server for persistent context")
201194
if (!kv.keys().contains(name)) {
202195
throw IOException("A variable with the name '$name' does not exist")
203196
}
@@ -212,7 +205,8 @@ class NatsContext(
212205
override fun getAll(): List<ContextVariable> =
213206
synchronized(lock) {
214207
runCatching {
215-
val kv = keyValue ?: throw IOException("Not connected to NATS for persistent context")
208+
val kv =
209+
keyValue ?: throw IOException("Not connected to the NATS server for persistent context")
216210
kv.keys().map { key ->
217211
val entry = kv.get(key)
218212
ContextVariable(entry.key, entry.value)
@@ -231,7 +225,7 @@ class NatsContext(
231225
conn.close()
232226
}
233227
}
234-
.onFailure { e -> throw IOException("Failed to close NATS persistent context", e) }
228+
.onFailure { e -> throw IOException("Failed to close the NATS persistent context", e) }
235229
}
236230
}
237231

src/main/java/at/ac/uibk/dps/cirrina/execution/object/statemachine/StateMachine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ public void run() {
780780

781781
Thread.currentThread().interrupt();
782782
} catch (Exception e) {
783-
logger.error("%s received a fatal error".formatted(stateMachineId.toString()), e);
783+
logger.error("{} received a fatal error", stateMachineId.toString(), e);
784784
}
785785

786786
logger.info("{} has stopped", stateMachineId.toString());

0 commit comments

Comments
 (0)