blob: f7881f3f50df8c9c0756e1a737d615e65b342412 [file] [log] [blame]
Yuta HIGUCHI02a125e2017-05-05 18:36:21 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yuta HIGUCHI02a125e2017-05-05 18:36:21 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cli;
17
18import static org.slf4j.LoggerFactory.getLogger;
19
20import java.util.List;
21import java.util.stream.Collectors;
22
Ray Milkeyd84f89b2018-08-17 14:54:17 -070023import org.apache.karaf.shell.api.action.Argument;
24import org.apache.karaf.shell.api.action.Command;
25import org.apache.karaf.shell.api.action.lifecycle.Service;
26import org.apache.karaf.shell.api.action.Option;
Yuta HIGUCHI02a125e2017-05-05 18:36:21 -070027import org.slf4j.Logger;
28
29import com.google.common.collect.ImmutableList;
30
31/**
32 * CLI command which just log message to ONOS log for ease of debugging, etc.
33 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070034@Service
Yuta HIGUCHI02a125e2017-05-05 18:36:21 -070035@Command(scope = "onos", name = "mark",
36 description = "Mark message in the log")
37public class MarkCommand extends AbstractShellCommand {
38
39 private static final String MARK = "--MARK--";
40
41 @Option(name = "--impersonate",
42 description = "Logger to use when logging this message",
43 required = false, multiValued = false)
44 String loggerName = "org.onosproject.cli.MarkCommand";
45
46 // TODO Option to specify log level
47
48
49 @Argument(index = 0, name = "message", description = "Message to log",
50 required = false, multiValued = true, valueToShowInHelp = MARK)
51 List<String> message = ImmutableList.of(MARK);
52
53 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070054 protected void doExecute() {
Yuta HIGUCHI02a125e2017-05-05 18:36:21 -070055
56 Logger log = getLogger(loggerName);
57
58 log.info("{}", message.stream().collect(Collectors.joining(" ")));
59
60 }
61
62}