From 6f0363258ee56f34e26adabcdb7624abde80fb24 Mon Sep 17 00:00:00 2001 From: sollecitom Date: Wed, 30 May 2018 13:28:05 +0100 Subject: [PATCH] [CORDA-1552]: Log commands executed by the Shell. --- .../java/net/corda/tools/shell/FlowShellCommand.java | 9 +++++++++ .../java/net/corda/tools/shell/RunShellCommand.java | 12 ++++++++---- .../net/corda/tools/shell/StartShellCommand.java | 11 ++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/tools/shell/src/main/java/net/corda/tools/shell/FlowShellCommand.java b/tools/shell/src/main/java/net/corda/tools/shell/FlowShellCommand.java index 1ed76de5f0..56607c948d 100644 --- a/tools/shell/src/main/java/net/corda/tools/shell/FlowShellCommand.java +++ b/tools/shell/src/main/java/net/corda/tools/shell/FlowShellCommand.java @@ -10,9 +10,12 @@ import org.crsh.cli.*; import org.crsh.command.*; import org.crsh.text.*; import org.crsh.text.ui.TableElement; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; +import static java.util.stream.Collectors.joining; import static net.corda.tools.shell.InteractiveShell.runFlowByNameFragment; import static net.corda.tools.shell.InteractiveShell.runStateMachinesView; @@ -24,12 +27,16 @@ import static net.corda.tools.shell.InteractiveShell.runStateMachinesView; "flow constructors (the right one is picked automatically) are then specified using the same syntax as for the run command." ) public class FlowShellCommand extends InteractiveShellCommand { + + private static Logger logger = LoggerFactory.getLogger(FlowShellCommand.class); + @Command @Usage("Start a (work)flow on the node. This is how you can change the ledger.") public void start( @Usage("The class name of the flow to run, or an unambiguous substring") @Argument String name, @Usage("The data to pass as input") @Argument(unquote = false) List input ) { + logger.info("Executing command \"flow start {} {}\",", name, input.stream().collect(joining(" "))); startFlow(name, input, out, ops(), ansiProgressRenderer(), objectMapper()); } @@ -37,6 +44,7 @@ public class FlowShellCommand extends InteractiveShellCommand { @Command @Usage("watch information about state machines running on the node with result information") public void watch(InvocationContext context) throws Exception { + logger.info("Executing command \"flow watch\"."); runStateMachinesView(out, ops()); } @@ -57,6 +65,7 @@ public class FlowShellCommand extends InteractiveShellCommand { @Command @Usage("list flows that user can start") public void list(InvocationContext context) throws Exception { + logger.info("Executing command \"flow list\"."); for (String name : ops().registeredFlows()) { context.provide(name + System.lineSeparator()); } diff --git a/tools/shell/src/main/java/net/corda/tools/shell/RunShellCommand.java b/tools/shell/src/main/java/net/corda/tools/shell/RunShellCommand.java index 497a855a68..11ec5e8e76 100644 --- a/tools/shell/src/main/java/net/corda/tools/shell/RunShellCommand.java +++ b/tools/shell/src/main/java/net/corda/tools/shell/RunShellCommand.java @@ -10,6 +10,8 @@ import org.crsh.cli.Man; import org.crsh.cli.Usage; import org.crsh.command.InvocationContext; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; @@ -17,11 +19,15 @@ import java.util.Map; import java.util.Set; import static java.util.Comparator.comparing; +import static java.util.stream.Collectors.joining; // Note that this class cannot be converted to Kotlin because CRaSH does not understand InvocationContext> which // is the closest you can get in Kotlin to raw types. public class RunShellCommand extends InteractiveShellCommand { + + private static Logger logger = LoggerFactory.getLogger(RunShellCommand.class); + @Command @Man( "Runs a method from the CordaRPCOps interface, which is the same interface exposed to RPC clients.\n\n" + @@ -30,10 +36,8 @@ public class RunShellCommand extends InteractiveShellCommand { "consulting the developer guide at https://docs.corda.net/api/kotlin/corda/net.corda.core.messaging/-corda-r-p-c-ops/index.html" ) @Usage("runs a method from the CordaRPCOps interface on the node.") - public Object main( - InvocationContext context, - @Usage("The command to run") @Argument(unquote = false) List command - ) { + public Object main(InvocationContext context, @Usage("The command to run") @Argument(unquote = false) List command) { + logger.info("Executing command \"run {}\",", command.stream().collect(joining(" "))); StringToMethodCallParser parser = new StringToMethodCallParser<>(CordaRPCOps.class, objectMapper()); if (command == null) { diff --git a/tools/shell/src/main/java/net/corda/tools/shell/StartShellCommand.java b/tools/shell/src/main/java/net/corda/tools/shell/StartShellCommand.java index 2f368128c1..6fd3ffae7e 100644 --- a/tools/shell/src/main/java/net/corda/tools/shell/StartShellCommand.java +++ b/tools/shell/src/main/java/net/corda/tools/shell/StartShellCommand.java @@ -5,15 +5,24 @@ package net.corda.tools.shell; import net.corda.tools.shell.utlities.ANSIProgressRenderer; import net.corda.tools.shell.utlities.CRaSHANSIProgressRenderer; import org.crsh.cli.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; +import static java.util.stream.Collectors.joining; + public class StartShellCommand extends InteractiveShellCommand { + + private static Logger logger = LoggerFactory.getLogger(StartShellCommand.class); + @Command @Man("An alias for 'flow start'. Example: \"start Yo target: Some other company\"") public void main(@Usage("The class name of the flow to run, or an unambiguous substring") @Argument String name, @Usage("The data to pass as input") @Argument(unquote = false) List input) { + + logger.info("Executing command \"start {} {}\",", name, input.stream().collect(joining(" "))); ANSIProgressRenderer ansiProgressRenderer = ansiProgressRenderer(); FlowShellCommand.startFlow(name, input, out, ops(), ansiProgressRenderer != null ? ansiProgressRenderer : new CRaSHANSIProgressRenderer(out), objectMapper()); } -} +} \ No newline at end of file