mattisonchao commented on a change in pull request #14200:
URL: https://github.com/apache/pulsar/pull/14200#discussion_r804274556
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
##########
@@ -43,6 +43,10 @@
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+
Review comment:
```suggestion
```
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
##########
@@ -437,5 +441,67 @@ private void doShutDownBrokerGracefully(int
maxConcurrentUnloadPerSec,
pulsar().getBrokerService().unloadNamespaceBundlesGracefully(maxConcurrentUnloadPerSec,
forcedTerminateTopic);
pulsar().closeAsync();
}
+
+ /**
+ * dynamically update log4j2 logger level in runtime.
+ *
+ * @param targetClassName
+ * @param targetLevel
+ */
+ private synchronized void updateLoggerLevel(String targetClassName, String
targetLevel) {
+ try {
+ String className;
+ if (targetClassName.trim().equalsIgnoreCase("ROOT")) {
+ className = LogManager.ROOT_LOGGER_NAME;
+ } else {
+ try {
+ className = targetClassName.trim();
+ // Check if class name valid
+ Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ // Logger not found
+ throw new RestException(Status.NOT_FOUND, "Logger not
found.");
+ }
+ }
+
+ Level level;
+ try {
+ level = Level.valueOf(targetLevel);
+ } catch (IllegalArgumentException e) {
+ // Level not found
+ throw new RestException(Status.PRECONDITION_FAILED, "Invalid
logger level.");
+ }
+
+ if (level != null) {
+ Level originLevel = LogManager.getLogger(className).getLevel();
+ Configurator.setAllLevels(className, level);
+ LOG.info("[{}] Successfully update log level for className: {}
({} -> {}.)", clientAppId(), className, originLevel, level);
+ } else {
+ LOG.error("[{}] Failed to update log level for {}",
clientAppId(), className);
+ }
+ } catch (RestException re) {
+ LOG.error("[{}] Failed to update log level for className: {},
targetLevel: {} due to rest exception.", clientAppId(), targetClassName,
targetLevel);
+ throw re;
+ } catch (Exception ie) {
+ LOG.error("[{}] Failed to update log level for {} to {} due to
internal error.",
+ clientAppId(), targetClassName, targetLevel);
+ throw new RestException(ie);
+ }
+ }
+
+ @POST
+ @Path("/log4j/{classname}/{level}")
+ @ApiOperation(value =
+ "update dynamic log4j2 logger level in runtime by classname. This
operation requires Pulsar super-user privileges.")
+ @ApiResponses(value = {
+ @ApiResponse(code = 204, message = "class logger level updated
successfully"),
+ @ApiResponse(code = 403, message = "You don't have admin permission to
update log4j2 logger level."),
+ @ApiResponse(code = 500, message = "Internal server error")})
+ public void updateLoggerLevelDynamically(@PathParam("classname") String
classname,
+ @PathParam("level") String level)
throws Exception {
Review comment:
```suggestion
@PathParam("level") String
level) {
```
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/BrokersBase.java
##########
@@ -437,5 +441,67 @@ private void doShutDownBrokerGracefully(int
maxConcurrentUnloadPerSec,
pulsar().getBrokerService().unloadNamespaceBundlesGracefully(maxConcurrentUnloadPerSec,
forcedTerminateTopic);
pulsar().closeAsync();
}
+
+ /**
+ * dynamically update log4j2 logger level in runtime.
+ *
+ * @param targetClassName
+ * @param targetLevel
+ */
+ private synchronized void updateLoggerLevel(String targetClassName, String
targetLevel) {
Review comment:
Why synchronized?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]