Skip to content

Commit

Permalink
Move initial local code
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Jul 17, 2024
1 parent f356868 commit 0d68626
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
4 changes: 4 additions & 0 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkiverse.chappie</groupId>
<artifactId>quarkus-chappie</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.quarkiverse.chappie.deployment;

import io.quarkiverse.chappie.runtime.LogMessageReceiver;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;

Expand All @@ -11,4 +15,9 @@ class ChappieProcessor {
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep(onlyIf = IsDevelopment.class)
void registerBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
additionalBeans.produce(AdditionalBeanBuildItem.unremovableOf(LogMessageReceiver.class));
}
}
5 changes: 5 additions & 0 deletions runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<!-- TODO: Consider moving the mutiny logger to core ? -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.quarkiverse.chappie.runtime;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;

import org.jboss.logging.Logger;

import io.quarkus.devui.runtime.logstream.LogStreamBroadcaster;
import io.quarkus.runtime.StartupEvent;
import io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

/**
* Receive Log messages, and check if there is an exception
*/
@ApplicationScoped
public class LogMessageReceiver {
private static final Logger LOGGER = Logger.getLogger(LogMessageReceiver.class);

@Inject
LogStreamBroadcaster logStreamBroadcaster;

void onStart(@Observes StartupEvent ev) {
LOGGER.info("Chappie is listening for exceptions....");

BroadcastProcessor<JsonObject> logStream = logStreamBroadcaster.getLogStream();

logStream.subscribe().with((JsonObject item) -> {
if (item.containsKey(STACKTRACE)) {
JsonArray stacktrace = item.getJsonArray(STACKTRACE);
if (!stacktrace.isEmpty()) {
System.out.println(">>>>>>> CHAPPIE FOUND AN EXCEPTION !");
String fileName = getFileName(item);
int lineNumber = item.getInteger(SOURCE_LINE_NUMBER);

System.out.println("\t\t " + fileName + " | line " + lineNumber);
}
}
});

}

private String getFileName(JsonObject item) {
String classNameFull = item.getString(SOURCE_CLASS_NAME_FULL);
String fileName = item.getString(SOURCE_FILE_NAME);
int lastDotIndex = classNameFull.lastIndexOf('.');

if (lastDotIndex == -1) {
return fileName; // No package
}
return classNameFull.substring(0, lastDotIndex + 1) + fileName;
}

private static final String STACKTRACE = "stacktrace";
private static final String SOURCE_CLASS_NAME_FULL = "sourceClassNameFull";
private static final String SOURCE_FILE_NAME = "sourceFileName";
private static final String SOURCE_LINE_NUMBER = "sourceLineNumber";

}

0 comments on commit 0d68626

Please sign in to comment.