Skip to content

Commit

Permalink
Adapt for quarkus 3.3+
Browse files Browse the repository at this point in the history
  • Loading branch information
manofthepeace committed Aug 29, 2023
1 parent d0160cf commit 80eeab5
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 546 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ To use this in your application, simply add this in your pom.xml:

Note: Replace `${logger-manager.version}` with the latest version

Then browse to [http://localhost:8080/q/logging-manager-ui/](http://localhost:8080/q/logging-manager-ui/)

![logger_manager_log_screenshot](logstream.gif "Log stream Screenshot")

## OpenAPI

You can include the Logger Manager API in the OpenAPI document (and thus also Swagger UI). This needs to be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,4 @@ public class LoggingManagerConfig {
*/
@ConfigItem(defaultValue = "true")
boolean alwaysInclude;

/**
* The number of history log entries to remember.
*/
@ConfigItem(defaultValue = "50")
public int historySize;

/**
* UI configuration
*/
@ConfigItem
@ConfigDocSection
LoggingManagerUIConfig ui;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.eclipse.microprofile.openapi.models.media.Schema;
import org.eclipse.microprofile.openapi.models.parameters.Parameter;

import io.quarkus.vertx.http.runtime.logstream.LogController;
import io.quarkiverse.loggingmanager.LogController;
import io.smallrye.openapi.api.models.media.SchemaImpl;

/**
Expand Down

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions deployment/src/main/resources/dev-templates/embedded.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.deployment.configuration.ConfigurationError;
import io.quarkus.runtime.configuration.ConfigurationException;
import io.quarkus.test.QuarkusUnitTest;

public class ErroneousConfigTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setExpectedException(ConfigurationError.class)
.setExpectedException(ConfigurationException.class)
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addAsResource(new StringAsset("quarkus.logging-manager.ui.root-path=/\n"), "application.properties"));

Expand Down
Binary file removed logstream.gif
Binary file not shown.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.parameters>true</maven.compiler.parameters>
<quarkus.version>3.2.4.Final</quarkus.version>
<quarkus.version>3.3.0</quarkus.version>
<compiler-plugin.version>3.11.0</compiler-plugin.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static io.vertx.core.http.HttpMethod.GET;

import io.quarkus.vertx.http.runtime.logstream.LogController;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
Expand Down
125 changes: 125 additions & 0 deletions runtime/src/main/java/io/quarkiverse/loggingmanager/LogController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package io.quarkiverse.loggingmanager;

import static org.jboss.logmanager.Level.ALL;
import static org.jboss.logmanager.Level.CONFIG;
import static org.jboss.logmanager.Level.DEBUG;
import static org.jboss.logmanager.Level.ERROR;
import static org.jboss.logmanager.Level.FATAL;
import static org.jboss.logmanager.Level.FINE;
import static org.jboss.logmanager.Level.FINER;
import static org.jboss.logmanager.Level.FINEST;
import static org.jboss.logmanager.Level.INFO;
import static org.jboss.logmanager.Level.OFF;
import static org.jboss.logmanager.Level.SEVERE;
import static org.jboss.logmanager.Level.TRACE;
import static org.jboss.logmanager.Level.WARN;
import static org.jboss.logmanager.Level.WARNING;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.TreeMap;
import java.util.logging.Level;

import org.jboss.logmanager.LogContext;
import org.jboss.logmanager.Logger;

import io.quarkus.vertx.http.runtime.devmode.Json;

/**
* Allow controlling to the log levels
*/
public class LogController {
private static final org.jboss.logging.Logger LOG = org.jboss.logging.Logger.getLogger(LogController.class);

private LogController() {
}

public static Json.JsonArrayBuilder getLevels() {
Json.JsonArrayBuilder array = Json.array();
for (String level : LEVELS) {
array.add(level);
}
return array;
}

public static Json.JsonArrayBuilder getLoggers() {
LogContext logContext = LogContext.getLogContext();
TreeMap<String, Json.JsonObjectBuilder> loggerMap = new TreeMap<>();

Enumeration<String> loggerNames = logContext.getLoggerNames();
while (loggerNames.hasMoreElements()) {
String loggerName = loggerNames.nextElement();
Json.JsonObjectBuilder jsonObject = getLogger(loggerName);
if (jsonObject != null) {
loggerMap.put(loggerName, jsonObject);
}
}

List<Json.JsonObjectBuilder> orderedLoggers = new ArrayList<>(loggerMap.values());
Json.JsonArrayBuilder jsonArray = Json.array();
jsonArray.addAll(orderedLoggers);
return jsonArray;
}

public static Json.JsonObjectBuilder getLogger(String loggerName) {
LogContext logContext = LogContext.getLogContext();
if (loggerName != null && !loggerName.isEmpty()) {
Logger logger = logContext.getLogger(loggerName);
Json.JsonObjectBuilder jsonObject = Json.object();
jsonObject.put("name", loggerName);
jsonObject.put("effectiveLevel", getEffectiveLogLevel(logger));
jsonObject.put("configuredLevel", getConfiguredLogLevel(logger));
return jsonObject;
}
return null;
}

public static void updateLogLevel(String loggerName, String levelValue) {
LogContext logContext = LogContext.getLogContext();
Logger logger = logContext.getLogger(loggerName);
java.util.logging.Level level;
if (levelValue == null || levelValue.isBlank()) {
if (logger.getParent() != null) {
level = logger.getParent().getLevel();
} else {
throw new IllegalArgumentException("The level of the root logger cannot be set to null");
}
} else {
level = Level.parse(levelValue);
}
logger.setLevel(level);
LOG.info("Log level updated [" + loggerName + "] changed to [" + levelValue + "]");
}

private static String getConfiguredLogLevel(Logger logger) {
java.util.logging.Level level = logger.getLevel();
return level != null ? level.getName() : null;
}

private static String getEffectiveLogLevel(Logger logger) {
if (logger == null) {
return null;
}
if (logger.getLevel() != null) {
return logger.getLevel().getName();
}
return getEffectiveLogLevel(logger.getParent());
}

public static final List<String> LEVELS = List.of(
OFF.getName(),
SEVERE.getName(),
ERROR.getName(),
FATAL.getName(),
WARNING.getName(),
WARN.getName(),
INFO.getName(),
DEBUG.getName(),
TRACE.getName(),
CONFIG.getName(),
FINE.getName(),
FINER.getName(),
FINEST.getName(),
ALL.getName());
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static io.vertx.core.http.HttpMethod.GET;
import static io.vertx.core.http.HttpMethod.POST;

import io.quarkus.vertx.http.runtime.logstream.LogController;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package io.quarkiverse.loggingmanager;

import java.util.Optional;
import java.util.function.Consumer;

import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.vertx.http.runtime.logstream.LogStreamWebSocket;
import io.quarkus.vertx.http.runtime.logstream.WebSocketLogHandler;
import io.vertx.core.Handler;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;
Expand All @@ -22,25 +18,6 @@ public Handler<RoutingContext> levelHandler() {
return new LevelHandler();
}

public Handler<RoutingContext> uiHandler(String loggingManagerFinalDestination, String loggingManagerPath,
LoggingManagerRuntimeConfig runtimeConfig) {

if (runtimeConfig.enableUi) {
return new LoggingManagerStaticHandler(loggingManagerFinalDestination, loggingManagerPath);
} else {
return new LoggingManagerNotFoundHandler();
}
}

public Handler<RoutingContext> logStreamWebSocketHandler(LoggingManagerRuntimeConfig runtimeConfig,
RuntimeValue<Optional<WebSocketLogHandler>> historyHandler) {
if (runtimeConfig.enableUi) {
return new LogStreamWebSocket(historyHandler.getValue().get());
} else {
return new LoggingManagerNotFoundHandler();
}
}

public Consumer<Route> routeConsumer(Handler<RoutingContext> bodyHandler, LoggingManagerRuntimeConfig runtimeConfig) {
if (runtimeConfig.enable) {
return new Consumer<Route>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
@ConfigRoot(name = "logging-manager", phase = ConfigPhase.RUN_TIME)
public class LoggingManagerRuntimeConfig {

/**
* If Logging Manager UI should be enabled. By default, Logging Manager UI is enabled if it is included (see
* {@code always-include}).
*/
@ConfigItem(name = "ui.enable", defaultValue = "true")
boolean enableUi;

/**
* If Logging Manager should be enabled. By default, Logging Manager is enabled if it is included (see
* {@code always-include}).
Expand Down
Loading

0 comments on commit 80eeab5

Please sign in to comment.