CLI command to log something for ease of debugging.
onos> mark --impersonate org.onosproject.stc Starting step FOO
onos> display | tail -n 2
2017-05-06 01:34:57,275 | INFO | r user y-higuchi | stc | 137 - org.onosproject.onos-cli - 1.10.0.SNAPSHOT | Starting step FOO
Change-Id: I548ae2470b333a2ac047d8c7782b4a1b79535dbb
diff --git a/cli/src/main/java/org/onosproject/cli/MarkCommand.java b/cli/src/main/java/org/onosproject/cli/MarkCommand.java
new file mode 100644
index 0000000..9703ff1
--- /dev/null
+++ b/cli/src/main/java/org/onosproject/cli/MarkCommand.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.cli;
+
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.slf4j.Logger;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * CLI command which just log message to ONOS log for ease of debugging, etc.
+ */
+@Command(scope = "onos", name = "mark",
+ description = "Mark message in the log")
+public class MarkCommand extends AbstractShellCommand {
+
+ private static final String MARK = "--MARK--";
+
+ @Option(name = "--impersonate",
+ description = "Logger to use when logging this message",
+ required = false, multiValued = false)
+ String loggerName = "org.onosproject.cli.MarkCommand";
+
+ // TODO Option to specify log level
+
+
+ @Argument(index = 0, name = "message", description = "Message to log",
+ required = false, multiValued = true, valueToShowInHelp = MARK)
+ List<String> message = ImmutableList.of(MARK);
+
+ @Override
+ protected void execute() {
+
+ Logger log = getLogger(loggerName);
+
+ log.info("{}", message.stream().collect(Collectors.joining(" ")));
+
+ }
+
+}
diff --git a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
index 85dde80..1f0a70d 100644
--- a/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
+++ b/cli/src/main/resources/OSGI-INF/blueprint/shell-config.xml
@@ -18,6 +18,10 @@
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
<command>
+ <action class="org.onosproject.cli.MarkCommand"/>
+ </command>
+
+ <command>
<action class="org.onosproject.cli.PrettyJson"/>
</command>