From 0b3e32e2dc18ce59772b9aa1afe465e7ff0bf1de Mon Sep 17 00:00:00 2001 From: Ondro Mihalyi Date: Fri, 21 Jun 2024 17:19:35 +0200 Subject: [PATCH] GH24992 Admin Logger: Moved command logger into a separate module --- .../main/asciidoc/general-administration.adoc | 7 ++- nucleus/extras/command-logger/pom.xml | 45 +++++++++++++++++++ .../commandlogger/AdminCommandLogger.java} | 9 ++-- nucleus/extras/pom.xml | 38 ++++++++++++++++ nucleus/featuresets/nucleus/pom.xml | 14 ++++++ 5 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 nucleus/extras/command-logger/pom.xml rename nucleus/{admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/commandrecorder/AdminCommandRecorder.java => extras/command-logger/src/main/java/org/glassfish/extras/commandlogger/AdminCommandLogger.java} (96%) create mode 100644 nucleus/extras/pom.xml diff --git a/docs/administration-guide/src/main/asciidoc/general-administration.adoc b/docs/administration-guide/src/main/asciidoc/general-administration.adoc index 79d837eccdd..da88f119838 100644 --- a/docs/administration-guide/src/main/asciidoc/general-administration.adoc +++ b/docs/administration-guide/src/main/asciidoc/general-administration.adoc @@ -3164,7 +3164,7 @@ specify the type through the `-H` option as follows: It's possible to log admin commands executed either using the asadmin CLI, Admin Console, or the REST interface. -To enable this logging, set the system property `glassfish.commandrecorder.logmode` on the DAS server to one of the following values: +To enable this logging, set the system property `glassfish.commandlogger.logmode` on the DAS server to one of the following values: * `ALL_COMMANDS` - will log all commands * `WRITE_COMMANDS` - will log all commands that modify server configuration @@ -3172,11 +3172,10 @@ To enable this logging, set the system property `glassfish.commandrecorder.logmo * `READ_WRITE_COMMANDS` - will log all commands that modify server configuration or return info about the configuration * `NO_COMMAND` - do not log any command, this is the default value if the property not specified -The log message will contain: +The log message will be logged using `org.glassfish.extras.commandlogger.AdminCommandLogger` logger with `INFO` level, and will contain: * name of the admin user that executed the command * name of the command * arguments to the command -The name and arguments can be copied and pasted to the asadmin CLI to repeat running the same command from the command line. - +The name and arguments can be copied and pasted to the asadmin CLI to repeat running the same command from the command line. \ No newline at end of file diff --git a/nucleus/extras/command-logger/pom.xml b/nucleus/extras/command-logger/pom.xml new file mode 100644 index 00000000000..1c305b45b21 --- /dev/null +++ b/nucleus/extras/command-logger/pom.xml @@ -0,0 +1,45 @@ + + + + + 4.0.0 + + + org.glassfish.main.extras + nucleus-extras + 7.0.16-SNAPSHOT + + + command-logger + glassfish-jar + + Admin Command Logger + + + + org.glassfish.hk2 + hk2 + + + org.glassfish.main.common + internal-api + ${project.version} + + + diff --git a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/commandrecorder/AdminCommandRecorder.java b/nucleus/extras/command-logger/src/main/java/org/glassfish/extras/commandlogger/AdminCommandLogger.java similarity index 96% rename from nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/commandrecorder/AdminCommandRecorder.java rename to nucleus/extras/command-logger/src/main/java/org/glassfish/extras/commandlogger/AdminCommandLogger.java index e1a11065686..36ab4b6370b 100644 --- a/nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/commandrecorder/AdminCommandRecorder.java +++ b/nucleus/extras/command-logger/src/main/java/org/glassfish/extras/commandlogger/AdminCommandLogger.java @@ -13,7 +13,7 @@ * * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 */ -package org.glassfish.admin.rest.commandrecorder; +package org.glassfish.extras.commandlogger; import static java.lang.System.Logger.Level.INFO; import static java.lang.System.Logger.Level.WARNING; @@ -41,9 +41,9 @@ @Service @RunLevel(value = StartupRunLevel.VAL, mode = RunLevel.RUNLEVEL_MODE_NON_VALIDATING) @MessageReceiver({CommandInvokedEvent.class}) -public class AdminCommandRecorder { +public class AdminCommandLogger { - private static final System.Logger logger = System.getLogger(AdminCommandRecorder.class.getName()); + private static final System.Logger logger = System.getLogger(AdminCommandLogger.class.getName()); public void receiveCommandInvokedEvent(@SubscribeTo CommandInvokedEvent event) { logCommand(event.getCommandName(), event.getParameters(), event.getSubject()); @@ -64,7 +64,6 @@ public void logCommand(String commandName, ParameterMap parameters, Subject subj private String constructCommandLine(String commandName, ParameterMap parameters) { final String DEFAULT_PARAM_KEY = "DEFAULT"; - final StringBuilder commandLineBuilder = new StringBuilder(); final Stream namedParamsStream = parameters.entrySet().stream() .filter(param -> !"userpassword".equals(param.getKey())) .filter(param -> !DEFAULT_PARAM_KEY.equals(param.getKey())) @@ -82,7 +81,7 @@ private static enum LogMode { ALL_COMMANDS, INTERNAL_COMMANDS, WRITE_COMMANDS, READ_WRITE_COMMANDS, NO_COMMAND; public static final LogMode DEFAULT = LogMode.WRITE_COMMANDS; - public static final String PROPERTY_NAME = "glassfish.commandrecorder.logmode"; + public static final String PROPERTY_NAME = "glassfish.commandlogger.logmode"; public static LogMode get() { final String logModeValue = TranslatedConfigView.expandValue("${" + LogMode.PROPERTY_NAME + "}"); diff --git a/nucleus/extras/pom.xml b/nucleus/extras/pom.xml new file mode 100644 index 00000000000..222423accb4 --- /dev/null +++ b/nucleus/extras/pom.xml @@ -0,0 +1,38 @@ + + + + + 4.0.0 + + + org.glassfish.main + glassfish-nucleus-parent + 7.0.16-SNAPSHOT + + + org.glassfish.main.extras + nucleus-extras + pom + + Nucleus extras + + + command-logger + + diff --git a/nucleus/featuresets/nucleus/pom.xml b/nucleus/featuresets/nucleus/pom.xml index 0ea3a3c71fc..60089797fba 100644 --- a/nucleus/featuresets/nucleus/pom.xml +++ b/nucleus/featuresets/nucleus/pom.xml @@ -288,5 +288,19 @@ + + + + org.glassfish.main.extras + command-logger + ${project.version} + + + * + * + + + +